Thread
-
WIN32 Non Blocking
Darko Prenosil <darko_prenosil@yahoo.com> — 2001-07-16T22:12:48Z
Hi ,Bruce ! There is diff for fe-connect.c. Diff was made with options -cr as You asked. I must say that this is the first time I ever use diff, so I do not know if if it is ok. I did not check if all of non-blocking functions are working, but I checked PQsetnonblocking,PQisnonblocking, PQsendQuery, PQgetResult and few others. I think that *** ./fe-connect.c Tue Jun 12 20:03:04 2001 --- ./fe-connect1.c Fri Jun 29 05:25:18 2001 *************** *** 189,195 **** static void defaultNoticeProcessor(void *arg, const char *message); static int parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage); ! /* ---------------- * Connecting to a Database --- 189,195 ---- static void defaultNoticeProcessor(void *arg, const char *message); static int parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage); ! static char FLastError[200]; /* ---------------- * Connecting to a Database *************** *** 240,249 **** PQconnectdb(const char *conninfo) { PGconn *conn = PQconnectStart(conninfo); - if (conn && conn->status != CONNECTION_BAD) (void) connectDBComplete(conn); - return conn; } --- 240,247 ---- *************** *** 291,296 **** --- 289,295 ---- { conn->status = CONNECTION_BAD; /* errorMessage is already set */ + sprintf( FLastError, "PQconnectStart-Invalid Connection Info"); return conn; } *************** *** 516,523 **** conn->require_ssl = 0; #endif ! if (error) conn->status = CONNECTION_BAD; else { if (connectDBStart(conn)) --- 515,524 ---- conn->require_ssl = 0; #endif ! if (error){ conn->status = CONNECTION_BAD; + sprintf( FLastError, "Failed to set DBLogin"); + } else { if (connectDBStart(conn)) *************** *** 709,717 **** if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) #endif { printfPQExpBuffer(&conn->errorMessage, ! "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", ! errno, strerror(errno)); return 0; } --- 710,724 ---- if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) #endif { + #ifdef WIN32 + sprintf( FLastError, "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", + WSAGetLastError()); + #else printfPQExpBuffer(&conn->errorMessage, ! "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", ! errno, strerror(errno)); ! #endif ! return 0; } *************** *** 788,794 **** { int portno, family; - #ifdef USE_SSL StartupPacket np; /* Used to negotiate SSL connection */ char SSLok; --- 795,800 ---- *************** *** 932,943 **** * Thus, we have make arrangements for all eventualities. * ---------- */ if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0) { - #ifndef WIN32 if (errno == EINPROGRESS || errno == 0) #else ! if (WSAGetLastError() == WSAEINPROGRESS) #endif { --- 938,952 ---- * Thus, we have make arrangements for all eventualities. * ---------- */ + + #ifndef WIN32 if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0) { if (errno == EINPROGRESS || errno == 0) #else ! if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) != 0) ! { ! if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK) #endif { *************** *** 1056,1061 **** --- 1065,1071 ---- conn->status = CONNECTION_BAD; return 0; + } *************** *** 1095,1100 **** --- 1105,1111 ---- if (pqWait(1, 0, conn)) { conn->status = CONNECTION_BAD; + sprintf(FLastError,conn->errorMessage.data); return 0; } break; *************** *** 1103,1108 **** --- 1114,1120 ---- if (pqWait(0, 1, conn)) { conn->status = CONNECTION_BAD; + sprintf(FLastError,conn->errorMessage.data); return 0; } break; *************** *** 1110,1115 **** --- 1122,1128 ---- default: /* Just in case we failed to set it in PQconnectPoll */ conn->status = CONNECTION_BAD; + sprintf(FLastError,conn->errorMessage.data); return 0; } *************** *** 1208,1222 **** { ACCEPT_TYPE_ARG3 laddrlen; - #ifndef WIN32 - int optval; - - #else - char optval; - - #endif - ACCEPT_TYPE_ARG3 optlen = sizeof(optval); - /* * Write ready, since we've made it here, so the * connection has been made. --- 1221,1226 ---- *************** *** 1226,1235 **** * Now check (using getsockopt) that there is not an error * state waiting for us on the socket. */ if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, ! (char *) &optval, &optlen) == -1) ! { printfPQExpBuffer(&conn->errorMessage, "PQconnectPoll() -- getsockopt() failed: " "errno=%d\n%s\n", --- 1230,1241 ---- * Now check (using getsockopt) that there is not an error * state waiting for us on the socket. */ + #ifndef WIN32 + int optval; + ACCEPT_TYPE_ARG3 optlen = sizeof(optval); if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, ! (char *) &optval, &optlen) == -1){ printfPQExpBuffer(&conn->errorMessage, "PQconnectPoll() -- getsockopt() failed: " "errno=%d\n%s\n", *************** *** 1247,1252 **** --- 1253,1272 ---- connectFailureMessage(conn, "PQconnectPoll()", optval); goto error_return; } + #else + char far optval[8]; + ACCEPT_TYPE_ARG3 optlen = sizeof(optval); + + int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval, &optlen); + if (OptResult==SOCKET_ERROR){ + printfPQExpBuffer(&conn->errorMessage, + "PQconnectPoll() -- getsockopt() failed: " + "errno=%i\n", + WSAGetLastError()); + connectFailureMessage(conn, "PQconnectPoll()", OptResult); + goto error_return; + } + #endif /* Fill in the client address */ laddrlen = sizeof(conn->laddr); *************** *** 1929,1934 **** --- 1949,1955 ---- #endif if (conn->sock >= 0) #ifdef WIN32 + //WSACleanup(); closesocket(conn->sock); #else close(conn->sock); *************** *** 2699,2706 **** char * PQerrorMessage(const PGconn *conn) { if (!conn) ! return "PQerrorMessage: conn pointer is NULL\n"; return conn->errorMessage.data; } --- 2720,2732 ---- char * PQerrorMessage(const PGconn *conn) { + //char ErrBuffer[200]; if (!conn) ! #ifdef WIN32 ! return FLastError; ! #else ! return "PQerrorMessage: conn pointer is NULL\n"; ! #endif return conn->errorMessage.data; } -
Re: WIN32 Non Blocking
Denis A. Doroshenko <d.doroshenko@omnitel.net> — 2001-07-17T12:30:50Z
Ugh... statically alocated buffer and sprintf()s with data of variable length; usage of data as format string... hell, i'm happy this is code for win32, although it scares me greatly. will it go as it is to PGSQL? :-0 On Tue, Jul 17, 2001 at 12:12:48AM +0200, Darko Prenosil wrote: > Hi ,Bruce ! > There is diff for fe-connect.c. > Diff was made with options -cr as You asked. > I must say that this is the first time I ever use diff, so I do not know if > if it is ok. > > I did not check if all of non-blocking functions are working, > but I checked PQsetnonblocking,PQisnonblocking, > PQsendQuery, PQgetResult and few others. > I think that > > > > *** ./fe-connect.c Tue Jun 12 20:03:04 2001 > --- ./fe-connect1.c Fri Jun 29 05:25:18 2001 > *************** > *** 189,195 **** > static void defaultNoticeProcessor(void *arg, const char *message); > static int parseServiceInfo(PQconninfoOption *options, > PQExpBuffer errorMessage); > ! > > /* ---------------- > * Connecting to a Database > --- 189,195 ---- > static void defaultNoticeProcessor(void *arg, const char *message); > static int parseServiceInfo(PQconninfoOption *options, > PQExpBuffer errorMessage); > ! static char FLastError[200]; > > /* ---------------- > * Connecting to a Database > *************** > *** 240,249 **** > PQconnectdb(const char *conninfo) > { > PGconn *conn = PQconnectStart(conninfo); > - > if (conn && conn->status != CONNECTION_BAD) > (void) connectDBComplete(conn); > - > return conn; > } > > --- 240,247 ---- > *************** > *** 291,296 **** > --- 289,295 ---- > { > conn->status = CONNECTION_BAD; > /* errorMessage is already set */ > + sprintf( FLastError, "PQconnectStart-Invalid Connection Info"); > return conn; > } > > *************** > *** 516,523 **** > conn->require_ssl = 0; > #endif > > ! if (error) > conn->status = CONNECTION_BAD; > else > { > if (connectDBStart(conn)) > --- 515,524 ---- > conn->require_ssl = 0; > #endif > > ! if (error){ > conn->status = CONNECTION_BAD; > + sprintf( FLastError, "Failed to set DBLogin"); > + } > else > { > if (connectDBStart(conn)) > *************** > *** 709,717 **** > if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) > #endif > { > printfPQExpBuffer(&conn->errorMessage, > ! "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", > ! errno, strerror(errno)); > return 0; > } > > --- 710,724 ---- > if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) > #endif > { > + #ifdef WIN32 > + sprintf( FLastError, "connectMakeNonblocking -- fcntl() failed: > errno=%d\n%s\n", > + WSAGetLastError()); > + #else > printfPQExpBuffer(&conn->errorMessage, > ! "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", > ! errno, strerror(errno)); > ! #endif > ! > return 0; > } > > *************** > *** 788,794 **** > { > int portno, > family; > - > #ifdef USE_SSL > StartupPacket np; /* Used to negotiate SSL connection */ > char SSLok; > --- 795,800 ---- > *************** > *** 932,943 **** > * Thus, we have make arrangements for all eventualities. > * ---------- > */ > if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0) > { > - #ifndef WIN32 > if (errno == EINPROGRESS || errno == 0) > #else > ! if (WSAGetLastError() == WSAEINPROGRESS) > #endif > { > > --- 938,952 ---- > * Thus, we have make arrangements for all eventualities. > * ---------- > */ > + > + #ifndef WIN32 > if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0) > { > if (errno == EINPROGRESS || errno == 0) > #else > ! if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) != 0) > ! { > ! if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == > WSAEWOULDBLOCK) > #endif > { > > *************** > *** 1056,1061 **** > --- 1065,1071 ---- > conn->status = CONNECTION_BAD; > > return 0; > + > } > > > *************** > *** 1095,1100 **** > --- 1105,1111 ---- > if (pqWait(1, 0, conn)) > { > conn->status = CONNECTION_BAD; > + sprintf(FLastError,conn->errorMessage.data); > return 0; > } > break; > *************** > *** 1103,1108 **** > --- 1114,1120 ---- > if (pqWait(0, 1, conn)) > { > conn->status = CONNECTION_BAD; > + sprintf(FLastError,conn->errorMessage.data); > return 0; > } > break; > *************** > *** 1110,1115 **** > --- 1122,1128 ---- > default: > /* Just in case we failed to set it in PQconnectPoll */ > conn->status = CONNECTION_BAD; > + sprintf(FLastError,conn->errorMessage.data); > return 0; > } > > *************** > *** 1208,1222 **** > { > ACCEPT_TYPE_ARG3 laddrlen; > > - #ifndef WIN32 > - int optval; > - > - #else > - char optval; > - > - #endif > - ACCEPT_TYPE_ARG3 optlen = sizeof(optval); > - > /* > * Write ready, since we've made it here, so the > * connection has been made. > --- 1221,1226 ---- > *************** > *** 1226,1235 **** > * Now check (using getsockopt) that there is not an error > * state waiting for us on the socket. > */ > > if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, > ! (char *) &optval, &optlen) == -1) > ! { > printfPQExpBuffer(&conn->errorMessage, > "PQconnectPoll() -- getsockopt() failed: " > "errno=%d\n%s\n", > --- 1230,1241 ---- > * Now check (using getsockopt) that there is not an error > * state waiting for us on the socket. > */ > + #ifndef WIN32 > + int optval; > + ACCEPT_TYPE_ARG3 optlen = sizeof(optval); > > if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, > ! (char *) &optval, &optlen) == -1){ > printfPQExpBuffer(&conn->errorMessage, > "PQconnectPoll() -- getsockopt() failed: " > "errno=%d\n%s\n", > *************** > *** 1247,1252 **** > --- 1253,1272 ---- > connectFailureMessage(conn, "PQconnectPoll()", optval); > goto error_return; > } > + #else > + char far optval[8]; > + ACCEPT_TYPE_ARG3 optlen = sizeof(optval); > + > + int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval, > &optlen); > + if (OptResult==SOCKET_ERROR){ > + printfPQExpBuffer(&conn->errorMessage, > + "PQconnectPoll() -- getsockopt() failed: " > + "errno=%i\n", > + WSAGetLastError()); > + connectFailureMessage(conn, "PQconnectPoll()", OptResult); > + goto error_return; > + } > + #endif > > /* Fill in the client address */ > laddrlen = sizeof(conn->laddr); > *************** > *** 1929,1934 **** > --- 1949,1955 ---- > #endif > if (conn->sock >= 0) > #ifdef WIN32 > + //WSACleanup(); > closesocket(conn->sock); > #else > close(conn->sock); > *************** > *** 2699,2706 **** > char * > PQerrorMessage(const PGconn *conn) > { > if (!conn) > ! return "PQerrorMessage: conn pointer is NULL\n"; > > return conn->errorMessage.data; > } > --- 2720,2732 ---- > char * > PQerrorMessage(const PGconn *conn) > { > + //char ErrBuffer[200]; > if (!conn) > ! #ifdef WIN32 > ! return FLastError; > ! #else > ! return "PQerrorMessage: conn pointer is NULL\n"; > ! #endif > > return conn->errorMessage.data; > } > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly -- Denis A. Doroshenko [GPRS engineer] .-. _|_ | [Omnitel Ltd., T.Sevcenkos st. 25, Vilnius, Lithuania] | | _ _ _ .| _ | [Phone: +370 9863486 E-mail: d.doroshenko@omnitel.net] |_|| | || |||(/_|_ -
Re: WIN32 Non Blocking
Bruce Momjian <pgman@candle.pha.pa.us> — 2001-07-17T12:51:45Z
I just got a new Win32 libpq patch. Please see it at: http://candle.pha.pa.us/cgi-bin/pgpatches How does your match with that one? I haven't applied it yet. > Hi ,Bruce ! > There is diff for fe-connect.c. > Diff was made with options -cr as You asked. > I must say that this is the first time I ever use diff, so I do not know if > if it is ok. > > I did not check if all of non-blocking functions are working, > but I checked PQsetnonblocking,PQisnonblocking, > PQsendQuery, PQgetResult and few others. > I think that > > > > *** ./fe-connect.c Tue Jun 12 20:03:04 2001 > --- ./fe-connect1.c Fri Jun 29 05:25:18 2001 > *************** > *** 189,195 **** > static void defaultNoticeProcessor(void *arg, const char *message); > static int parseServiceInfo(PQconninfoOption *options, > PQExpBuffer errorMessage); > ! > > /* ---------------- > * Connecting to a Database > --- 189,195 ---- > static void defaultNoticeProcessor(void *arg, const char *message); > static int parseServiceInfo(PQconninfoOption *options, > PQExpBuffer errorMessage); > ! static char FLastError[200]; > > /* ---------------- > * Connecting to a Database > *************** > *** 240,249 **** > PQconnectdb(const char *conninfo) > { > PGconn *conn = PQconnectStart(conninfo); > - > if (conn && conn->status != CONNECTION_BAD) > (void) connectDBComplete(conn); > - > return conn; > } > > --- 240,247 ---- > *************** > *** 291,296 **** > --- 289,295 ---- > { > conn->status = CONNECTION_BAD; > /* errorMessage is already set */ > + sprintf( FLastError, "PQconnectStart-Invalid Connection Info"); > return conn; > } > > *************** > *** 516,523 **** > conn->require_ssl = 0; > #endif > > ! if (error) > conn->status = CONNECTION_BAD; > else > { > if (connectDBStart(conn)) > --- 515,524 ---- > conn->require_ssl = 0; > #endif > > ! if (error){ > conn->status = CONNECTION_BAD; > + sprintf( FLastError, "Failed to set DBLogin"); > + } > else > { > if (connectDBStart(conn)) > *************** > *** 709,717 **** > if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) > #endif > { > printfPQExpBuffer(&conn->errorMessage, > ! "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", > ! errno, strerror(errno)); > return 0; > } > > --- 710,724 ---- > if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) > #endif > { > + #ifdef WIN32 > + sprintf( FLastError, "connectMakeNonblocking -- fcntl() failed: > errno=%d\n%s\n", > + WSAGetLastError()); > + #else > printfPQExpBuffer(&conn->errorMessage, > ! "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", > ! errno, strerror(errno)); > ! #endif > ! > return 0; > } > > *************** > *** 788,794 **** > { > int portno, > family; > - > #ifdef USE_SSL > StartupPacket np; /* Used to negotiate SSL connection */ > char SSLok; > --- 795,800 ---- > *************** > *** 932,943 **** > * Thus, we have make arrangements for all eventualities. > * ---------- > */ > if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0) > { > - #ifndef WIN32 > if (errno == EINPROGRESS || errno == 0) > #else > ! if (WSAGetLastError() == WSAEINPROGRESS) > #endif > { > > --- 938,952 ---- > * Thus, we have make arrangements for all eventualities. > * ---------- > */ > + > + #ifndef WIN32 > if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0) > { > if (errno == EINPROGRESS || errno == 0) > #else > ! if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) != 0) > ! { > ! if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == > WSAEWOULDBLOCK) > #endif > { > > *************** > *** 1056,1061 **** > --- 1065,1071 ---- > conn->status = CONNECTION_BAD; > > return 0; > + > } > > > *************** > *** 1095,1100 **** > --- 1105,1111 ---- > if (pqWait(1, 0, conn)) > { > conn->status = CONNECTION_BAD; > + sprintf(FLastError,conn->errorMessage.data); > return 0; > } > break; > *************** > *** 1103,1108 **** > --- 1114,1120 ---- > if (pqWait(0, 1, conn)) > { > conn->status = CONNECTION_BAD; > + sprintf(FLastError,conn->errorMessage.data); > return 0; > } > break; > *************** > *** 1110,1115 **** > --- 1122,1128 ---- > default: > /* Just in case we failed to set it in PQconnectPoll */ > conn->status = CONNECTION_BAD; > + sprintf(FLastError,conn->errorMessage.data); > return 0; > } > > *************** > *** 1208,1222 **** > { > ACCEPT_TYPE_ARG3 laddrlen; > > - #ifndef WIN32 > - int optval; > - > - #else > - char optval; > - > - #endif > - ACCEPT_TYPE_ARG3 optlen = sizeof(optval); > - > /* > * Write ready, since we've made it here, so the > * connection has been made. > --- 1221,1226 ---- > *************** > *** 1226,1235 **** > * Now check (using getsockopt) that there is not an error > * state waiting for us on the socket. > */ > > if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, > ! (char *) &optval, &optlen) == -1) > ! { > printfPQExpBuffer(&conn->errorMessage, > "PQconnectPoll() -- getsockopt() failed: " > "errno=%d\n%s\n", > --- 1230,1241 ---- > * Now check (using getsockopt) that there is not an error > * state waiting for us on the socket. > */ > + #ifndef WIN32 > + int optval; > + ACCEPT_TYPE_ARG3 optlen = sizeof(optval); > > if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, > ! (char *) &optval, &optlen) == -1){ > printfPQExpBuffer(&conn->errorMessage, > "PQconnectPoll() -- getsockopt() failed: " > "errno=%d\n%s\n", > *************** > *** 1247,1252 **** > --- 1253,1272 ---- > connectFailureMessage(conn, "PQconnectPoll()", optval); > goto error_return; > } > + #else > + char far optval[8]; > + ACCEPT_TYPE_ARG3 optlen = sizeof(optval); > + > + int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval, > &optlen); > + if (OptResult==SOCKET_ERROR){ > + printfPQExpBuffer(&conn->errorMessage, > + "PQconnectPoll() -- getsockopt() failed: " > + "errno=%i\n", > + WSAGetLastError()); > + connectFailureMessage(conn, "PQconnectPoll()", OptResult); > + goto error_return; > + } > + #endif > > /* Fill in the client address */ > laddrlen = sizeof(conn->laddr); > *************** > *** 1929,1934 **** > --- 1949,1955 ---- > #endif > if (conn->sock >= 0) > #ifdef WIN32 > + //WSACleanup(); > closesocket(conn->sock); > #else > close(conn->sock); > *************** > *** 2699,2706 **** > char * > PQerrorMessage(const PGconn *conn) > { > if (!conn) > ! return "PQerrorMessage: conn pointer is NULL\n"; > > return conn->errorMessage.data; > } > --- 2720,2732 ---- > char * > PQerrorMessage(const PGconn *conn) > { > + //char ErrBuffer[200]; > if (!conn) > ! #ifdef WIN32 > ! return FLastError; > ! #else > ! return "PQerrorMessage: conn pointer is NULL\n"; > ! #endif > > return conn->errorMessage.data; > } > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026 -
Re: WIN32 Non Blocking
Bruce Momjian <pgman@candle.pha.pa.us> — 2001-07-17T14:07:25Z
> Ugh... statically alocated buffer and sprintf()s with data of variable > length; usage of data as format string... hell, i'm happy this is code > for win32, although it scares me greatly. will it go as it is to PGSQL? > :-0 Good points. Right now, because they arrived on the same day, we have two libpq Win32 patches floating around. Seems the two authors are going to have to communicate and submit one patch anyway. I am going to put both patches http://candle.pha.pa.us/cgi-bin/pgpatches and maybe someone can merge them and clean them up as needed. Few of us have Win32 development machines so we need some help. We know we have Win32 errno problems and I am glad two people have jumped in to fix them. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026
-
Re: WIN32 Non Blocking
Bruce Momjian <pgman@candle.pha.pa.us> — 2001-07-17T14:09:59Z
Your patch has been added to the PostgreSQL unapplied patches list at: http://candle.pha.pa.us/cgi-bin/pgpatches This must be merged with the other Win32 libpq patch. Thanks. > Hi ,Bruce ! > There is diff for fe-connect.c. > Diff was made with options -cr as You asked. > I must say that this is the first time I ever use diff, so I do not know if > if it is ok. > > I did not check if all of non-blocking functions are working, > but I checked PQsetnonblocking,PQisnonblocking, > PQsendQuery, PQgetResult and few others. > I think that > > > > *** ./fe-connect.c Tue Jun 12 20:03:04 2001 > --- ./fe-connect1.c Fri Jun 29 05:25:18 2001 > *************** > *** 189,195 **** > static void defaultNoticeProcessor(void *arg, const char *message); > static int parseServiceInfo(PQconninfoOption *options, > PQExpBuffer errorMessage); > ! > > /* ---------------- > * Connecting to a Database > --- 189,195 ---- > static void defaultNoticeProcessor(void *arg, const char *message); > static int parseServiceInfo(PQconninfoOption *options, > PQExpBuffer errorMessage); > ! static char FLastError[200]; > > /* ---------------- > * Connecting to a Database > *************** > *** 240,249 **** > PQconnectdb(const char *conninfo) > { > PGconn *conn = PQconnectStart(conninfo); > - > if (conn && conn->status != CONNECTION_BAD) > (void) connectDBComplete(conn); > - > return conn; > } > > --- 240,247 ---- > *************** > *** 291,296 **** > --- 289,295 ---- > { > conn->status = CONNECTION_BAD; > /* errorMessage is already set */ > + sprintf( FLastError, "PQconnectStart-Invalid Connection Info"); > return conn; > } > > *************** > *** 516,523 **** > conn->require_ssl = 0; > #endif > > ! if (error) > conn->status = CONNECTION_BAD; > else > { > if (connectDBStart(conn)) > --- 515,524 ---- > conn->require_ssl = 0; > #endif > > ! if (error){ > conn->status = CONNECTION_BAD; > + sprintf( FLastError, "Failed to set DBLogin"); > + } > else > { > if (connectDBStart(conn)) > *************** > *** 709,717 **** > if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) > #endif > { > printfPQExpBuffer(&conn->errorMessage, > ! "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", > ! errno, strerror(errno)); > return 0; > } > > --- 710,724 ---- > if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) > #endif > { > + #ifdef WIN32 > + sprintf( FLastError, "connectMakeNonblocking -- fcntl() failed: > errno=%d\n%s\n", > + WSAGetLastError()); > + #else > printfPQExpBuffer(&conn->errorMessage, > ! "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", > ! errno, strerror(errno)); > ! #endif > ! > return 0; > } > > *************** > *** 788,794 **** > { > int portno, > family; > - > #ifdef USE_SSL > StartupPacket np; /* Used to negotiate SSL connection */ > char SSLok; > --- 795,800 ---- > *************** > *** 932,943 **** > * Thus, we have make arrangements for all eventualities. > * ---------- > */ > if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0) > { > - #ifndef WIN32 > if (errno == EINPROGRESS || errno == 0) > #else > ! if (WSAGetLastError() == WSAEINPROGRESS) > #endif > { > > --- 938,952 ---- > * Thus, we have make arrangements for all eventualities. > * ---------- > */ > + > + #ifndef WIN32 > if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0) > { > if (errno == EINPROGRESS || errno == 0) > #else > ! if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) != 0) > ! { > ! if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == > WSAEWOULDBLOCK) > #endif > { > > *************** > *** 1056,1061 **** > --- 1065,1071 ---- > conn->status = CONNECTION_BAD; > > return 0; > + > } > > > *************** > *** 1095,1100 **** > --- 1105,1111 ---- > if (pqWait(1, 0, conn)) > { > conn->status = CONNECTION_BAD; > + sprintf(FLastError,conn->errorMessage.data); > return 0; > } > break; > *************** > *** 1103,1108 **** > --- 1114,1120 ---- > if (pqWait(0, 1, conn)) > { > conn->status = CONNECTION_BAD; > + sprintf(FLastError,conn->errorMessage.data); > return 0; > } > break; > *************** > *** 1110,1115 **** > --- 1122,1128 ---- > default: > /* Just in case we failed to set it in PQconnectPoll */ > conn->status = CONNECTION_BAD; > + sprintf(FLastError,conn->errorMessage.data); > return 0; > } > > *************** > *** 1208,1222 **** > { > ACCEPT_TYPE_ARG3 laddrlen; > > - #ifndef WIN32 > - int optval; > - > - #else > - char optval; > - > - #endif > - ACCEPT_TYPE_ARG3 optlen = sizeof(optval); > - > /* > * Write ready, since we've made it here, so the > * connection has been made. > --- 1221,1226 ---- > *************** > *** 1226,1235 **** > * Now check (using getsockopt) that there is not an error > * state waiting for us on the socket. > */ > > if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, > ! (char *) &optval, &optlen) == -1) > ! { > printfPQExpBuffer(&conn->errorMessage, > "PQconnectPoll() -- getsockopt() failed: " > "errno=%d\n%s\n", > --- 1230,1241 ---- > * Now check (using getsockopt) that there is not an error > * state waiting for us on the socket. > */ > + #ifndef WIN32 > + int optval; > + ACCEPT_TYPE_ARG3 optlen = sizeof(optval); > > if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, > ! (char *) &optval, &optlen) == -1){ > printfPQExpBuffer(&conn->errorMessage, > "PQconnectPoll() -- getsockopt() failed: " > "errno=%d\n%s\n", > *************** > *** 1247,1252 **** > --- 1253,1272 ---- > connectFailureMessage(conn, "PQconnectPoll()", optval); > goto error_return; > } > + #else > + char far optval[8]; > + ACCEPT_TYPE_ARG3 optlen = sizeof(optval); > + > + int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval, > &optlen); > + if (OptResult==SOCKET_ERROR){ > + printfPQExpBuffer(&conn->errorMessage, > + "PQconnectPoll() -- getsockopt() failed: " > + "errno=%i\n", > + WSAGetLastError()); > + connectFailureMessage(conn, "PQconnectPoll()", OptResult); > + goto error_return; > + } > + #endif > > /* Fill in the client address */ > laddrlen = sizeof(conn->laddr); > *************** > *** 1929,1934 **** > --- 1949,1955 ---- > #endif > if (conn->sock >= 0) > #ifdef WIN32 > + //WSACleanup(); > closesocket(conn->sock); > #else > close(conn->sock); > *************** > *** 2699,2706 **** > char * > PQerrorMessage(const PGconn *conn) > { > if (!conn) > ! return "PQerrorMessage: conn pointer is NULL\n"; > > return conn->errorMessage.data; > } > --- 2720,2732 ---- > char * > PQerrorMessage(const PGconn *conn) > { > + //char ErrBuffer[200]; > if (!conn) > ! #ifdef WIN32 > ! return FLastError; > ! #else > ! return "PQerrorMessage: conn pointer is NULL\n"; > ! #endif > > return conn->errorMessage.data; > } > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026