PostgreSQL Source Code  git master
fe-misc.c File Reference
#include "postgres_fe.h"
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include "libpq-fe.h"
#include "libpq-int.h"
#include "mb/pg_wchar.h"
#include "pg_config_paths.h"
#include "port/pg_bswap.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)
 
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, 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 PQmblenBounded (const char *s, int encoding)
 
int PQdsplen (const char *s, int encoding)
 
int PQenv2encoding (void)
 

Function Documentation

◆ pqCheckInBufferSpace()

int pqCheckInBufferSpace ( size_t  bytes_needed,
PGconn conn 
)

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

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

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

355 {
356  int newsize = conn->inBufSize;
357  char *newbuf;
358 
359  /* Quick exit if we have enough space */
360  if (bytes_needed <= (size_t) newsize)
361  return 0;
362 
363  /*
364  * Before concluding that we need to enlarge the buffer, left-justify
365  * whatever is in it and recheck. The caller's value of bytes_needed
366  * includes any data to the left of inStart, but we can delete that in
367  * preference to enlarging the buffer. It's slightly ugly to have this
368  * function do this, but it's better than making callers worry about it.
369  */
370  bytes_needed -= conn->inStart;
371 
372  if (conn->inStart < conn->inEnd)
373  {
374  if (conn->inStart > 0)
375  {
376  memmove(conn->inBuffer, conn->inBuffer + conn->inStart,
377  conn->inEnd - conn->inStart);
378  conn->inEnd -= conn->inStart;
379  conn->inCursor -= conn->inStart;
380  conn->inStart = 0;
381  }
382  }
383  else
384  {
385  /* buffer is logically empty, reset it */
386  conn->inStart = conn->inCursor = conn->inEnd = 0;
387  }
388 
389  /* Recheck whether we have enough space */
390  if (bytes_needed <= (size_t) newsize)
391  return 0;
392 
393  /*
394  * If we need to enlarge the buffer, we first try to double it in size; if
395  * that doesn't work, enlarge in multiples of 8K. This avoids thrashing
396  * the malloc pool by repeated small enlargements.
397  *
398  * Note: tests for newsize > 0 are to catch integer overflow.
399  */
400  do
401  {
402  newsize *= 2;
403  } while (newsize > 0 && bytes_needed > (size_t) newsize);
404 
405  if (newsize > 0 && bytes_needed <= (size_t) newsize)
406  {
407  newbuf = realloc(conn->inBuffer, newsize);
408  if (newbuf)
409  {
410  /* realloc succeeded */
411  conn->inBuffer = newbuf;
412  conn->inBufSize = newsize;
413  return 0;
414  }
415  }
416 
417  newsize = conn->inBufSize;
418  do
419  {
420  newsize += 8192;
421  } while (newsize > 0 && bytes_needed > (size_t) newsize);
422 
423  if (newsize > 0 && bytes_needed <= (size_t) newsize)
424  {
425  newbuf = realloc(conn->inBuffer, newsize);
426  if (newbuf)
427  {
428  /* realloc succeeded */
429  conn->inBuffer = newbuf;
430  conn->inBufSize = newsize;
431  return 0;
432  }
433  }
434 
435  /* realloc failed. Probably out of memory */
437  "cannot allocate memory for input buffer\n");
438  return EOF;
439 }
int inEnd
Definition: libpq-int.h:483
int inStart
Definition: libpq-int.h:481
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int inBufSize
Definition: libpq-int.h:480
char * inBuffer
Definition: libpq-int.h:479
PQExpBufferData errorMessage
Definition: libpq-int.h:571
#define realloc(a, b)
Definition: header.h:60
int inCursor
Definition: libpq-int.h:482

◆ pqCheckOutBufferSpace()

int pqCheckOutBufferSpace ( size_t  bytes_needed,
PGconn conn 
)

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

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

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

291 {
292  int newsize = conn->outBufSize;
293  char *newbuf;
294 
295  /* Quick exit if we have enough space */
296  if (bytes_needed <= (size_t) newsize)
297  return 0;
298 
299  /*
300  * If we need to enlarge the buffer, we first try to double it in size; if
301  * that doesn't work, enlarge in multiples of 8K. This avoids thrashing
302  * the malloc pool by repeated small enlargements.
303  *
304  * Note: tests for newsize > 0 are to catch integer overflow.
305  */
306  do
307  {
308  newsize *= 2;
309  } while (newsize > 0 && bytes_needed > (size_t) newsize);
310 
311  if (newsize > 0 && bytes_needed <= (size_t) newsize)
312  {
313  newbuf = realloc(conn->outBuffer, newsize);
314  if (newbuf)
315  {
316  /* realloc succeeded */
317  conn->outBuffer = newbuf;
318  conn->outBufSize = newsize;
319  return 0;
320  }
321  }
322 
323  newsize = conn->outBufSize;
324  do
325  {
326  newsize += 8192;
327  } while (newsize > 0 && bytes_needed > (size_t) newsize);
328 
329  if (newsize > 0 && bytes_needed <= (size_t) newsize)
330  {
331  newbuf = realloc(conn->outBuffer, newsize);
332  if (newbuf)
333  {
334  /* realloc succeeded */
335  conn->outBuffer = newbuf;
336  conn->outBufSize = newsize;
337  return 0;
338  }
339  }
340 
341  /* realloc failed. Probably out of memory */
343  "cannot allocate memory for output buffer\n");
344  return EOF;
345 }
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
PQExpBufferData errorMessage
Definition: libpq-int.h:571
int outBufSize
Definition: libpq-int.h:487
#define realloc(a, b)
Definition: header.h:60
char * outBuffer
Definition: libpq-int.h:486

