Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6024ac1

Browse files
committed
Back out old version and update with newer patch of:
Fix for non-blocking connections in libpq Bernhard Herzog
1 parent 66cd6a0 commit 6024ac1

File tree

4 files changed

+42
-60
lines changed

4 files changed

+42
-60
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.115 2002/03/05 05:20:12 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.116 2002/03/05 06:07:26 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/

src/interfaces/libpq/fe-misc.c

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
*
2727
* IDENTIFICATION
28-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.66 2002/03/05 05:20:12 momjian Exp $
28+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.67 2002/03/05 06:07:26 momjian Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
@@ -110,21 +110,19 @@ pqPutc(char c, PGconn *conn)
110110
static int
111111
pqPutBytes(const char *s, size_t nbytes, PGconn *conn)
112112
{
113-
/*
114-
* Strategy to handle blocking and non-blocking connections: Fill the
115-
* output buffer and flush it repeatedly until either all data has
116-
* been sent or is at least queued in the buffer.
113+
/* Strategy to handle blocking and non-blocking connections: Fill
114+
* the output buffer and flush it repeatedly until either all data
115+
* has been sent or is at least queued in the buffer.
117116
*
118-
* For non-blocking connections, grow the buffer if not all data fits
119-
* into it and the buffer can't be sent because the socket would
120-
* block.
117+
* For non-blocking connections, grow the buffer if not all data
118+
* fits into it and the buffer can't be sent because the socket
119+
* would block.
121120
*/
122121

123122
while (nbytes)
124123
{
125-
size_t avail,
126-
remaining;
127-
124+
size_t avail, remaining;
125+
128126
/* fill the output buffer */
129127
avail = Max(conn->outBufSize - conn->outCount, 0);
130128
remaining = Min(avail, nbytes);
@@ -133,40 +131,36 @@ pqPutBytes(const char *s, size_t nbytes, PGconn *conn)
133131
s += remaining;
134132
nbytes -= remaining;
135133

136-
/*
137-
* if the data didn't fit completely into the buffer, try to flush
138-
* the buffer
139-
*/
134+
/* if the data didn't fit completely into the buffer, try to
135+
* flush the buffer */
140136
if (nbytes)
141137
{
142-
int send_result = pqSendSome(conn);
138+
int send_result = pqSendSome(conn);
143139

144140
/* if there were errors, report them */
145141
if (send_result < 0)
146142
return EOF;
147143

148-
/*
149-
* if not all data could be sent, increase the output buffer,
150-
* put the rest of s into it and return successfully. This
151-
* case will only happen in a non-blocking connection
144+
/* if not all data could be sent, increase the output
145+
* buffer, put the rest of s into it and return
146+
* successfully. This case will only happen in a
147+
* non-blocking connection
152148
*/
153149
if (send_result > 0)
154150
{
155-
/*
156-
* try to grow the buffer. FIXME: The new size could be
157-
* chosen more intelligently.
151+
/* try to grow the buffer.
152+
* FIXME: The new size could be chosen more
153+
* intelligently.
158154
*/
159-
size_t buflen = conn->outCount + nbytes;
160-
155+
size_t buflen = conn->outCount + nbytes;
161156
if (buflen > conn->outBufSize)
162157
{
163-
char *newbuf = realloc(conn->outBuffer, buflen);
164-
158+
char * newbuf = realloc(conn->outBuffer, buflen);
165159
if (!newbuf)
166160
{
167161
/* realloc failed. Probably out of memory */
168162
printfPQExpBuffer(&conn->errorMessage,
169-
"cannot allocate memory for output buffer\n");
163+
"cannot allocate memory for output buffer\n");
170164
return EOF;
171165
}
172166
conn->outBuffer = newbuf;
@@ -181,11 +175,9 @@ pqPutBytes(const char *s, size_t nbytes, PGconn *conn)
181175
}
182176
}
183177

184-
/*
185-
* pqSendSome was able to send all data. Continue with the next
186-
* chunk of s.
187-
*/
188-
} /* while */
178+
/* pqSendSome was able to send all data. Continue with the next
179+
* chunk of s. */
180+
} /* while */
189181

190182
return 0;
191183
}
@@ -631,19 +623,11 @@ pqReadData(PGconn *conn)
631623
return -1;
632624
}
633625

