PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
fe-misc.c File Reference
#include "postgres_fe.h"
#include <signal.h>
#include <time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include "libpq-fe.h"
#include "libpq-int.h"
#include "mb/pg_wchar.h"
#include "pg_config_paths.h"
Include dependency graph for fe-misc.c:

Go to the source code of this file.

Functions

static int pqPutMsgBytes (const void *buf, size_t len, PGconn *conn)
 
static int pqSendSome (PGconn *conn, int len)
 
static int pqSocketCheck (PGconn *conn, int forRead, int forWrite, time_t end_time)
 
static int pqSocketPoll (int sock, int forRead, int forWrite, time_t end_time)
 
int PQlibVersion (void)
 
static void fputnbytes (FILE *f, const char *str, size_t n)
 
int pqGetc (char *result, PGconn *conn)
 
int pqPutc (char c, PGconn *conn)
 
static int pqGets_internal (PQExpBuffer buf, PGconn *conn, bool resetbuffer)
 
int pqGets (PQExpBuffer buf, PGconn *conn)
 
int pqGets_append (PQExpBuffer buf, PGconn *conn)
 
int pqPuts (const char *s, PGconn *conn)
 
int pqGetnchar (char *s, size_t len, PGconn *conn)
 
int pqSkipnchar (size_t len, PGconn *conn)
 
int pqPutnchar (const char *s, size_t len, PGconn *conn)
 
int pqGetInt (int *result, size_t bytes, PGconn *conn)
 
int pqPutInt (int value, size_t bytes, PGconn *conn)
 
int pqCheckOutBufferSpace (size_t bytes_needed, PGconn *conn)
 
int pqCheckInBufferSpace (size_t bytes_needed, PGconn *conn)
 
int pqPutMsgStart (char msg_type, bool force_len, PGconn *conn)
 
int pqPutMsgEnd (PGconn *conn)
 
int pqReadData (PGconn *conn)
 
int pqFlush (PGconn *conn)
 
int pqWait (int forRead, int forWrite, PGconn *conn)
 
int pqWaitTimed (int forRead, int forWrite, PGconn *conn, time_t finish_time)
 
int pqReadReady (PGconn *conn)
 
int pqWriteReady (PGconn *conn)
 
int PQmblen (const char *s, int encoding)
 
int PQdsplen (const char *s, int encoding)
 
int PQenv2encoding (void)
 

Function Documentation

static void fputnbytes ( FILE *  f,
const char *  str,
size_t  n 
)
static

Definition at line 84 of file fe-misc.c.

Referenced by pqGetnchar(), pqPutnchar(), and pqSkipnchar().

85 {
86  while (n-- > 0)
87  fputc(*str++, f);
88 }
int pqCheckInBufferSpace ( size_t  bytes_needed,
PGconn conn 
)

Definition at line 413 of file fe-misc.c.

References pg_conn::errorMessage, pg_conn::inBuffer, pg_conn::inBufSize, pg_conn::inCursor, pg_conn::inEnd, pg_conn::inStart, memmove, printfPQExpBuffer(), and realloc.

Referenced by getCopyDataMessage(), PQconnectPoll(), pqFunctionCall3(), pqParseInput3(), and pqReadData().

414 {
415  int newsize = conn->inBufSize;
416  char *newbuf;
417 
418  /* Quick exit if we have enough space */
419  if (bytes_needed <= (size_t) newsize)
420  return 0;
421 
422  /*
423  * Before concluding that we need to enlarge the buffer, left-justify
424  * whatever is in it and recheck. The caller's value of bytes_needed
425  * includes any data to the left of inStart, but we can delete that in
426  * preference to enlarging the buffer. It's slightly ugly to have this
427  * function do this, but it's better than making callers worry about it.
428  */
429  bytes_needed -= conn->inStart;
430 
431  if (conn->inStart < conn->inEnd)
432  {
433  if (conn->inStart > 0)
434  {
435  memmove(conn->inBuffer, conn->inBuffer + conn->inStart,
436  conn->inEnd - conn->inStart);
437  conn->inEnd -= conn->inStart;
438  conn->inCursor -= conn->inStart;
439  conn->inStart = 0;
440  }
441  }
442  else
443  {
444  /* buffer is logically empty, reset it */
445  conn->inStart = conn->inCursor = conn->inEnd = 0;
446  }
447 
448  /* Recheck whether we have enough space */
449  if (bytes_needed <= (size_t) newsize)
450  return 0;
451 
452  /*
453  * If we need to enlarge the buffer, we first try to double it in size; if
454  * that doesn't work, enlarge in multiples of 8K. This avoids thrashing
455  * the malloc pool by repeated small enlargements.
456  *
457  * Note: tests for newsize > 0 are to catch integer overflow.
458  */
459  do
460  {
461  newsize *= 2;
462  } while (newsize > 0 && bytes_needed > (size_t) newsize);
463 
464  if (newsize > 0 && bytes_needed <= (size_t) newsize)
465  {
466  newbuf = realloc(conn->inBuffer, newsize);
467  if (newbuf)
468  {
469  /* realloc succeeded */
470  conn->inBuffer = newbuf;
471  conn->inBufSize = newsize;
472  return 0;
473  }
474  }
475 
476  newsize = conn->inBufSize;
477  do
478  {
479  newsize += 8192;
480  } while (newsize > 0 && bytes_needed > (size_t) newsize);
481 
482  if (newsize > 0 && bytes_needed <= (size_t) newsize)
483  {
484  newbuf = realloc(conn->inBuffer, newsize);
485  if (newbuf)
486  {
487  /* realloc succeeded */
488  conn->inBuffer = newbuf;
489  conn->inBufSize = newsize;
490  return 0;
491  }
492  }
493 
494  /* realloc failed. Probably out of memory */
496  "cannot allocate memory for input buffer\n");
497  return EOF;
498 }
int inEnd
Definition: libpq-int.h:435
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
int inStart
Definition: libpq-int.h:433
int inBufSize
Definition: libpq-int.h:432
#define memmove(d, s, c)
Definition: c.h:1058
char * inBuffer
Definition: libpq-int.h:431
PQExpBufferData errorMessage
Definition: libpq-int.h:501
#define realloc(a, b)
Definition: header.h:60
int inCursor
Definition: libpq-int.h:434
int pqCheckOutBufferSpace ( size_t  bytes_needed,
PGconn conn 
)