◆ PQdsplen()

int PQdsplen ( const char *  s,
int  encoding 
)

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

References pg_encoding_dsplen().

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

1213 {
1214  return pg_encoding_dsplen(encoding, s);
1215 }
int pg_encoding_dsplen(int encoding, const char *mbstr)
Definition: wchar.c:1935
int32 encoding
Definition: pg_database.h:41

◆ PQenv2encoding()

int PQenv2encoding ( void  )

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

References dgettext, dngettext, encoding, libpq_gettext, libpq_ngettext, pg_char_to_encoding(), PG_SQL_ASCII, PG_TEXTDOMAIN, and generate_unaccent_rules::str.

Referenced by main().

1222 {
1223  char *str;
1224  int encoding = PG_SQL_ASCII;
1225 
1226  str = getenv("PGCLIENTENCODING");
1227  if (str && *str != '\0')
1228  {
1229  encoding = pg_char_to_encoding(str);
1230  if (encoding < 0)
1231  encoding = PG_SQL_ASCII;
1232  }
1233  return encoding;
1234 }
int pg_char_to_encoding(const char *name)
Definition: encnames.c:550
int32 encoding
Definition: pg_database.h:41

◆ pqFlush()

int pqFlush ( PGconn conn)

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

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

Referenced by pg_SASL_init(), PQconnectPoll(), PQconsumeInput(), pqEndcopy3(), PQexitPipelineMode(), PQflush(), pqFunctionCall3(), PQgetResult(), pqPacketSend(), pqPipelineFlush(), PQputCopyData(), PQputCopyEnd(), PQsetnonblocking(), and sendTerminateConn().

966 {
967  if (conn->outCount > 0)
968  {
969  if (conn->Pfdebug)
970  fflush(conn->Pfdebug);
971 
972  return pqSendSome(conn, conn->outCount);
973  }
974 
975  return 0;
976 }
int outCount
Definition: libpq-int.h:488
FILE * Pfdebug
Definition: libpq-int.h:398
static int pqSendSome(PGconn *conn, int len)
Definition: fe-misc.c:788

◆ pqGetc()

int pqGetc ( char *  result,
PGconn conn 
)

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

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

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

81 {
82  if (conn->inCursor >= conn->inEnd)
83  return EOF;
84 
85  *result = conn->inBuffer[conn->inCursor++];
86 
87  return 0;
88 }
int inEnd
Definition: libpq-int.h:483
char * inBuffer
Definition: libpq-int.h:479
int inCursor
Definition: libpq-int.h:482

◆ pqGetInt()

int pqGetInt ( int *  result,
size_t  bytes,
PGconn conn 
)

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

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

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

220 {
221  uint16 tmp2;
222  uint32 tmp4;
223 
224  switch (bytes)
225  {
226  case 2:
227  if (conn->inCursor + 2 > conn->inEnd)
228  return EOF;
229  memcpy(&tmp2, conn->inBuffer + conn->inCursor, 2);
230  conn->inCursor += 2;
231  *result = (int) pg_ntoh16(tmp2);
232  break;
233  case 4:
234  if (conn->inCursor + 4 > conn->inEnd)
235  return EOF;
236  memcpy(&tmp4, conn->inBuffer + conn->inCursor, 4);
237  conn->inCursor += 4;
238  *result = (int) pg_ntoh32(tmp4);
239  break;
240  default:
242  "integer of size %lu not supported by pqGetInt",
243  (unsigned long) bytes);
244  return EOF;
245  }
246 
247  return 0;
248 }
int inEnd
Definition: libpq-int.h:483
def bytes(source, encoding='ascii', errors='strict')
#define pg_ntoh16(x)
Definition: pg_bswap.h:124
unsigned short uint16
Definition: c.h:440
#define pg_ntoh32(x)
Definition: pg_bswap.h:125
PGNoticeHooks noticeHooks
Definition: libpq-int.h:402
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
Definition: fe-exec.c:839
unsigned int uint32
Definition: c.h:441
char * inBuffer
Definition: libpq-int.h:479
int inCursor
Definition: libpq-int.h:482