634-
/* pqSendSome: send any data waiting in the output buffer and return 0
635-
* if all data was sent, -1 if an error occurred or 1 if not all data
636-
* could be written because the socket would have blocked.
637-
*
638-
* For a blocking connection all data will be sent unless an error
639-
* occurrs. -1 will only be returned if the connection is non-blocking.
640-
*
641-
* Internally, the case of data remaining in the buffer after pqSendSome
642-
* could be determined by looking at outCount, but this function also
643-
* serves as the implementation of the new API function PQsendsome.
626+
/*
627+
* pqSendSome: send any data waiting in the output buffer.
644628
*
645-
* FIXME: perhaps it would be more useful to return the number of bytes
646-
* remaining?
629+
* Return 0 on sucess, -1 on failure and 1 when data remains because the
630+
* socket would block and the connection is non-blocking.
647631
*/
648632
int
649633
pqSendSome(PGconn *conn)
@@ -655,7 +639,7 @@ pqSendSome(PGconn *conn)
655639
{
656640
printfPQExpBuffer(&conn->errorMessage,
657641
libpq_gettext("connection not open\n"));
658-
return EOF;
642+
return -1;
659643
}
660644

661645
/*
@@ -713,7 +697,7 @@ pqSendSome(PGconn *conn)
713697
printfPQExpBuffer(&conn->errorMessage,
714698
libpq_gettext(
715699
"server closed the connection unexpectedly\n"
716-
"\tThis probably means the server terminated abnormally\n"
700+
"\tThis probably means the server terminated abnormally\n"
717701
"\tbefore or while processing the request.\n"));
718702

719703
/*
@@ -778,6 +762,7 @@ pqSendSome(PGconn *conn)
778762
}
779763

780764

765+
781766
/*
782767
* pqFlush: send any data waiting in the output buffer
783768
*
@@ -790,7 +775,9 @@ int
790775
pqFlush(PGconn *conn)
791776
{
792777
if (pqSendSome(conn))
778+
{
793779
return EOF;
780+
}
794781
return 0;
795782
}
796783

@@ -812,7 +799,7 @@ pqWait(int forRead, int forWrite, PGconn *conn)
812799
{
813800
printfPQExpBuffer(&conn->errorMessage,
814801
libpq_gettext("connection not open\n"));
815-
return -1;
802+
return EOF;
816803
}
817804

818805
if (forRead || forWrite)
@@ -913,20 +900,19 @@ libpq_gettext(const char *msgid)
913900
* strerror replacement for windows:
914901
*
915902
* This works on WIN2000 and newer, but we don't know where to find WinSock
916-
* error strings on older Windows flavors. If you know, clue us in.
903+
* error strings on older Windows flavors. If you know, clue us in.
917904
*/
918905
const char *
919906
winsock_strerror(int eno)
920907
{
921-
static char err_buf[512];
922-
923-
#define WSSE_MAXLEN (sizeof(err_buf)-1-13) /* 13 for " (0x00000000)" */
908+
static char err_buf[512];
909+
#define WSSE_MAXLEN (sizeof(err_buf)-1-13) /* 13 for " (0x00000000)" */
924910
int length;
925911

926912
/* First try the "system table", this works on Win2k and up */
927913

928914
if (FormatMessage(
929-
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
915+
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
930916
0,
931917
eno,
932918
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),

src/interfaces/libpq/libpq-fe.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: libpq-fe.h,v 1.82 2002/03/05 05:20:12 momjian Exp $
10+
* $Id: libpq-fe.h,v 1.83 2002/03/05 06:07:26 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -282,10 +282,6 @@ extern int PQisnonblocking(const PGconn *conn);
282282

283283
/* Force the write buffer to be written (or at least try) */
284284
extern int PQflush(PGconn *conn);
285-
/*
286-
* Force the write buffer to be written (or at least try)
287-
* (better than PQflush)
288-
*/
289285
extern int PQsendSome(PGconn *conn);
290286

291287
/*

src/interfaces/libpq/libpq-int.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: libpq-int.h,v 1.45 2002/03/05 05:20:12 momjian Exp $
15+
* $Id: libpq-int.h,v 1.46 2002/03/05 06:07:27 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/

0 commit comments

Comments
 (0)