Definition at line 349 of file fe-misc.c.

References pg_conn::errorMessage, pg_conn::outBuffer, pg_conn::outBufSize, printfPQExpBuffer(), and realloc.

Referenced by PQputCopyData(), pqPutMsgBytes(), and pqPutMsgStart().

350 {
351  int newsize = conn->outBufSize;
352  char *newbuf;
353 
354  /* Quick exit if we have enough space */
355  if (bytes_needed <= (size_t) newsize)
356  return 0;
357 
358  /*
359  * If we need to enlarge the buffer, we first try to double it in size; if
360  * that doesn't work, enlarge in multiples of 8K. This avoids thrashing
361  * the malloc pool by repeated small enlargements.
362  *
363  * Note: tests for newsize > 0 are to catch integer overflow.
364  */
365  do
366  {
367  newsize *= 2;
368  } while (newsize > 0 && bytes_needed > (size_t) newsize);
369 
370  if (newsize > 0 && bytes_needed <= (size_t) newsize)
371  {
372  newbuf = realloc(conn->outBuffer, newsize);
373  if (newbuf)
374  {
375  /* realloc succeeded */
376  conn->outBuffer = newbuf;
377  conn->outBufSize = newsize;
378  return 0;
379  }
380  }
381 
382  newsize = conn->outBufSize;
383  do
384  {
385  newsize += 8192;
386  } while (newsize > 0 && bytes_needed > (size_t) newsize);
387 
388  if (newsize > 0 && bytes_needed <= (size_t) newsize)
389  {
390  newbuf = realloc(conn->outBuffer, newsize);
391  if (newbuf)
392  {
393  /* realloc succeeded */
394  conn->outBuffer = newbuf;
395  conn->outBufSize = newsize;
396  return 0;
397  }
398  }
399 
400  /* realloc failed. Probably out of memory */
402  "cannot allocate memory for output buffer\n");
403  return EOF;
404 }
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PQExpBufferData errorMessage
Definition: libpq-int.h:501
int outBufSize
Definition: libpq-int.h:439
#define realloc(a, b)
Definition: header.h:60
char * outBuffer
Definition: libpq-int.h:438
int PQdsplen ( const char *  s,
int  encoding 
)

Definition at line 1197 of file fe-misc.c.

References pg_encoding_dsplen().

Referenced by pg_wcsformat(), pg_wcssize(), pg_wcswidth(), and strlen_max_width().

1198 {
1199  return pg_encoding_dsplen(encoding, s);
1200 }
int pg_encoding_dsplen(int encoding, const char *mbstr)
Definition: wchar.c:1796
static char * encoding
Definition: initdb.c:121
int PQenv2encoding ( void  )

Definition at line 1206 of file fe-misc.c.

References encoding, pg_char_to_encoding(), and PG_SQL_ASCII.

Referenced by main().

1207 {
1208  char *str;
1209  int encoding = PG_SQL_ASCII;
1210 
1211  str = getenv("PGCLIENTENCODING");
1212  if (str && *str != '\0')
1213  {
1214  encoding = pg_char_to_encoding(str);
1215  if (encoding < 0)
1216  encoding = PG_SQL_ASCII;
1217  }
1218  return encoding;
1219 }
int pg_char_to_encoding(const char *name)
Definition: encnames.c:475
static char * encoding
Definition: initdb.c:121
int pqFlush ( PGconn conn)

Definition at line 966 of file fe-misc.c.

References pg_conn::outCount, pg_conn::Pfdebug, and pqSendSome().

Referenced by PQconnectPoll(), PQconsumeInput(), pqEndcopy2(), pqEndcopy3(), PQflush(), pqFunctionCall2(), pqFunctionCall3(), PQgetResult(), pqPacketSend(), PQputCopyData(), PQputCopyEnd(), PQsendDescribe(), PQsendPrepare(), PQsendQuery(), PQsendQueryGuts(), PQsetnonblocking(), and sendTerminateConn().

967 {
968  if (conn->Pfdebug)
969  fflush(conn->Pfdebug);
970 
971  if (conn->outCount > 0)
972  return pqSendSome(conn, conn->outCount);
973 
974  return 0;
975 }
int outCount
Definition: libpq-int.h:440
FILE * Pfdebug
Definition: libpq-int.h:367
static int pqSendSome(PGconn *conn, int len)
Definition: fe-misc.c:834
int pqGetc ( char *  result,
PGconn conn 
)

Definition at line 99 of file fe-misc.c.

References pg_conn::inBuffer, pg_conn::inCursor, pg_conn::inEnd, and pg_conn::Pfdebug.

Referenced by getCopyDataMessage(), getCopyStart(), getReadyForQuery(), PQconnectPoll(), pqFunctionCall2(), pqFunctionCall3(), pqGetErrorNotice3(), pqParseInput2(), and pqParseInput3().

100 {
101  if (conn->inCursor >= conn->inEnd)
102  return EOF;
103 
104  *result = conn->inBuffer[conn->inCursor++];
105 
106  if (conn->Pfdebug)
107  fprintf(conn->Pfdebug, "From backend> %c\n", *result);
108 
109  return 0;
110 }
int inEnd
Definition: libpq-int.h:435
FILE * Pfdebug
Definition: libpq-int.h:367
char * inBuffer
Definition: libpq-int.h:431
int inCursor
Definition: libpq-int.h:434
int pqGetInt ( int *  result,
size_t  bytes,
PGconn conn 
)

Definition at line 272 of file fe-misc.c.

References pg_conn::inBuffer, pg_conn::inCursor, pg_conn::inEnd, pg_conn::noticeHooks, pg_conn::Pfdebug, and pqInternalNotice().

Referenced by getAnotherTuple(), getCopyDataMessage(), getCopyStart(), getNotify(), getParamDescriptions(), getRowDescriptions(), PQconnectPoll(), pqFunctionCall2(), pqFunctionCall3(), pqParseInput2(), and pqParseInput3().

273 {
274  uint16 tmp2;
275  uint32 tmp4;
276 
277  switch (bytes)
278  {
279  case 2:
280  if (conn->inCursor + 2 > conn->inEnd)
281  return EOF;
282  memcpy(&tmp2, conn->inBuffer + conn->inCursor, 2);
283  conn->inCursor += 2;
284  *result = (int) ntohs(tmp2);
285  break;
286  case 4:
287  if (conn->inCursor + 4 > conn->inEnd)
288  return EOF;
289  memcpy(&tmp4, conn->inBuffer + conn->inCursor, 4);
290  conn->inCursor += 4;
291  *result = (int) ntohl(tmp4);
292  break;
293  default:
295  "integer of size %lu not supported by pqGetInt",
296  (unsigned long) bytes);
297  return EOF;
298  }
299 
300  if (conn->Pfdebug)
301  fprintf(conn->Pfdebug, "From backend (#%lu)> %d\n", (unsigned long) bytes, *result);
302 
303  return 0;
304 }
int inEnd
Definition: libpq-int.h:435
FILE * Pfdebug
Definition: libpq-int.h:367
unsigned short uint16
Definition: c.h:267
PGNoticeHooks noticeHooks
Definition: libpq-int.h:370
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
Definition: fe-exec.c:801
unsigned int uint32
Definition: c.h:268
char * inBuffer
Definition: libpq-int.h:431
int inCursor
Definition: libpq-int.h:434
int pqGetnchar ( char *  s,
size_t  len,
PGconn conn 
)

Definition at line 200 of file fe-misc.c.

References fputnbytes(), pg_conn::inBuffer, pg_conn::inCursor, pg_conn::inEnd, and pg_conn::Pfdebug.

Referenced by getAnotherTuple(), PQconnectPoll(), pqFunctionCall2(), and pqFunctionCall3().

201 {
202  if (len > (size_t) (conn->inEnd - conn->inCursor))
203  return EOF;
204 
205  memcpy(s, conn->inBuffer + conn->inCursor, len);
206  /* no terminating null */
207 
208  conn->inCursor += len;
209 
210  if (conn->Pfdebug)
211  {
212  fprintf(conn->Pfdebug, "From backend (%lu)> ", (unsigned long) len);
213  fputnbytes(conn->Pfdebug, s, len);
214  fprintf(conn->Pfdebug, "\n");
215  }
216 
217  return 0;
218 }
int inEnd
Definition: libpq-int.h:435
FILE * Pfdebug
Definition: libpq-int.h:367
char * inBuffer
Definition: libpq-int.h:431
static void fputnbytes(FILE *f, const char *str, size_t n)
Definition: fe-misc.c:84
int inCursor
Definition: libpq-int.h:434
int pqGets ( PQExpBuffer  buf,
PGconn conn 
)

Definition at line 168 of file fe-misc.c.

References pqGets_internal().

Referenced by getNotify(), getParameterStatus(), getRowDescriptions(), pqGetErrorNotice2(), pqGetErrorNotice3(), pqParseInput2(), and pqParseInput3().

169 {
170  return pqGets_internal(buf, conn, true);
171 }
static int pqGets_internal(PQExpBuffer buf, PGconn *conn, bool resetbuffer)
Definition: fe-misc.c:137
int pqGets_append ( PQExpBuffer  buf,
PGconn conn 
)

Definition at line 174 of file fe-misc.c.

References pqGets_internal().

Referenced by PQconnectPoll().

175 {
176  return pqGets_internal(buf, conn, false);
177 }
static int pqGets_internal(PQExpBuffer buf, PGconn *conn, bool resetbuffer)
Definition: fe-misc.c:137
static int pqGets_internal ( PQExpBuffer  buf,
PGconn conn,
bool  resetbuffer 
)
static

Definition at line 137 of file fe-misc.c.

References appendBinaryPQExpBuffer(), PQExpBufferData::data, pg_conn::inBuffer, pg_conn::inCursor, pg_conn::inEnd, pg_conn::Pfdebug, and resetPQExpBuffer().

Referenced by pqGets(), and pqGets_append().

138 {
139  /* Copy conn data to locals for faster search loop */
140  char *inBuffer = conn->inBuffer;
141  int inCursor = conn->inCursor;
142  int inEnd = conn->inEnd;
143  int slen;
144 
145  while (inCursor < inEnd && inBuffer[inCursor])
146  inCursor++;
147 
148  if (inCursor >= inEnd)
149  return EOF;
150 
151  slen = inCursor - conn->inCursor;
152 
153  if (resetbuffer)
154  resetPQExpBuffer(buf);
155 
156  appendBinaryPQExpBuffer(buf, inBuffer + conn->inCursor, slen);
157 
158  conn->inCursor = ++inCursor;
159 
160  if (conn->Pfdebug)
161  fprintf(conn->Pfdebug, "From backend> \"%s\"\n",
162  buf->data);
163 
164  return 0;
165 }
int inEnd
Definition: libpq-int.h:435
FILE * Pfdebug
Definition: libpq-int.h:367
char * inBuffer
Definition: libpq-int.h:431
int inCursor
Definition: libpq-int.h:434
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
Definition: pqexpbuffer.c:415
int PQlibVersion ( void  )

Definition at line 72 of file fe-misc.c.

73 {
74  return PG_VERSION_NUM;
75 }
int PQmblen ( const char *  s,
int  encoding 
)

Definition at line 1187 of file fe-misc.c.

References pg_encoding_mblen().

Referenced by appendStringLiteral(), command_no_begin(), do_field(), is_select_command(), pg_wcsformat(), pg_wcssize(), pg_wcswidth(), processSQLNamePattern(), quote_if_needed(), skip_white_space(), strip_quotes(), strlen_max_width(), and strtokx().

1188 {
1189  return pg_encoding_mblen(encoding, s);
1190 }
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition: wchar.c:1785
static char * encoding
Definition: initdb.c:121
int pqPutc ( char  c,
PGconn conn 
)