◆ pqGetnchar()

int pqGetnchar ( char *  s,
size_t  len,
PGconn conn 
)

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

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

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

169 {
170  if (len > (size_t) (conn->inEnd - conn->inCursor))
171  return EOF;
172 
173  memcpy(s, conn->inBuffer + conn->inCursor, len);
174  /* no terminating null */
175 
176  conn->inCursor += len;
177 
178  return 0;
179 }
int inEnd
Definition: libpq-int.h:483
char * inBuffer
Definition: libpq-int.h:479
int inCursor
Definition: libpq-int.h:482

◆ pqGets()

int pqGets ( PQExpBuffer  buf,
PGconn conn 
)

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

References pqGets_internal().

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

140 {
141  return pqGets_internal(buf, conn, true);
142 }
static int pqGets_internal(PQExpBuffer buf, PGconn *conn, bool resetbuffer)
Definition: fe-misc.c:112

◆ pqGets_append()

int pqGets_append ( PQExpBuffer  buf,
PGconn conn 
)

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

References pqGets_internal().

Referenced by PQconnectPoll().

146 {
147  return pqGets_internal(buf, conn, false);
148 }
static int pqGets_internal(PQExpBuffer buf, PGconn *conn, bool resetbuffer)
Definition: fe-misc.c:112

◆ pqGets_internal()

static int pqGets_internal ( PQExpBuffer  buf,
PGconn conn,
bool  resetbuffer 
)
static

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

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

Referenced by pqGets(), and pqGets_append().

113 {
114  /* Copy conn data to locals for faster search loop */
115  char *inBuffer = conn->inBuffer;
116  int inCursor = conn->inCursor;
117  int inEnd = conn->inEnd;
118  int slen;
119 
120  while (inCursor < inEnd && inBuffer[inCursor])
121  inCursor++;
122 
123  if (inCursor >= inEnd)
124  return EOF;
125 
126  slen = inCursor - conn->inCursor;
127 
128  if (resetbuffer)
129  resetPQExpBuffer(buf);
130 
131  appendBinaryPQExpBuffer(buf, inBuffer + conn->inCursor, slen);
132 
133  conn->inCursor = ++inCursor;
134 
135  return 0;
136 }
int inEnd
Definition: libpq-int.h:483
char * inBuffer
Definition: libpq-int.h:479
int inCursor
Definition: libpq-int.h:482
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
Definition: pqexpbuffer.c:399

◆ PQlibVersion()

int PQlibVersion ( void  )

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

67 {
68  return PG_VERSION_NUM;
69 }

◆ PQmblen()

int PQmblen ( const char *  s,
int  encoding 
)

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

References pg_encoding_mblen().

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

1193 {
1194  return pg_encoding_mblen(encoding, s);
1195 }
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition: wchar.c:1914
int32 encoding
Definition: pg_database.h:41

◆ PQmblenBounded()

int PQmblenBounded ( const char *  s,
int  encoding 
)

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

References pg_encoding_mblen(), and strnlen().

Referenced by command_no_begin(), do_field(), is_select_command(), patternToSQLRegex(), quote_if_needed(), reportErrorPosition(), skip_white_space(), splitTableColumnsSpec(), strip_quotes(), and strtokx().

1203 {
1204  return strnlen(s, pg_encoding_mblen(encoding, s));
1205 }
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition: wchar.c:1914
size_t strnlen(const char *str, size_t maxlen)
Definition: strnlen.c:26
int32 encoding
Definition: pg_database.h:41

◆ pqPutc()

int pqPutc ( char  c,
PGconn conn 
)

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

References pqPutMsgBytes().

Referenced by PQsendDescribe(), PQsendQueryGuts(), and PQsendQueryInternal().

96 {
97  if (pqPutMsgBytes(&c, 1, conn))
98  return EOF;
99 
100  return 0;
101 }
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn)
Definition: fe-misc.c:497
char * c

◆ pqPutInt()

int pqPutInt ( int  value,
size_t  bytes,
PGconn conn 
)

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

References pg_conn::noticeHooks, pg_hton16, pg_hton32, pqInternalNotice(), and pqPutMsgBytes().

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

257 {
258  uint16 tmp2;
259  uint32 tmp4;
260 
261  switch (bytes)
262  {
263  case 2:
264  tmp2 = pg_hton16((uint16) value);
265  if (pqPutMsgBytes((const char *) &tmp2, 2, conn))
266  return EOF;
267  break;
268  case 4:
269  tmp4 = pg_hton32((uint32) value);
270  if (pqPutMsgBytes((const char *) &tmp4, 4, conn))
271  return EOF;
272  break;
273  default:
275  "integer of size %lu not supported by pqPutInt",
276  (unsigned long) bytes);
277  return EOF;
278  }
279 
280  return 0;
281 }
def bytes(source, encoding='ascii', errors='strict')
#define pg_hton16(x)
Definition: pg_bswap.h:120
unsigned short uint16
Definition: c.h:440
#define pg_hton32(x)
Definition: pg_bswap.h:121
PGNoticeHooks noticeHooks
Definition: libpq-int.h:402
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn)
Definition: fe-misc.c:497
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
Definition: fe-exec.c:839
unsigned int uint32
Definition: c.h:441
static struct @143 value

