Skip to content

Commit ca5a516

Browse files
committed
I downloaded new source for lib (only few hours old !!!), and made
changes on this new source to make non-blocking connection work. I tested it, and PQSendQuery and PQGetResult are working fine. In win32.h I added one line: #define snprintf _snprintf Darko Prenosil
1 parent 54bf5da commit ca5a516

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.169 2001/07/20 17:45:05 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.170 2001/07/21 04:32:41 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -70,7 +70,7 @@ static SSL_CTX *SSL_context = NULL;
7070

7171
#define NOTIFYLIST_INITIAL_SIZE 10
7272
#define NOTIFYLIST_GROWBY 10
73-
73+
#define WIN32_NON_BLOCKING_CONNECTIONS
7474

7575
/* ----------
7676
* Definition of the conninfo parameters and their fallback resources.
@@ -932,9 +932,15 @@ connectDBStart(PGconn *conn)
932932
* Thus, we have make arrangements for all eventualities.
933933
* ----------
934934
*/
935+
#ifndef WIN32
935936
if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
936937
{
937938
if (errno == EINPROGRESS || errno == 0)
939+
#else
940+
if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) != 0)
941+
{
942+
if (errno == EINPROGRESS || errno == EWOULDBLOCK)
943+
#endif
938944
{
939945

940946
/*
@@ -1208,15 +1214,6 @@ PQconnectPoll(PGconn *conn)
12081214
{
12091215
ACCEPT_TYPE_ARG3 laddrlen;
12101216

1211-
#ifndef WIN32
1212-
int optval;
1213-
1214-
#else
1215-
char optval;
1216-
1217-
#endif
1218-
ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
1219-
12201217
/*
12211218
* Write ready, since we've made it here, so the
12221219
* connection has been made.
@@ -1227,6 +1224,10 @@ PQconnectPoll(PGconn *conn)
12271224
* state waiting for us on the socket.
12281225
*/
12291226

1227+
#ifndef WIN32
1228+
int optval;
1229+
ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
1230+
12301231
if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
12311232
(char *) &optval, &optlen) == -1)
12321233
{
@@ -1235,6 +1236,20 @@ PQconnectPoll(PGconn *conn)
12351236
strerror(errno));
12361237
goto error_return;
12371238
}
1239+
#else
1240+
char far optval[8];
1241+
ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
1242+
1243+
int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval, &optlen);
1244+
if (OptResult==SOCKET_ERROR)
1245+
{
1246+
printfPQExpBuffer(&conn->errorMessage,
1247+
"PQconnectPoll() -- getsockopt() failed: "
1248+
"errno=%i\n", errno);
1249+
connectFailureMessage(conn, OptResult);
1250+
goto error_return;
1251+
}
1252+
#endif
12381253
else if (optval != 0)
12391254
{
12401255

src/interfaces/libpq/win32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define popen(a,b) _popen(a,b)
1717
#define pclose(a) _pclose(a)
1818
#define vsnprintf(a,b,c,d) _vsnprintf(a,b,c,d)
19+
#define snprintf _snprintf
1920

2021
/*
2122
* crypt not available (yet)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy