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 81 of file fe-misc.c.

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

82 {
83  while (n-- > 0)
84  fputc(*str++, f);
85 }
int pqCheckInBufferSpace ( size_t  bytes_needed,
PGconn conn 
)

Definition at line 410 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().

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

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

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

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

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

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

References pg_encoding_dsplen().

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

1193 {
1194  return pg_encoding_dsplen(encoding, s);
1195 }
int pg_encoding_dsplen(int encoding, const char *mbstr)
Definition: wchar.c:1796
static char * encoding
Definition: initdb.c:122
int PQenv2encoding ( void  )

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

References encoding, pg_char_to_encoding(), and PG_SQL_ASCII.

Referenced by main().

1202 {
1203  char *str;
1204  int encoding = PG_SQL_ASCII;
1205 
1206  str = getenv("PGCLIENTENCODING");
1207  if (str && *str != '\0')
1208  {
1209  encoding = pg_char_to_encoding(str);
1210  if (encoding < 0)
1211  encoding = PG_SQL_ASCII;
1212  }
1213  return encoding;
1214 }
int pg_char_to_encoding(const char *name)
Definition: encnames.c:551
static char * encoding
Definition: initdb.c:122
int pqFlush ( PGconn conn)

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

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

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

964 {
965  if (conn->Pfdebug)
966  fflush(conn->Pfdebug);
967 
968  if (conn->outCount > 0)
969  return pqSendSome(conn, conn->outCount);
970 
971  return 0;
972 }
int outCount
Definition: libpq-int.h:438
FILE * Pfdebug
Definition: libpq-int.h:368
static int pqSendSome(PGconn *conn, int len)
Definition: fe-misc.c:831
int pqGetc ( char *  result,
PGconn conn 
)

Definition at line 96 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().

97 {
98  if (conn->inCursor >= conn->inEnd)
99  return EOF;
100 
101  *result = conn->inBuffer[conn->inCursor++];
102 
103  if (conn->Pfdebug)
104  fprintf(conn->Pfdebug, "From backend> %c\n", *result);
105 
106  return 0;
107 }
int inEnd
Definition: libpq-int.h:433
return result
Definition: formatting.c:1633
FILE * Pfdebug
Definition: libpq-int.h:368
char * inBuffer
Definition: libpq-int.h:429
int inCursor
Definition: libpq-int.h:432
int pqGetInt ( int *  result,
size_t  bytes,
PGconn conn 
)

Definition at line 269 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().

270 {
271  uint16 tmp2;
272  uint32 tmp4;
273 
274  switch (bytes)
275  {
276  case 2:
277  if (conn->inCursor + 2 > conn->inEnd)
278  return EOF;
279  memcpy(&tmp2, conn->inBuffer + conn->inCursor, 2);
280  conn->inCursor += 2;
281  *result = (int) ntohs(tmp2);
282  break;
283  case 4:
284  if (conn->inCursor + 4 > conn->inEnd)
285  return EOF;
286  memcpy(&tmp4, conn->inBuffer + conn->inCursor, 4);
287  conn->inCursor += 4;
288  *result = (int) ntohl(tmp4);
289  break;
290  default:
292  "integer of size %lu not supported by pqGetInt",
293  (unsigned long) bytes);
294  return EOF;
295  }
296 
297  if (conn->Pfdebug)
298  fprintf(conn->Pfdebug, "From backend (#%lu)> %d\n", (unsigned long) bytes, *result);
299 
300  return 0;
301 }
int inEnd
Definition: libpq-int.h:433
return result
Definition: formatting.c:1633
FILE * Pfdebug
Definition: libpq-int.h:368
unsigned short uint16
Definition: c.h:267
PGNoticeHooks noticeHooks
Definition: libpq-int.h:371
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:429
int inCursor
Definition: libpq-int.h:432
int pqGetnchar ( char *  s,
size_t  len,
PGconn conn 
)

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

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