◆ pqPutMsgBytes()

static int pqPutMsgBytes ( const void *  buf,
size_t  len,
PGconn conn 
)
static

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

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

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

498 {
499  /* make sure there is room for it */
500  if (pqCheckOutBufferSpace(conn->outMsgEnd + len, conn))
501  return EOF;
502  /* okay, save the data */
503  memcpy(conn->outBuffer + conn->outMsgEnd, buf, len);
504  conn->outMsgEnd += len;
505  /* no Pfdebug call here, caller should do it */
506  return 0;
507 }
int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn)
Definition: fe-misc.c:290
int outMsgEnd
Definition: libpq-int.h:493
static char * buf
Definition: pg_test_fsync.c:68
char * outBuffer
Definition: libpq-int.h:486

◆ pqPutMsgEnd()

int pqPutMsgEnd ( PGconn conn)

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

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

Referenced by pg_SASL_init(), pqEndcopy3(), pqFunctionCall3(), pqPacketSend(), PQpipelineSync(), PQputCopyData(), PQputCopyEnd(), PQsendDescribe(), PQsendFlushRequest(), PQsendPrepare(), PQsendQueryGuts(), PQsendQueryInternal(), and sendTerminateConn().

521 {
522  /* Fill in length word if needed */
523  if (conn->outMsgStart >= 0)
524  {
525  uint32 msgLen = conn->outMsgEnd - conn->outMsgStart;
526 
527  msgLen = pg_hton32(msgLen);
528  memcpy(conn->outBuffer + conn->outMsgStart, &msgLen, 4);
529  }
530 
531  /* trace client-to-server message */
532  if (conn->Pfdebug)
533  {
534  if (conn->outCount < conn->outMsgStart)
535  pqTraceOutputMessage(conn, conn->outBuffer + conn->outCount, true);
536  else
538  conn->outBuffer + conn->outMsgStart);
539  }
540 
541  /* Make message eligible to send */
542  conn->outCount = conn->outMsgEnd;
543 
544  if (conn->outCount >= 8192)
545  {
546  int toSend = conn->outCount - (conn->outCount % 8192);
547 
548  if (pqSendSome(conn, toSend) < 0)
549  return EOF;
550  /* in nonblock mode, don't complain if unable to send it all */
551  }
552 
553  return 0;
554 }
int outCount
Definition: libpq-int.h:488
int outMsgEnd
Definition: libpq-int.h:493
FILE * Pfdebug
Definition: libpq-int.h:398
#define pg_hton32(x)
Definition: pg_bswap.h:121
unsigned int uint32
Definition: c.h:441
void pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer)
Definition: fe-trace.c:529
int outMsgStart
Definition: libpq-int.h:491
void pqTraceOutputNoTypeByteMessage(PGconn *conn, const char *message)
Definition: fe-trace.c:694
char * outBuffer
Definition: libpq-int.h:486
static int pqSendSome(PGconn *conn, int len)
Definition: fe-misc.c:788

◆ pqPutMsgStart()

int pqPutMsgStart ( char  msg_type,
PGconn conn 
)

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

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

Referenced by pg_SASL_init(), pqEndcopy3(), pqFunctionCall3(), pqPacketSend(), PQpipelineSync(), PQputCopyData(), PQputCopyEnd(), PQsendDescribe(), PQsendFlushRequest(), PQsendPrepare(), PQsendQueryGuts(), PQsendQueryInternal(), and sendTerminateConn().

462 {
463  int lenPos;
464  int endPos;
465 
466  /* allow room for message type byte */
467  if (msg_type)
468  endPos = conn->outCount + 1;
469  else
470  endPos = conn->outCount;
471 
472  /* do we want a length word? */
473  lenPos = endPos;
474  /* allow room for message length */
475  endPos += 4;
476 
477  /* make sure there is room for message header */
478  if (pqCheckOutBufferSpace(endPos, conn))
479  return EOF;
480  /* okay, save the message type byte if any */
481  if (msg_type)
482  conn->outBuffer[conn->outCount] = msg_type;
483  /* set up the message pointers */
484  conn->outMsgStart = lenPos;
485  conn->outMsgEnd = endPos;
486  /* length word, if needed, will be filled in by pqPutMsgEnd */
487 
488  return 0;
489 }
int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn)
Definition: fe-misc.c:290
int outCount
Definition: libpq-int.h:488
int outMsgEnd
Definition: libpq-int.h:493
int outMsgStart
Definition: libpq-int.h:491
char * outBuffer
Definition: libpq-int.h:486

