25
25
*
26
26
*
27
27
* 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 $
29
29
*
30
30
*-------------------------------------------------------------------------
31
31
*/
@@ -110,21 +110,19 @@ pqPutc(char c, PGconn *conn)
110
110
static int
111
111
pqPutBytes (const char * s , size_t nbytes , PGconn * conn )
112
112
{
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.
117
116
*
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.
121
120
*/
122
121
123
122
while (nbytes )
124
123
{
125
- size_t avail ,
126
- remaining ;
127
-
124
+ size_t avail , remaining ;
125
+
128
126
/* fill the output buffer */
129
127
avail = Max (conn -> outBufSize - conn -> outCount , 0 );
130
128
remaining = Min (avail , nbytes );
@@ -133,40 +131,36 @@ pqPutBytes(const char *s, size_t nbytes, PGconn *conn)
133
131
s += remaining ;
134
132
nbytes -= remaining ;
135
133
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 */
140
136
if (nbytes )
141
137
{
142
- int send_result = pqSendSome (conn );
138
+ int send_result = pqSendSome (conn );
143
139
144
140
/* if there were errors, report them */
145
141
if (send_result < 0 )
146
142
return EOF ;
147
143
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
152
148
*/
153
149
if (send_result > 0 )
154
150
{
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.
158
154
*/
159
- size_t buflen = conn -> outCount + nbytes ;
160
-
155
+ size_t buflen = conn -> outCount + nbytes ;
161
156
if (buflen > conn -> outBufSize )
162
157
{
163
- char * newbuf = realloc (conn -> outBuffer , buflen );
164
-
158
+ char * newbuf = realloc (conn -> outBuffer , buflen );
165
159
if (!newbuf )
166
160
{
167
161
/* realloc failed. Probably out of memory */
168
162
printfPQExpBuffer (& conn -> errorMessage ,
169
- "cannot allocate memory for output buffer\n" );
163
+ "cannot allocate memory for output buffer\n" );
170
164
return EOF ;
171
165
}
172
166
conn -> outBuffer = newbuf ;
@@ -181,11 +175,9 @@ pqPutBytes(const char *s, size_t nbytes, PGconn *conn)
181
175
}
182
176
}
183
177
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 */
189
181
190
182
return 0 ;
191
183
}
@@ -631,19 +623,11 @@ pqReadData(PGconn *conn)
631
623
return -1 ;
632
624
}
633
625
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.
644
628
*
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.
647
631
*/
648
632
int
649
633
pqSendSome (PGconn * conn )
@@ -655,7 +639,7 @@ pqSendSome(PGconn *conn)
655
639
{
656
640
printfPQExpBuffer (& conn -> errorMessage ,
657
641
libpq_gettext ("connection not open\n" ));
658
- return EOF ;
642
+ return -1 ;
659
643
}
660
644
661
645
/*
@@ -713,7 +697,7 @@ pqSendSome(PGconn *conn)
713
697
printfPQExpBuffer (& conn -> errorMessage ,
714
698
libpq_gettext (
715
699
"server closed the connection unexpectedly\n"
716
- "\tThis probably means the server terminated abnormally\n"
700
+ "\tThis probably means the server terminated abnormally\n"
717
701
"\tbefore or while processing the request.\n" ));
718
702
719
703
/*
@@ -778,6 +762,7 @@ pqSendSome(PGconn *conn)
778
762
}
779
763
780
764
765
+
781
766
/*
782
767
* pqFlush: send any data waiting in the output buffer
783
768
*
790
775
pqFlush (PGconn * conn )
791
776
{
792
777
if (pqSendSome (conn ))
778
+ {
793
779
return EOF ;
780
+ }
794
781
return 0 ;
795
782
}
796
783
@@ -812,7 +799,7 @@ pqWait(int forRead, int forWrite, PGconn *conn)
812
799
{
813
800
printfPQExpBuffer (& conn -> errorMessage ,
814
801
libpq_gettext ("connection not open\n" ));
815
- return -1 ;
802
+ return EOF ;
816
803
}
817
804
818
805
if (forRead || forWrite )
@@ -913,20 +900,19 @@ libpq_gettext(const char *msgid)
913
900
* strerror replacement for windows:
914
901
*
915
902
* 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.
917
904
*/
918
905
const char *
919
906
winsock_strerror (int eno )
920
907
{
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)" */
924
910
int length ;
925
911
926
912
/* First try the "system table", this works on Win2k and up */
927
913
928
914
if (FormatMessage (
929
- FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM ,
915
+ FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM ,
930
916
0 ,
931
917
eno ,
932
918
MAKELANGID (LANG_NEUTRAL , SUBLANG_DEFAULT ),
0 commit comments