Definition at line 117 of file fe-misc.c.

References pg_conn::Pfdebug, and pqPutMsgBytes().

Referenced by PQsendDescribe(), and PQsendQueryGuts().

118 {
119  if (pqPutMsgBytes(&c, 1, conn))
120  return EOF;
121 
122  if (conn->Pfdebug)
123  fprintf(conn->Pfdebug, "To backend> %c\n", c);
124 
125  return 0;
126 }
FILE * Pfdebug
Definition: libpq-int.h:367
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn)
Definition: fe-misc.c:569
char * c
int pqPutInt ( int  value,
size_t  bytes,
PGconn conn 
)

Definition at line 312 of file fe-misc.c.

References pg_conn::noticeHooks, pg_conn::Pfdebug, pqInternalNotice(), and pqPutMsgBytes().

Referenced by pqFunctionCall2(), pqFunctionCall3(), PQsendPrepare(), and PQsendQueryGuts().

313 {
314  uint16 tmp2;
315  uint32 tmp4;
316 
317  switch (bytes)
318  {
319  case 2:
320  tmp2 = htons((uint16) value);
321  if (pqPutMsgBytes((const char *) &tmp2, 2, conn))
322  return EOF;
323  break;
324  case 4:
325  tmp4 = htonl((uint32) value);
326  if (pqPutMsgBytes((const char *) &tmp4, 4, conn))
327  return EOF;
328  break;
329  default:
331  "integer of size %lu not supported by pqPutInt",
332  (unsigned long) bytes);
333  return EOF;
334  }
335 
336  if (conn->Pfdebug)
337  fprintf(conn->Pfdebug, "To backend (%lu#)> %d\n", (unsigned long) bytes, value);
338 
339  return 0;
340 }
static struct @76 value
FILE * Pfdebug
Definition: libpq-int.h:367
unsigned short uint16
Definition: c.h:267
PGNoticeHooks noticeHooks
Definition: libpq-int.h:370
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn)
Definition: fe-misc.c:569
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
Definition: fe-exec.c:801
unsigned int uint32
Definition: c.h:268
static int pqPutMsgBytes ( const void *  buf,
size_t  len,
PGconn conn 
)
static

Definition at line 569 of file fe-misc.c.

References pg_conn::outBuffer, pg_conn::outMsgEnd, and pqCheckOutBufferSpace().

Referenced by pqPutc(), pqPutInt(), pqPutnchar(), and pqPuts().

570 {
571  /* make sure there is room for it */
572  if (pqCheckOutBufferSpace(conn->outMsgEnd + len, conn))
573  return EOF;
574  /* okay, save the data */
575  memcpy(conn->outBuffer + conn->outMsgEnd, buf, len);
576  conn->outMsgEnd += len;
577  /* no Pfdebug call here, caller should do it */
578  return 0;
579 }
int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn)
Definition: fe-misc.c:349
int outMsgEnd
Definition: libpq-int.h:445
static char * buf
Definition: pg_test_fsync.c:65
char * outBuffer
Definition: libpq-int.h:438
int pqPutMsgEnd ( PGconn conn)

Definition at line 592 of file fe-misc.c.

References pg_conn::outBuffer, pg_conn::outCount, pg_conn::outMsgEnd, pg_conn::outMsgStart, pg_conn::Pfdebug, and pqSendSome().

Referenced by pqEndcopy3(), pqFunctionCall2(), pqFunctionCall3(), pqPacketSend(), PQputCopyData(), PQputCopyEnd(), PQsendDescribe(), PQsendPrepare(), PQsendQuery(), PQsendQueryGuts(), and sendTerminateConn().

593 {
594  if (conn->Pfdebug)
595  fprintf(conn->Pfdebug, "To backend> Msg complete, length %u\n",
596  conn->outMsgEnd - conn->outCount);
597 
598  /* Fill in length word if needed */
599  if (conn->outMsgStart >= 0)
600  {
601  uint32 msgLen = conn->outMsgEnd - conn->outMsgStart;
602 
603  msgLen = htonl(msgLen);
604  memcpy(conn->outBuffer + conn->outMsgStart, &msgLen, 4);
605  }
606 
607  /* Make message eligible to send */
608  conn->outCount = conn->outMsgEnd;
609 
610  if (conn->outCount >= 8192)
611  {
612  int toSend = conn->outCount - (conn->outCount % 8192);
613 
614  if (pqSendSome(conn, toSend) < 0)
615  return EOF;
616  /* in nonblock mode, don't complain if unable to send it all */
617  }
618 
619  return 0;
620 }
int outCount
Definition: libpq-int.h:440
int outMsgEnd
Definition: libpq-int.h:445
FILE * Pfdebug
Definition: libpq-int.h:367
unsigned int uint32
Definition: c.h:268
int outMsgStart
Definition: libpq-int.h:443
char * outBuffer
Definition: libpq-int.h:438
static int pqSendSome(PGconn *conn, int len)
Definition: fe-misc.c:834
int pqPutMsgStart ( char  msg_type,
bool  force_len,
PGconn conn 
)

Definition at line 524 of file fe-misc.c.

References pg_conn::outBuffer, pg_conn::outCount, pg_conn::outMsgEnd, pg_conn::outMsgStart, pg_conn::Pfdebug, PG_PROTOCOL_MAJOR, pqCheckOutBufferSpace(), and pg_conn::pversion.

Referenced by pqEndcopy3(), pqFunctionCall2(), pqFunctionCall3(), pqPacketSend(), PQputCopyData(), PQputCopyEnd(), PQsendDescribe(), PQsendPrepare(), PQsendQuery(), PQsendQueryGuts(), and sendTerminateConn().