◆ pqPutnchar()

int pqPutnchar ( const char *  s,
size_t  len,
PGconn conn 
)

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

References pqPutMsgBytes().

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

206 {
207  if (pqPutMsgBytes(s, len, conn))
208  return EOF;
209 
210  return 0;
211 }
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn)
Definition: fe-misc.c:497

◆ pqPuts()

int pqPuts ( const char *  s,
PGconn conn 
)

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

References pqPutMsgBytes().

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

156 {
157  if (pqPutMsgBytes(s, strlen(s) + 1, conn))
158  return EOF;
159 
160  return 0;
161 }
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn)
Definition: fe-misc.c:497

◆ pqReadData()

int pqReadData ( PGconn conn)

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

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

Referenced by PQconnectPoll(), PQconsumeInput(), pqFunctionCall3(), pqGetCopyData3(), pqGetline3(), PQgetResult(), and pqSendSome().

569 {
570  int someread = 0;
571  int nread;
572 
573  if (conn->sock == PGINVALID_SOCKET)
574  {
576  libpq_gettext("connection not open\n"));
577  return -1;
578  }
579 
580  /* Left-justify any data in the buffer to make room */
581  if (conn->inStart < conn->inEnd)
582  {
583  if (conn->inStart > 0)
584  {
585  memmove(conn->inBuffer, conn->inBuffer + conn->inStart,
586  conn->inEnd - conn->inStart);
587  conn->inEnd -= conn->inStart;
588  conn->inCursor -= conn->inStart;
589  conn->inStart = 0;
590  }
591  }
592  else
593  {
594  /* buffer is logically empty, reset it */
595  conn->inStart = conn->inCursor = conn->inEnd = 0;
596  }
597 
598  /*
599  * If the buffer is fairly full, enlarge it. We need to be able to enlarge
600  * the buffer in case a single message exceeds the initial buffer size. We
601  * enlarge before filling the buffer entirely so as to avoid asking the
602  * kernel for a partial packet. The magic constant here should be large
603  * enough for a TCP packet or Unix pipe bufferload. 8K is the usual pipe
604  * buffer size, so...
605  */
606  if (conn->inBufSize - conn->inEnd < 8192)
607  {
608  if (pqCheckInBufferSpace(conn->inEnd + (size_t) 8192, conn))
609  {
610  /*
611  * We don't insist that the enlarge worked, but we need some room
612  */
613  if (conn->inBufSize - conn->inEnd < 100)
614  return -1; /* errorMessage already set */
615  }
616  }
617 
618  /* OK, try to read some data */
619 retry3:
620  nread = pqsecure_read(conn, conn->inBuffer + conn->inEnd,
621  conn->inBufSize - conn->inEnd);
622  if (nread < 0)
623  {
624  switch (SOCK_ERRNO)
625  {
626  case EINTR:
627  goto retry3;
628 
629  /* Some systems return EAGAIN/EWOULDBLOCK for no data */
630 #ifdef EAGAIN
631  case EAGAIN:
632  return someread;
633 #endif
634 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
635  case EWOULDBLOCK:
636  return someread;
637 #endif
638 
639  /* We might get ECONNRESET etc here if connection failed */
641  goto definitelyFailed;
642 
643  default:
644  /* pqsecure_read set the error message for us */
645  return -1;
646  }
647  }
648  if (nread > 0)
649  {
650  conn->inEnd += nread;
651 
652  /*
653  * Hack to deal with the fact that some kernels will only give us back
654  * 1 packet per recv() call, even if we asked for more and there is
655  * more available. If it looks like we are reading a long message,
656  * loop back to recv() again immediately, until we run out of data or
657  * buffer space. Without this, the block-and-restart behavior of
658  * libpq's higher levels leads to O(N^2) performance on long messages.
659  *
660  * Since we left-justified the data above, conn->inEnd gives the
661  * amount of data already read in the current message. We consider
662  * the message "long" once we have acquired 32k ...
663  */
664  if (conn->inEnd > 32768 &&
665  (conn->inBufSize - conn->inEnd) >= 8192)
666  {
667  someread = 1;
668  goto retry3;
669  }
670  return 1;
671  }
672 
673  if (someread)
674  return 1; /* got a zero read after successful tries */
675 
676  /*
677  * A return value of 0 could mean just that no data is now available, or
678  * it could mean EOF --- that is, the server has closed the connection.
679  * Since we have the socket in nonblock mode, the only way to tell the
680  * difference is to see if select() is saying that the file is ready.
681  * Grumble. Fortunately, we don't expect this path to be taken much,
682  * since in normal practice we should not be trying to read data unless
683  * the file selected for reading already.
684  *
685  * In SSL mode it's even worse: SSL_read() could say WANT_READ and then
686  * data could arrive before we make the pqReadReady() test, but the second
687  * SSL_read() could still say WANT_READ because the data received was not
688  * a complete SSL record. So we must play dumb and assume there is more
689  * data, relying on the SSL layer to detect true EOF.
690  */
691 
692 #ifdef USE_SSL
693  if (conn->ssl_in_use)
694  return 0;
695 #endif
696 
697  switch (pqReadReady(conn))
698  {
699  case 0:
700  /* definitely no data available */
701  return 0;
702  case 1:
703  /* ready for read */
704  break;
705  default:
706  /* we override pqReadReady's message with something more useful */
707  goto definitelyEOF;
708  }
709 
710  /*
711  * Still not sure that it's EOF, because some data could have just
712  * arrived.
713  */
714 retry4:
715  nread = pqsecure_read(conn, conn->inBuffer + conn->inEnd,
716  conn->inBufSize - conn->inEnd);
717  if (nread < 0)
718  {
719  switch (SOCK_ERRNO)
720  {
721  case EINTR:
722  goto retry4;
723 
724  /* Some systems return EAGAIN/EWOULDBLOCK for no data */
725 #ifdef EAGAIN
726  case EAGAIN:
727  return 0;
728 #endif
729 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
730  case EWOULDBLOCK:
731  return 0;
732 #endif
733 
734  /* We might get ECONNRESET etc here if connection failed */
736  goto definitelyFailed;
737 
738  default:
739  /* pqsecure_read set the error message for us */
740  return -1;
741  }
742  }
743  if (nread > 0)
744  {
745  conn->inEnd += nread;
746  return 1;
747  }
748 
749  /*
750  * OK, we are getting a zero read even though select() says ready. This
751  * means the connection has been closed. Cope.
752  */
753 definitelyEOF:
755  libpq_gettext("server closed the connection unexpectedly\n"
756  "\tThis probably means the server terminated abnormally\n"
757  "\tbefore or while processing the request.\n"));
758 
759  /* Come here if lower-level code already set a suitable errorMessage */
760 definitelyFailed:
761  /* Do *not* drop any already-read data; caller still wants it */
762  pqDropConnection(conn, false);
763  conn->status = CONNECTION_BAD; /* No more connection to backend */
764  return -1;
765 }
int inEnd
Definition: libpq-int.h:483
int inStart
Definition: libpq-int.h:481
int pqReadReady(PGconn *conn)
Definition: fe-misc.c:1027
#define EAGAIN
Definition: win32_port.h:349
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn)
Definition: fe-misc.c:354
ssize_t pqsecure_read(PGconn *conn, void *ptr, size_t len)
Definition: fe-secure.c:206
void pqDropConnection(PGconn *conn, bool flushInput)
Definition: fe-connect.c:448
#define SOCK_ERRNO
Definition: libpq-int.h:854
int inBufSize
Definition: libpq-int.h:480
bool ssl_in_use
Definition: libpq-int.h:508
pgsocket sock
Definition: libpq-int.h:444
#define PGINVALID_SOCKET
Definition: port.h:33
char * inBuffer
Definition: libpq-int.h:479
PQExpBufferData errorMessage
Definition: libpq-int.h:571
ConnStatusType status
Definition: libpq-int.h:410
#define ALL_CONNECTION_FAILURE_ERRNOS
Definition: port.h:114
#define EWOULDBLOCK
Definition: win32_port.h:357
int inCursor
Definition: libpq-int.h:482
#define EINTR
Definition: win32_port.h:351
#define libpq_gettext(x)
Definition: libpq-int.h:841