Referenced by getAnotherTuple(), pg_password_sendauth(), pg_SASL_continue(), pqFunctionCall2(), and pqFunctionCall3().

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

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

References pqGets_internal().

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

166 {
167  return pqGets_internal(buf, conn, true);
168 }
static int pqGets_internal(PQExpBuffer buf, PGconn *conn, bool resetbuffer)
Definition: fe-misc.c:134
int pqGets_append ( PQExpBuffer  buf,
PGconn conn 
)

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

References pqGets_internal().

Referenced by PQconnectPoll().

172 {
173  return pqGets_internal(buf, conn, false);
174 }
static int pqGets_internal(PQExpBuffer buf, PGconn *conn, bool resetbuffer)
Definition: fe-misc.c:134
static int pqGets_internal ( PQExpBuffer  buf,
PGconn conn,
bool  resetbuffer 
)
static

Definition at line 134 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().

135 {
136  /* Copy conn data to locals for faster search loop */
137  char *inBuffer = conn->inBuffer;
138  int inCursor = conn->inCursor;
139  int inEnd = conn->inEnd;
140  int slen;
141 
142  while (inCursor < inEnd && inBuffer[inCursor])
143  inCursor++;
144 
145  if (inCursor >= inEnd)
146  return EOF;
147 
148  slen = inCursor - conn->inCursor;
149 
150  if (resetbuffer)
151  resetPQExpBuffer(buf);
152 
153  appendBinaryPQExpBuffer(buf, inBuffer + conn->inCursor, slen);
154 
155  conn->inCursor = ++inCursor;
156 
157  if (conn->Pfdebug)
158  fprintf(conn->Pfdebug, "From backend> \"%s\"\n",
159  buf->data);
160 
161  return 0;
162 }
int inEnd
Definition: libpq-int.h:433
FILE * Pfdebug
Definition: libpq-int.h:368
char * inBuffer
Definition: libpq-int.h:429
int inCursor
Definition: libpq-int.h:432
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 69 of file fe-misc.c.

70 {
71  return PG_VERSION_NUM;
72 }
int PQmblen ( const char *  s,
int  encoding 
)

Definition at line 1182 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().

1183 {
1184  return pg_encoding_mblen(encoding, s);
1185 }
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition: wchar.c:1785
static char * encoding
Definition: initdb.c:122
int pqPutc ( char  c,
PGconn conn 
)

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

References pg_conn::Pfdebug, and pqPutMsgBytes().

Referenced by PQsendDescribe(), and PQsendQueryGuts().

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

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

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

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

310 {
311  uint16 tmp2;
312  uint32 tmp4;
313 
314  switch (bytes)
315  {
316  case 2:
317  tmp2 = htons((uint16) value);
318  if (pqPutMsgBytes((const char *) &tmp2, 2, conn))
319  return EOF;
320  break;
321  case 4:
322  tmp4 = htonl((uint32) value);
323  if (pqPutMsgBytes((const char *) &tmp4, 4, conn))
324  return EOF;
325  break;
326  default:
328  "integer of size %lu not supported by pqPutInt",
329  (unsigned long) bytes);
330  return EOF;
331  }
332 
333  if (conn->Pfdebug)
334  fprintf(conn->Pfdebug, "To backend (%lu#)> %d\n", (unsigned long) bytes, value);
335 
336  return 0;
337 }
FILE * Pfdebug
Definition: libpq-int.h:368
unsigned short uint16
Definition: c.h:267
static struct @121 value
PGNoticeHooks noticeHooks
Definition: libpq-int.h:371
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn)
Definition: fe-misc.c:566
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 566 of file fe-misc.c.

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

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

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

Definition at line 589 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 pg_SASL_init(), pqEndcopy3(), pqFunctionCall2(), pqFunctionCall3(), pqPacketSend(), PQputCopyData(), PQputCopyEnd(), PQsendDescribe(), PQsendPrepare(), PQsendQuery(), PQsendQueryGuts(), and sendTerminateConn().

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