525 {
526  int lenPos;
527  int endPos;
528 
529  /* allow room for message type byte */
530  if (msg_type)
531  endPos = conn->outCount + 1;
532  else
533  endPos = conn->outCount;
534 
535  /* do we want a length word? */
536  if (force_len || PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
537  {
538  lenPos = endPos;
539  /* allow room for message length */
540  endPos += 4;
541  }
542  else
543  lenPos = -1;
544 
545  /* make sure there is room for message header */
546  if (pqCheckOutBufferSpace(endPos, conn))
547  return EOF;
548  /* okay, save the message type byte if any */
549  if (msg_type)
550  conn->outBuffer[conn->outCount] = msg_type;
551  /* set up the message pointers */
552  conn->outMsgStart = lenPos;
553  conn->outMsgEnd = endPos;
554  /* length word, if needed, will be filled in by pqPutMsgEnd */
555 
556  if (conn->Pfdebug)
557  fprintf(conn->Pfdebug, "To backend> Msg %c\n",
558  msg_type ? msg_type : ' ');
559 
560  return 0;
561 }
int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn)
Definition: fe-misc.c:349
int outCount
Definition: libpq-int.h:440
int outMsgEnd
Definition: libpq-int.h:445
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
FILE * Pfdebug
Definition: libpq-int.h:367
int outMsgStart
Definition: libpq-int.h:443
ProtocolVersion pversion
Definition: libpq-int.h:404
char * outBuffer
Definition: libpq-int.h:438
int pqPutnchar ( const char *  s,
size_t  len,
PGconn conn 
)

Definition at line 251 of file fe-misc.c.

References fputnbytes(), pg_conn::Pfdebug, and pqPutMsgBytes().

Referenced by pqFunctionCall2(), pqFunctionCall3(), pqPacketSend(), PQputCopyData(), PQputCopyEnd(), and PQsendQueryGuts().

252 {
253  if (pqPutMsgBytes(s, len, conn))
254  return EOF;
255 
256  if (conn->Pfdebug)
257  {
258  fprintf(conn->Pfdebug, "To backend> ");
259  fputnbytes(conn->Pfdebug, s, len);
260  fprintf(conn->Pfdebug, "\n");
261  }
262 
263  return 0;
264 }
FILE * Pfdebug
Definition: libpq-int.h:367
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn)
Definition: fe-misc.c:569
static void fputnbytes(FILE *f, const char *str, size_t n)
Definition: fe-misc.c:84
int pqPuts ( const char *  s,
PGconn conn 
)

Definition at line 184 of file fe-misc.c.

References pg_conn::Pfdebug, and pqPutMsgBytes().

Referenced by pqFunctionCall2(), PQputCopyEnd(), PQsendDescribe(), PQsendPrepare(), PQsendQuery(), and PQsendQueryGuts().

185 {
186  if (pqPutMsgBytes(s, strlen(s) + 1, conn))
187  return EOF;
188 
189  if (conn->Pfdebug)
190  fprintf(conn->Pfdebug, "To backend> \"%s\"\n", s);
191 
192  return 0;
193 }
FILE * Pfdebug
Definition: libpq-int.h:367
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn)
Definition: fe-misc.c:569
int pqReadData ( PGconn conn)

Definition at line 634 of file fe-misc.c.

References CONNECTION_BAD, EAGAIN, ECONNRESET, EINTR, pg_conn::errorMessage, EWOULDBLOCK, pg_conn::inBuffer, pg_conn::inBufSize, pg_conn::inCursor, pg_conn::inEnd, pg_conn::inStart, libpq_gettext, memmove, PGINVALID_SOCKET, pqCheckInBufferSpace(), pqDropConnection(), pqReadReady(), pqsecure_read(), printfPQExpBuffer(), pg_conn::sock, SOCK_ERRNO, and pg_conn::status.

Referenced by PQconnectPoll(), PQconsumeInput(), pqFunctionCall2(), pqFunctionCall3(), pqGetCopyData2(), pqGetCopyData3(), pqGetline2(), pqGetline3(), PQgetResult(), pqHandleSendFailure(), pqSendSome(), and pqSetenvPoll().