◆ pqReadReady()

int pqReadReady ( PGconn conn)

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

References pqSocketCheck().

Referenced by gss_read(), and pqReadData().

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

◆ pqSendSome()

static int pqSendSome ( PGconn conn,
int  len 
)
static

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

References PQExpBufferData::data, EAGAIN, EINTR, pg_conn::errorMessage, EWOULDBLOCK, PQExpBufferData::len, libpq_gettext, Min, pg_conn::outBuffer, pg_conn::outCount, PGINVALID_SOCKET, PQExpBufferBroken, pqIsnonblocking, pqReadData(), pqsecure_write(), pqWait(), remaining, pg_conn::sock, SOCK_ERRNO, pg_conn::write_err_msg, and pg_conn::write_failed.

Referenced by pqFlush(), and pqPutMsgEnd().

789 {
790  char *ptr = conn->outBuffer;
791  int remaining = conn->outCount;
792  int oldmsglen = conn->errorMessage.len;
793  int result = 0;
794 
795  /*
796  * If we already had a write failure, we will never again try to send data
797  * on that connection. Even if the kernel would let us, we've probably
798  * lost message boundary sync with the server. conn->write_failed
799  * therefore persists until the connection is reset, and we just discard
800  * all data presented to be written. However, as long as we still have a
801  * valid socket, we should continue to absorb data from the backend, so
802  * that we can collect any final error messages.
803  */
804  if (conn->write_failed)
805  {
806  /* conn->write_err_msg should be set up already */
807  conn->outCount = 0;
808  /* Absorb input data if any, and detect socket closure */
809  if (conn->sock != PGINVALID_SOCKET)
810  {
811  if (pqReadData(conn) < 0)
812  return -1;
813  }
814  return 0;
815  }
816 
817  if (conn->sock == PGINVALID_SOCKET)
818  {
819  conn->write_failed = true;
820  /* Insert error message into conn->write_err_msg, if possible */
821  /* (strdup failure is OK, we'll cope later) */
822  conn->write_err_msg = strdup(libpq_gettext("connection not open\n"));
823  /* Discard queued data; no chance it'll ever be sent */
824  conn->outCount = 0;
825  return 0;
826  }
827 
828  /* while there's still data to send */
829  while (len > 0)
830  {
831  int sent;
832 
833 #ifndef WIN32
834  sent = pqsecure_write(conn, ptr, len);
835 #else
836 
837  /*
838  * Windows can fail on large sends, per KB article Q201213. The
839  * failure-point appears to be different in different versions of
840  * Windows, but 64k should always be safe.
841  */
842  sent = pqsecure_write(conn, ptr, Min(len, 65536));
843 #endif
844 
845  if (sent < 0)
846  {
847  /* Anything except EAGAIN/EWOULDBLOCK/EINTR is trouble */
848  switch (SOCK_ERRNO)
849  {
850 #ifdef EAGAIN
851  case EAGAIN:
852  break;
853 #endif
854 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
855  case EWOULDBLOCK:
856  break;
857 #endif
858  case EINTR:
859  continue;
860 
861  default:
862  /* pqsecure_write set the error message for us */
863  conn->write_failed = true;
864 
865  /*
866  * Transfer error message to conn->write_err_msg, if
867  * possible (strdup failure is OK, we'll cope later).
868  *
869  * We only want to transfer whatever has been appended to
870  * conn->errorMessage since we entered this routine.
871  */
872  if (!PQExpBufferBroken(&conn->errorMessage))
873  {
874  conn->write_err_msg = strdup(conn->errorMessage.data +
875  oldmsglen);
876  conn->errorMessage.len = oldmsglen;
877  conn->errorMessage.data[oldmsglen] = '\0';
878  }
879 
880  /* Discard queued data; no chance it'll ever be sent */
881  conn->outCount = 0;
882 
883  /* Absorb input data if any, and detect socket closure */
884  if (conn->sock != PGINVALID_SOCKET)
885  {
886  if (pqReadData(conn) < 0)
887  return -1;
888  }
889  return 0;
890  }
891  }
892  else
893  {
894  ptr += sent;
895  len -= sent;
896  remaining -= sent;
897  }
898 
899  if (len > 0)
900  {
901  /*
902  * We didn't send it all, wait till we can send more.
903  *
904  * There are scenarios in which we can't send data because the
905  * communications channel is full, but we cannot expect the server
906  * to clear the channel eventually because it's blocked trying to
907  * send data to us. (This can happen when we are sending a large
908  * amount of COPY data, and the server has generated lots of
909  * NOTICE responses.) To avoid a deadlock situation, we must be
910  * prepared to accept and buffer incoming data before we try
911  * again. Furthermore, it is possible that such incoming data
912  * might not arrive until after we've gone to sleep. Therefore,
913  * we wait for either read ready or write ready.
914  *
915  * In non-blocking mode, we don't wait here directly, but return 1
916  * to indicate that data is still pending. The caller should wait
917  * for both read and write ready conditions, and call
918  * PQconsumeInput() on read ready, but just in case it doesn't, we
919  * call pqReadData() ourselves before returning. That's not
920  * enough if the data has not arrived yet, but it's the best we
921  * can do, and works pretty well in practice. (The documentation
922  * used to say that you only need to wait for write-ready, so
923  * there are still plenty of applications like that out there.)
924  *
925  * Note that errors here don't result in write_failed becoming
926  * set.
927  */
928  if (pqReadData(conn) < 0)
929  {
930  result = -1; /* error message already set up */
931  break;
932  }
933 
934  if (pqIsnonblocking(conn))
935  {
936  result = 1;
937  break;
938  }
939 
940  if (pqWait(true, true, conn))
941  {
942  result = -1;
943  break;
944  }
945  }
946  }
947 
948  /* shift the remaining contents of the buffer */
949  if (remaining > 0)
950  memmove(conn->outBuffer, ptr, remaining);
951  conn->outCount = remaining;
952 
953  return result;
954 }
int remaining
Definition: informix.c:667
#define EAGAIN
Definition: win32_port.h:349
#define pqIsnonblocking(conn)
Definition: libpq-int.h:830
int outCount
Definition: libpq-int.h:488
#define Min(x, y)
Definition: c.h:986
char * write_err_msg
Definition: libpq-int.h:455
ssize_t pqsecure_write(PGconn *conn, const void *ptr, size_t len)
Definition: fe-secure.c:288
bool write_failed
Definition: libpq-int.h:454
#define SOCK_ERRNO
Definition: libpq-int.h:854
int pqReadData(PGconn *conn)
Definition: fe-misc.c:568
int pqWait(int forRead, int forWrite, PGconn *conn)
Definition: fe-misc.c:990
pgsocket sock
Definition: libpq-int.h:444
#define PGINVALID_SOCKET
Definition: port.h:33
PQExpBufferData errorMessage
Definition: libpq-int.h:571
#define PQExpBufferBroken(str)
Definition: pqexpbuffer.h:59
char * outBuffer
Definition: libpq-int.h:486
#define EWOULDBLOCK
Definition: win32_port.h:357
#define EINTR
Definition: win32_port.h:351
#define libpq_gettext(x)
Definition: libpq-int.h:841

