2525 *
2626 *
2727 * IDENTIFICATION
28- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.66 2002/03/0505:20:12 momjian Exp $
28+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.67 2002/03/0506:07:26 momjian Exp $
2929 *
3030 *-------------------------------------------------------------------------
3131 */
@@ -110,21 +110,19 @@ pqPutc(char c, PGconn *conn)
110110static int
111111pqPutBytes (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
123122while (nbytes )
124123{
125- size_t avail ,
126- remaining ;
127-
124+ size_t avail ,remaining ;
125+
128126/* fill the output buffer */
129127avail = Max (conn -> outBufSize - conn -> outCount ,0 );
130128remaining = Min (avail ,nbytes );
@@ -133,40 +131,36 @@ pqPutBytes(const char *s, size_t nbytes, PGconn *conn)
133131s += remaining ;
134132nbytes -= 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 */
140136if (nbytes )
141137{
142- int send_result = pqSendSome (conn );
138+ int send_result = pqSendSome (conn );
143139
144140/* if there were errors, report them */
145141if (send_result < 0 )
146142return 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 */
153149if (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 ;
161156if (buflen > conn -> outBufSize )
162157{
163- char * newbuf = realloc (conn -> outBuffer ,buflen );
164-
158+ char * newbuf = realloc (conn -> outBuffer ,buflen );
165159if (!newbuf )
166160{
167161/* realloc failed. Probably out of memory */
168162printfPQExpBuffer (& conn -> errorMessage ,
169- "cannot allocate memory for output buffer\n" );
163+ "cannot allocate memory for output buffer\n" );
170164return EOF ;
171165}
172166conn -> 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
190182return 0 ;
191183}
@@ -631,19 +623,11 @@ pqReadData(PGconn *conn)
631623return -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 */
648632int
649633pqSendSome (PGconn * conn )
@@ -655,7 +639,7 @@ pqSendSome(PGconn *conn)
655639{
656640printfPQExpBuffer (& conn -> errorMessage ,
657641libpq_gettext ("connection not open\n" ));
658- return EOF ;
642+ return -1 ;
659643}
660644
661645/*
@@ -713,7 +697,7 @@ pqSendSome(PGconn *conn)
713697printfPQExpBuffer (& conn -> errorMessage ,
714698libpq_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 *
790775pqFlush (PGconn * conn )
791776{
792777if (pqSendSome (conn ))
778+ {
793779return EOF ;
780+ }
794781return 0 ;
795782}
796783
@@ -812,7 +799,7 @@ pqWait(int forRead, int forWrite, PGconn *conn)
812799{
813800printfPQExpBuffer (& conn -> errorMessage ,
814801libpq_gettext ("connection not open\n" ));
815- return -1 ;
802+ return EOF ;
816803}
817804
818805if (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 */
918905const char *
919906winsock_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)" */
924910int length ;
925911
926912/* First try the "system table", this works on Win2k and up */
927913
928914if (FormatMessage (
929- FORMAT_MESSAGE_IGNORE_INSERTS |FORMAT_MESSAGE_FROM_SYSTEM ,
915+ FORMAT_MESSAGE_IGNORE_INSERTS |FORMAT_MESSAGE_FROM_SYSTEM ,
9309160 ,
931917eno ,
932918MAKELANGID (LANG_NEUTRAL ,SUBLANG_DEFAULT ),