635 {
636  int someread = 0;
637  int nread;
638 
639  if (conn->sock == PGINVALID_SOCKET)
640  {
642  libpq_gettext("connection not open\n"));
643  return -1;
644  }
645 
646  /* Left-justify any data in the buffer to make room */
647  if (conn->inStart < conn->inEnd)
648  {
649  if (conn->inStart > 0)
650  {
651  memmove(conn->inBuffer, conn->inBuffer + conn->inStart,
652  conn->inEnd - conn->inStart);
653  conn->inEnd -= conn->inStart;
654  conn->inCursor -= conn->inStart;
655  conn->inStart = 0;
656  }
657  }
658  else
659  {
660  /* buffer is logically empty, reset it */
661  conn->inStart = conn->inCursor = conn->inEnd = 0;
662  }
663 
664  /*
665  * If the buffer is fairly full, enlarge it. We need to be able to enlarge
666  * the buffer in case a single message exceeds the initial buffer size. We
667  * enlarge before filling the buffer entirely so as to avoid asking the
668  * kernel for a partial packet. The magic constant here should be large
669  * enough for a TCP packet or Unix pipe bufferload. 8K is the usual pipe
670  * buffer size, so...
671  */
672  if (conn->inBufSize - conn->inEnd < 8192)
673  {
674  if (pqCheckInBufferSpace(conn->inEnd + (size_t) 8192, conn))
675  {
676  /*
677  * We don't insist that the enlarge worked, but we need some room
678  */
679  if (conn->inBufSize - conn->inEnd < 100)
680  return -1; /* errorMessage already set */
681  }
682  }
683 
684  /* OK, try to read some data */
685 retry3:
686  nread = pqsecure_read(conn, conn->inBuffer + conn->inEnd,
687  conn->inBufSize - conn->inEnd);
688  if (nread < 0)
689  {
690  if (SOCK_ERRNO == EINTR)
691  goto retry3;
692  /* Some systems return EAGAIN/EWOULDBLOCK for no data */
693 #ifdef EAGAIN
694  if (SOCK_ERRNO == EAGAIN)
695  return someread;
696 #endif
697 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
698  if (SOCK_ERRNO == EWOULDBLOCK)
699  return someread;
700 #endif
701  /* We might get ECONNRESET here if using TCP and backend died */
702 #ifdef ECONNRESET
703  if (SOCK_ERRNO == ECONNRESET)
704  goto definitelyFailed;
705 #endif
706  /* pqsecure_read set the error message for us */
707  return -1;
708  }
709  if (nread > 0)
710  {
711  conn->inEnd += nread;
712 
713  /*
714  * Hack to deal with the fact that some kernels will only give us back
715  * 1 packet per recv() call, even if we asked for more and there is
716  * more available. If it looks like we are reading a long message,
717  * loop back to recv() again immediately, until we run out of data or
718  * buffer space. Without this, the block-and-restart behavior of
719  * libpq's higher levels leads to O(N^2) performance on long messages.
720  *
721  * Since we left-justified the data above, conn->inEnd gives the
722  * amount of data already read in the current message. We consider
723  * the message "long" once we have acquired 32k ...
724  */
725  if (conn->inEnd > 32768 &&
726  (conn->inBufSize - conn->inEnd) >= 8192)
727  {
728  someread = 1;
729  goto retry3;
730  }
731  return 1;
732  }
733 
734  if (someread)
735  return 1; /* got a zero read after successful tries */
736 
737  /*
738  * A return value of 0 could mean just that no data is now available, or
739  * it could mean EOF --- that is, the server has closed the connection.
740  * Since we have the socket in nonblock mode, the only way to tell the
741  * difference is to see if select() is saying that the file is ready.
742  * Grumble. Fortunately, we don't expect this path to be taken much,
743  * since in normal practice we should not be trying to read data unless
744  * the file selected for reading already.
745  *
746  * In SSL mode it's even worse: SSL_read() could say WANT_READ and then
747  * data could arrive before we make the pqReadReady() test, but the second
748  * SSL_read() could still say WANT_READ because the data received was not
749  * a complete SSL record. So we must play dumb and assume there is more
750  * data, relying on the SSL layer to detect true EOF.
751  */
752 
753 #ifdef USE_SSL
754  if (conn->ssl_in_use)
755  return 0;
756 #endif
757 
758  switch (pqReadReady(conn))
759  {
760  case 0:
761  /* definitely no data available */
762  return 0;
763  case 1:
764  /* ready for read */
765  break;
766  default:
767  /* we override pqReadReady's message with something more useful */
768  goto definitelyEOF;
769  }
770 
771  /*
772  * Still not sure that it's EOF, because some data could have just
773  * arrived.
774  */
775 retry4:
776  nread = pqsecure_read(conn, conn->inBuffer + conn->inEnd,
777  conn->inBufSize - conn->inEnd);
778  if (nread < 0)
779  {
780  if (SOCK_ERRNO == EINTR)
781  goto retry4;
782  /* Some systems return EAGAIN/EWOULDBLOCK for no data */
783 #ifdef EAGAIN
784  if (SOCK_ERRNO == EAGAIN)
785  return 0;
786 #endif
787 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
788  if (SOCK_ERRNO == EWOULDBLOCK)
789  return 0;
790 #endif
791  /* We might get ECONNRESET here if using TCP and backend died */
792 #ifdef ECONNRESET
793  if (SOCK_ERRNO == ECONNRESET)
794  goto definitelyFailed;
795 #endif
796  /* pqsecure_read set the error message for us */
797  return -1;
798  }
799  if (nread > 0)
800  {
801  conn->inEnd += nread;
802  return 1;
803  }
804 
805  /*
806  * OK, we are getting a zero read even though select() says ready. This
807  * means the connection has been closed. Cope.
808  */
809 definitelyEOF:
812  "server closed the connection unexpectedly\n"
813  "\tThis probably means the server terminated abnormally\n"
814  "\tbefore or while processing the request.\n"));
815 
816  /* Come here if lower-level code already set a suitable errorMessage */
817 definitelyFailed:
818  /* Do *not* drop any already-read data; caller still wants it */
819  pqDropConnection(conn, false);
820  conn->status = CONNECTION_BAD; /* No more connection to backend */
821  return -1;
822 }
#define EWOULDBLOCK
Definition: win32.h:301
int inEnd
Definition: libpq-int.h:435
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
int inStart
Definition: libpq-int.h:433
int pqReadReady(PGconn *conn)
Definition: fe-misc.c:1028
int pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn)
Definition: fe-misc.c:413
ssize_t pqsecure_read(PGconn *conn, void *ptr, size_t len)
Definition: fe-secure.c:205
void pqDropConnection(PGconn *conn, bool flushInput)
Definition: fe-connect.c:409
#define ECONNRESET
Definition: win32.h:305
#define EAGAIN
Definition: win32.h:293
#define SOCK_ERRNO
Definition: libpq-int.h:705
int inBufSize
Definition: libpq-int.h:432
#define memmove(d, s, c)
Definition: c.h:1058
pgsocket sock
Definition: libpq-int.h:400
#define PGINVALID_SOCKET
Definition: port.h:24
char * inBuffer
Definition: libpq-int.h:431
#define EINTR
Definition: win32.h:295
PQExpBufferData errorMessage
Definition: libpq-int.h:501
ConnStatusType status
Definition: libpq-int.h:378
int inCursor
Definition: libpq-int.h:434
#define libpq_gettext(x)
Definition: libpq-int.h:692
int pqReadReady ( PGconn conn)

Definition at line 1028 of file fe-misc.c.

References pqSocketCheck().

Referenced by pqReadData().

1029 {
1030  return pqSocketCheck(conn, 1, 0, (time_t) 0);
1031 }
static int pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
Definition: fe-misc.c:1052
static int pqSendSome ( PGconn conn,
int  len 
)
static

Definition at line 834 of file fe-misc.c.

References EAGAIN, EINTR, pg_conn::errorMessage, EWOULDBLOCK, libpq_gettext, memmove, Min, pg_conn::outBuffer, pg_conn::outCount, PGINVALID_SOCKET, pqIsnonblocking, pqReadData(), pqsecure_write(), pqWait(), printfPQExpBuffer(), remaining, pg_conn::sock, SOCK_ERRNO, and TRUE.

Referenced by pqFlush(), and pqPutMsgEnd().