◆ pqSkipnchar()

int pqSkipnchar ( size_t  len,
PGconn conn 
)

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

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

Referenced by getAnotherTuple().

191 {
192  if (len > (size_t) (conn->inEnd - conn->inCursor))
193  return EOF;
194 
195  conn->inCursor += len;
196 
197  return 0;
198 }
int inEnd
Definition: libpq-int.h:483
int inCursor
Definition: libpq-int.h:482

◆ pqSocketCheck()

static int pqSocketCheck ( PGconn conn,
int  forRead,
int  forWrite,
time_t  end_time 
)
static

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

References appendPQExpBuffer(), appendPQExpBufferStr(), EINTR, pg_conn::errorMessage, libpq_gettext, PG_STRERROR_R_BUFLEN, PGINVALID_SOCKET, pgtls_read_pending(), pqSocketPoll(), pg_conn::sock, SOCK_ERRNO, SOCK_STRERROR, and pg_conn::ssl_in_use.

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

1052 {
1053  int result;
1054 
1055  if (!conn)
1056  return -1;
1057  if (conn->sock == PGINVALID_SOCKET)
1058  {
1060  libpq_gettext("invalid socket\n"));
1061  return -1;
1062  }
1063 
1064 #ifdef USE_SSL
1065  /* Check for SSL library buffering read bytes */
1066  if (forRead && conn->ssl_in_use && pgtls_read_pending(conn))
1067  {
1068  /* short-circuit the select */
1069  return 1;
1070  }
1071 #endif
1072 
1073  /* We will retry as long as we get EINTR */
1074  do
1075  result = pqSocketPoll(conn->sock, forRead, forWrite, end_time);
1076  while (result < 0 && SOCK_ERRNO == EINTR);
1077 
1078  if (result < 0)
1079  {
1080  char sebuf[PG_STRERROR_R_BUFLEN];
1081 
1083  libpq_gettext("%s() failed: %s\n"),
1084  "select",
1085  SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
1086  }
1087 
1088  return result;
1089 }
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define PG_STRERROR_R_BUFLEN
Definition: port.h:235
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:855
int64 end_time
Definition: pgbench.c:185
#define SOCK_ERRNO
Definition: libpq-int.h:854
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
bool ssl_in_use
Definition: libpq-int.h:508
bool pgtls_read_pending(PGconn *conn)
pgsocket sock
Definition: libpq-int.h:444
#define PGINVALID_SOCKET
Definition: port.h:33
PQExpBufferData errorMessage
Definition: libpq-int.h:571
#define EINTR
Definition: win32_port.h:351
#define libpq_gettext(x)
Definition: libpq-int.h:841

◆ pqSocketPoll()

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(), 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 }
int64 end_time
Definition: pgbench.c:185
#define select(n, r, w, e, timeout)
Definition: win32_port.h:474
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1544

◆ pqWait()

int pqWait ( int  forRead,
int  forWrite,
PGconn conn 
)

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

References pqWaitTimed().

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

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

◆ pqWaitTimed()

int pqWaitTimed ( int  forRead,
int  forWrite,
PGconn conn,
time_t  finish_time 
)

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

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

Referenced by connectDBComplete(), and pqWait().

1004 {
1005  int result;
1006 
1007  result = pqSocketCheck(conn, forRead, forWrite, finish_time);
1008 
1009  if (result < 0)
1010  return -1; /* errorMessage is already set */
1011 
1012  if (result == 0)
1013  {
1015  libpq_gettext("timeout expired\n"));
1016  return 1;
1017  }
1018 
1019  return 0;
1020 }
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
static int pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
Definition: fe-misc.c:1051
PQExpBufferData errorMessage
Definition: libpq-int.h:571
#define libpq_gettext(x)
Definition: libpq-int.h:841

◆ pqWriteReady()

int pqWriteReady ( PGconn conn)

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

References pqSocketCheck().

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