Definition at line 521 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 pg_SASL_init(), pqEndcopy3(), pqFunctionCall2(), pqFunctionCall3(), pqPacketSend(), PQputCopyData(), PQputCopyEnd(), PQsendDescribe(), PQsendPrepare(), PQsendQuery(), PQsendQueryGuts(), and sendTerminateConn().

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

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

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

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

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

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

References pg_conn::Pfdebug, and pqPutMsgBytes().

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

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

Definition at line 631 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().

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

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

References pqSocketCheck().

Referenced by pqReadData().

1024 {
1025  return pqSocketCheck(conn, 1, 0, (time_t) 0);
1026 }
static int pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
Definition: fe-misc.c:1047
static int pqSendSome ( PGconn conn,
int  len 
)
static

Definition at line 831 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, result, pg_conn::sock, SOCK_ERRNO, and TRUE.

Referenced by pqFlush(), and pqPutMsgEnd().

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

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

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

Referenced by getAnotherTuple().

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

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

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

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

1048 {
1049  int result;
1050 
1051  if (!conn)
1052  return -1;
1053  if (conn->sock == PGINVALID_SOCKET)
1054  {
1056  libpq_gettext("invalid socket\n"));
1057  return -1;
1058  }
1059 
1060 #ifdef USE_SSL
1061  /* Check for SSL library buffering read bytes */
1062  if (forRead && conn->ssl_in_use && pgtls_read_pending(conn) > 0)
1063  {
1064  /* short-circuit the select */
1065  return 1;
1066  }
1067 #endif
1068 
1069  /* We will retry as long as we get EINTR */
1070  do
1071  result = pqSocketPoll(conn->sock, forRead, forWrite, end_time);
1072  while (result < 0 && SOCK_ERRNO == EINTR);
1073 
1074  if (result < 0)
1075  {
1076  char sebuf[256];
1077 
1079  libpq_gettext("select() failed: %s\n"),
1080  SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
1081  }
1082 
1083  return result;
1084 }
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
return result
Definition: formatting.c:1633
static int pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time)
Definition: fe-misc.c:1097
#define SOCK_STRERROR
Definition: libpq-int.h:696
int64 end_time
Definition: pgbench.c:100
#define SOCK_ERRNO
Definition: libpq-int.h:695
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:285
PQExpBufferData errorMessage
Definition: libpq-int.h:491
#define libpq_gettext(x)
Definition: libpq-int.h:682
static int pqSocketPoll ( int  sock,
int  forRead,
int  forWrite,
time_t  end_time 
)
static

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

References now(), NULL, and select.

Referenced by pqSocketCheck().

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

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

References pqWaitTimed().

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

987 {
988  return pqWaitTimed(forRead, forWrite, conn, (time_t) -1);
989 }
int pqWaitTimed(int forRead, int forWrite, PGconn *conn, time_t finish_time)
Definition: fe-misc.c:999
int pqWaitTimed ( int  forRead,
int  forWrite,
PGconn conn,
time_t  finish_time 
)

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

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

Referenced by connectDBComplete(), and pqWait().

1000 {
1001  int result;
1002 
1003  result = pqSocketCheck(conn, forRead, forWrite, finish_time);
1004 
1005  if (result < 0)
1006  return -1; /* errorMessage is already set */
1007 
1008  if (result == 0)
1009  {
1011  libpq_gettext("timeout expired\n"));
1012  return 1;
1013  }
1014 
1015  return 0;
1016 }
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:1047
return result
Definition: formatting.c:1633
PQExpBufferData errorMessage
Definition: libpq-int.h:491
#define libpq_gettext(x)
Definition: libpq-int.h:682
int pqWriteReady ( PGconn conn)

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

References pqSocketCheck().

1034 {
1035  return pqSocketCheck(conn, 0, 1, (time_t) 0);
1036 }
static int pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
Definition: fe-misc.c:1047