835 {
836  char *ptr = conn->outBuffer;
837  int remaining = conn->outCount;
838  int result = 0;
839 
840  if (conn->sock == PGINVALID_SOCKET)
841  {
843  libpq_gettext("connection not open\n"));
844  /* Discard queued data; no chance it'll ever be sent */
845  conn->outCount = 0;
846  return -1;
847  }
848 
849  /* while there's still data to send */
850  while (len > 0)
851  {
852  int sent;
853 
854 #ifndef WIN32
855  sent = pqsecure_write(conn, ptr, len);
856 #else
857 
858  /*
859  * Windows can fail on large sends, per KB article Q201213. The
860  * failure-point appears to be different in different versions of
861  * Windows, but 64k should always be safe.
862  */
863  sent = pqsecure_write(conn, ptr, Min(len, 65536));
864 #endif
865 
866  if (sent < 0)
867  {
868  /* Anything except EAGAIN/EWOULDBLOCK/EINTR is trouble */
869  switch (SOCK_ERRNO)
870  {
871 #ifdef EAGAIN
872  case EAGAIN:
873  break;
874 #endif
875 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
876  case EWOULDBLOCK:
877  break;
878 #endif
879  case EINTR:
880  continue;
881 
882  default:
883  /* pqsecure_write set the error message for us */
884 
885  /*
886  * We used to close the socket here, but that's a bad idea
887  * since there might be unread data waiting (typically, a
888  * NOTICE message from the backend telling us it's
889  * committing hara-kiri...). Leave the socket open until
890  * pqReadData finds no more data can be read. But abandon
891  * attempt to send data.
892  */
893  conn->outCount = 0;
894  return -1;
895  }
896  }
897  else
898  {
899  ptr += sent;
900  len -= sent;
901  remaining -= sent;
902  }
903 
904  if (len > 0)
905  {
906  /*
907  * We didn't send it all, wait till we can send more.
908  *
909  * There are scenarios in which we can't send data because the
910  * communications channel is full, but we cannot expect the server
911  * to clear the channel eventually because it's blocked trying to
912  * send data to us. (This can happen when we are sending a large
913  * amount of COPY data, and the server has generated lots of
914  * NOTICE responses.) To avoid a deadlock situation, we must be
915  * prepared to accept and buffer incoming data before we try
916  * again. Furthermore, it is possible that such incoming data
917  * might not arrive until after we've gone to sleep. Therefore,
918  * we wait for either read ready or write ready.
919  *
920  * In non-blocking mode, we don't wait here directly, but return 1
921  * to indicate that data is still pending. The caller should wait
922  * for both read and write ready conditions, and call
923  * PQconsumeInput() on read ready, but just in case it doesn't, we
924  * call pqReadData() ourselves before returning. That's not
925  * enough if the data has not arrived yet, but it's the best we
926  * can do, and works pretty well in practice. (The documentation
927  * used to say that you only need to wait for write-ready, so
928  * there are still plenty of applications like that out there.)
929  */
930  if (pqReadData(conn) < 0)
931  {
932  result = -1; /* error message already set up */
933  break;
934  }
935 
936  if (pqIsnonblocking(conn))
937  {
938  result = 1;
939  break;
940  }
941 
942  if (pqWait(TRUE, TRUE, conn))
943  {
944  result = -1;
945  break;
946  }
947  }
948  }
949 
950  /* shift the remaining contents of the buffer */
951  if (remaining > 0)
952  memmove(conn->outBuffer, ptr, remaining);
953  conn->outCount = remaining;
954 
955  return result;
956 }
int remaining
Definition: informix.c:692
#define EWOULDBLOCK
Definition: win32.h:301
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
#define pqIsnonblocking(conn)
Definition: libpq-int.h:686
int outCount
Definition: libpq-int.h:440
#define Min(x, y)
Definition: c.h:806
#define EAGAIN
Definition: win32.h:293
ssize_t pqsecure_write(PGconn *conn, const void *ptr, size_t len)
Definition: fe-secure.c:282
#define SOCK_ERRNO
Definition: libpq-int.h:705
int pqReadData(PGconn *conn)
Definition: fe-misc.c:634
int pqWait(int forRead, int forWrite, PGconn *conn)
Definition: fe-misc.c:989
#define memmove(d, s, c)
Definition: c.h:1058
pgsocket sock
Definition: libpq-int.h:400
#define PGINVALID_SOCKET
Definition: port.h:24
#define EINTR
Definition: win32.h:295
PQExpBufferData errorMessage
Definition: libpq-int.h:501
char * outBuffer
Definition: libpq-int.h:438
#define TRUE
Definition: c.h:217
#define libpq_gettext(x)
Definition: libpq-int.h:692
int pqSkipnchar ( size_t  len,
PGconn conn 
)

Definition at line 229 of file fe-misc.c.

References fputnbytes(), pg_conn::inBuffer, pg_conn::inCursor, pg_conn::inEnd, and pg_conn::Pfdebug.

Referenced by getAnotherTuple().

230 {
231  if (len > (size_t) (conn->inEnd - conn->inCursor))
232  return EOF;
233 
234  if (conn->Pfdebug)
235  {
236  fprintf(conn->Pfdebug, "From backend (%lu)> ", (unsigned long) len);
237  fputnbytes(conn->Pfdebug, conn->inBuffer + conn->inCursor, len);
238  fprintf(conn->Pfdebug, "\n");
239  }
240 
241  conn->inCursor += len;
242 
243  return 0;
244 }
int inEnd
Definition: libpq-int.h:435
FILE * Pfdebug
Definition: libpq-int.h:367
char * inBuffer
Definition: libpq-int.h:431
static void fputnbytes(FILE *f, const char *str, size_t n)
Definition: fe-misc.c:84
int inCursor
Definition: libpq-int.h:434
static int pqSocketCheck ( PGconn conn,
int  forRead,
int  forWrite,
time_t  end_time 
)
static

Definition at line 1052 of file fe-misc.c.

References EINTR, pg_conn::errorMessage, libpq_gettext, PGINVALID_SOCKET, pgtls_read_pending(), pqSocketPoll(), printfPQExpBuffer(), pg_conn::sock, SOCK_ERRNO, and SOCK_STRERROR.

Referenced by pqReadReady(), pqWaitTimed(), and pqWriteReady().

1053 {
1054  int result;
1055 
1056  if (!conn)
1057  return -1;
1058  if (conn->sock == PGINVALID_SOCKET)
1059  {
1061  libpq_gettext("invalid socket\n"));
1062  return -1;
1063  }
1064 
1065 #ifdef USE_SSL
1066  /* Check for SSL library buffering read bytes */
1067  if (forRead && conn->ssl_in_use && pgtls_read_pending(conn) > 0)
1068  {
1069  /* short-circuit the select */
1070  return 1;
1071  }
1072 #endif
1073 
1074  /* We will retry as long as we get EINTR */
1075  do
1076  result = pqSocketPoll(conn->sock, forRead, forWrite, end_time);
1077  while (result < 0 && SOCK_ERRNO == EINTR);
1078 
1079  if (result < 0)
1080  {
1081  char sebuf[256];
1082 
1084  libpq_gettext("select() failed: %s\n"),
1085  SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
1086  }
1087 
1088  return result;
1089 }
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
static int pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time)
Definition: fe-misc.c:1102
#define SOCK_STRERROR
Definition: libpq-int.h:706
int64 end_time
Definition: pgbench.c:100
#define SOCK_ERRNO
Definition: libpq-int.h:705
bool pgtls_read_pending(PGconn *conn)
pgsocket sock
Definition: libpq-int.h:400
#define PGINVALID_SOCKET
Definition: port.h:24
#define EINTR
Definition: win32.h:295
PQExpBufferData errorMessage
Definition: libpq-int.h:501
#define libpq_gettext(x)
Definition: libpq-int.h:692
static int pqSocketPoll ( int  sock,
int  forRead,
int  forWrite,
time_t  end_time 
)
static

Definition at line 1102 of file fe-misc.c.

References now(), NULL, and select.

Referenced by pqSocketCheck().

1103 {
1104  /* We use poll(2) if available, otherwise select(2) */
1105 #ifdef HAVE_POLL
1106  struct pollfd input_fd;
1107  int timeout_ms;
1108 
1109  if (!forRead && !forWrite)
1110  return 0;
1111 
1112  input_fd.fd = sock;
1113  input_fd.events = POLLERR;
1114  input_fd.revents = 0;
1115 
1116  if (forRead)
1117  input_fd.events |= POLLIN;
1118  if (forWrite)
1119  input_fd.events |= POLLOUT;
1120 
1121  /* Compute appropriate timeout interval */
1122  if (end_time == ((time_t) -1))
1123  timeout_ms = -1;
1124  else
1125  {
1126  time_t now = time(NULL);
1127 
1128  if (end_time > now)
1129  timeout_ms = (end_time - now) * 1000;
1130  else
1131  timeout_ms = 0;
1132  }
1133 
1134  return poll(&input_fd, 1, timeout_ms);
1135 #else /* !HAVE_POLL */
1136 
1137  fd_set input_mask;
1138  fd_set output_mask;
1139  fd_set except_mask;
1140  struct timeval timeout;
1141  struct timeval *ptr_timeout;
1142 
1143  if (!forRead && !forWrite)
1144  return 0;
1145 
1146  FD_ZERO(&input_mask);
1147  FD_ZERO(&output_mask);
1148  FD_ZERO(&except_mask);
1149  if (forRead)
1150  FD_SET(sock, &input_mask);
1151 
1152  if (forWrite)
1153  FD_SET(sock, &output_mask);
1154  FD_SET(sock, &except_mask);
1155 
1156  /* Compute appropriate timeout interval */
1157  if (end_time == ((time_t) -1))
1158  ptr_timeout = NULL;
1159  else
1160  {
1161  time_t now = time(NULL);
1162 
1163  if (end_time > now)
1164  timeout.tv_sec = end_time - now;
1165  else
1166  timeout.tv_sec = 0;
1167  timeout.tv_usec = 0;
1168  ptr_timeout = &timeout;
1169  }
1170 
1171  return select(sock + 1, &input_mask, &output_mask,
1172  &except_mask, ptr_timeout);
1173 #endif /* HAVE_POLL */
1174 }
#define select(n, r, w, e, timeout)
Definition: win32.h:384
int64 end_time
Definition: pgbench.c:100
#define NULL
Definition: c.h:229
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1533
int pqWait ( int  forRead,
int  forWrite,
PGconn conn 
)

Definition at line 989 of file fe-misc.c.

References pqWaitTimed().

Referenced by pqFunctionCall2(), pqFunctionCall3(), pqGetCopyData2(), pqGetCopyData3(), pqGetline2(), pqGetline3(), PQgetResult(), and pqSendSome().

990 {
991  return pqWaitTimed(forRead, forWrite, conn, (time_t) -1);
992 }
int pqWaitTimed(int forRead, int forWrite, PGconn *conn, time_t finish_time)
Definition: fe-misc.c:1004
int pqWaitTimed ( int  forRead,
int  forWrite,
PGconn conn,
time_t  finish_time 
)

Definition at line 1004 of file fe-misc.c.

References pg_conn::errorMessage, libpq_gettext, pqSocketCheck(), and printfPQExpBuffer().

Referenced by connectDBComplete(), and pqWait().

1005 {
1006  int result;
1007 
1008  result = pqSocketCheck(conn, forRead, forWrite, finish_time);
1009 
1010  if (result < 0)
1011  return EOF; /* errorMessage is already set */
1012 
1013  if (result == 0)
1014  {
1016  libpq_gettext("timeout expired\n"));
1017  return EOF;
1018  }
1019 
1020  return 0;
1021 }
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
static int pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
Definition: fe-misc.c:1052
PQExpBufferData errorMessage
Definition: libpq-int.h:501
#define libpq_gettext(x)
Definition: libpq-int.h:692
int pqWriteReady ( PGconn conn)

Definition at line 1038 of file fe-misc.c.

References pqSocketCheck().

1039 {
1040  return pqSocketCheck(conn, 0, 1, (time_t) 0);
1041 }
static int pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
Definition: fe-misc.c:1052