PostgreSQL Source Code  git master
fe-misc.c File Reference
#include "postgres_fe.h"
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <sys/select.h>
#include <poll.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)
 
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 PQsocketPoll (int sock, int forRead, int forWrite, time_t end_time)
 
int PQmblen (const char *s, int encoding)
 
int PQmblenBounded (const char *s, int encoding)
 
int PQdsplen (const char *s, int encoding)
 
int PQenv2encoding (void)
 
void libpq_append_error (PQExpBuffer errorMessage, const char *fmt,...)
 
void libpq_append_conn_error (PGconn *conn, const char *fmt,...)
 

Function Documentation

◆ libpq_append_conn_error()

void libpq_append_conn_error ( PGconn conn,
const char *  fmt,
  ... 
)

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

1325 {
1326  int save_errno = errno;
1327  bool done;
1328  va_list args;
1329 
1330  Assert(fmt[strlen(fmt) - 1] != '\n');
1331 
1333  return; /* already failed */
1334 
1335  /* Loop in case we have to retry after enlarging the buffer. */
1336  do
1337  {
1338  errno = save_errno;
1339  va_start(args, fmt);
1341  va_end(args);
1342  } while (!done);
1343 
1345 }
#define Assert(condition)
Definition: c.h:858
#define libpq_gettext(x)
Definition: libpq-int.h:913
static void const char * fmt
va_end(args)
va_start(args, fmt)
bool appendPQExpBufferVA(PQExpBuffer str, const char *fmt, va_list args)
Definition: pqexpbuffer.c:294
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378
#define PQExpBufferBroken(str)
Definition: pqexpbuffer.h:59
PGconn * conn
Definition: streamutil.c:55
PQExpBufferData errorMessage
Definition: libpq-int.h:635

References appendPQExpBufferChar(), appendPQExpBufferVA(), generate_unaccent_rules::args, Assert, conn, pg_conn::errorMessage, fmt, libpq_gettext, PQExpBufferBroken, va_end(), and va_start().

Referenced by build_client_final_message(), build_client_first_message(), check_expected_areq(), connectFailureMessage(), connectNoDelay(), fillPGconn(), handleSyncLoss(), init_allowed_encryption_methods(), initialize_SSL(), lo_create(), lo_export(), lo_import_internal(), lo_initialize(), lo_lseek64(), lo_read(), lo_tell64(), lo_truncate(), lo_truncate64(), lo_write(), open_client_SSL(), openssl_verify_peer_name_matches_certificate_ip(), openssl_verify_peer_name_matches_certificate_name(), pg_fe_sendauth(), pg_GSS_load_servicename(), pg_GSS_read(), pg_GSS_write(), pg_password_sendauth(), pg_SASL_continue(), pg_SASL_init(), pgpassfileWarning(), pgtls_get_peer_certificate_hash(), pgtls_read(), pgtls_write(), pq_verify_peer_name_matches_certificate(), pq_verify_peer_name_matches_certificate_ip(), pq_verify_peer_name_matches_certificate_name(), pqAllocCmdQueueEntry(), PQcancelCreate(), PQcancelPoll(), PQcancelStart(), pqConnectOptions2(), PQconnectPoll(), pqCopyPGconn(), PQencryptPasswordConn(), pqEndcopy3(), PQenterPipelineMode(), PQescapeByteaInternal(), PQescapeInternal(), PQescapeStringInternal(), PQexecStart(), PQexitPipelineMode(), PQfn(), pqFunctionCall3(), PQgetCopyData(), pqGetCopyData3(), pqGetErrorNotice3(), pqGetline3(), pqGetNegotiateProtocolVersion3(), PQgetResult(), pqParseInput3(), pqParseIntParam(), pqPipelineProcessQueue(), pqPipelineSyncInternal(), pqPrepareAsyncResult(), PQputCopyData(), PQputCopyEnd(), pqReadData(), pqSaveWriteError(), pqsecure_open_gss(), pqsecure_raw_read(), PQsendFlushRequest(), PQsendPrepare(), PQsendQueryGuts(), PQsendQueryInternal(), PQsendQueryParams(), PQsendQueryPrepared(), PQsendQueryStart(), PQsendTypedCommand(), PQsetdbLogin(), pqSocketCheck(), pqWaitTimed(), read_server_final_message(), read_server_first_message(), scram_exchange(), select_next_encryption_method(), setKeepalivesCount(), setKeepalivesIdle(), setKeepalivesInterval(), setTCPUserTimeout(), and store_conn_addrinfo().

◆ libpq_append_error()

void libpq_append_error ( PQExpBuffer  errorMessage,
const char *  fmt,
  ... 
)

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

1296 {
1297  int save_errno = errno;
1298  bool done;
1299  va_list args;
1300 
1301  Assert(fmt[strlen(fmt) - 1] != '\n');
1302 
1303  if (PQExpBufferBroken(errorMessage))
1304  return; /* already failed */
1305 
1306  /* Loop in case we have to retry after enlarging the buffer. */
1307  do
1308  {
1309  errno = save_errno;
1310  va_start(args, fmt);
1311  done = appendPQExpBufferVA(errorMessage, libpq_gettext(fmt), args);
1312  va_end(args);
1313  } while (!done);
1314 
1315  appendPQExpBufferChar(errorMessage, '\n');
1316 }

References appendPQExpBufferChar(), appendPQExpBufferVA(), generate_unaccent_rules::args, Assert, fmt, libpq_gettext, PQExpBufferBroken, va_end(), and va_start().

Referenced by conninfo_add_defaults(), conninfo_array_parse(), conninfo_init(), conninfo_parse(), conninfo_storeval(), conninfo_uri_decode(), conninfo_uri_parse_options(), conninfo_uri_parse_params(), parseServiceFile(), parseServiceInfo(), pg_fe_getusername(), and read_attr_value().

◆ pqCheckInBufferSpace()

int pqCheckInBufferSpace ( size_t  bytes_needed,
PGconn conn 
)

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

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

References appendPQExpBufferStr(), conn, 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().

◆ pqCheckOutBufferSpace()

int pqCheckOutBufferSpace ( size_t  bytes_needed,
PGconn conn 
)

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

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

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

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

◆ PQdsplen()

int PQdsplen ( const char *  s,
int  encoding 
)

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

1197 {
1198  return pg_encoding_dsplen(encoding, s);
1199 }
int32 encoding
Definition: pg_database.h:41
int pg_encoding_dsplen(int encoding, const char *mbstr)
Definition: wchar.c:2090

References encoding, and pg_encoding_dsplen().

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

◆ PQenv2encoding()

int PQenv2encoding ( void  )

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

1206 {
1207  char *str;
1208  int encoding = PG_SQL_ASCII;
1209 
1210  str = getenv("PGCLIENTENCODING");
1211  if (str && *str != '\0')
1212  {
1214  if (encoding < 0)
1216  }
1217  return encoding;
1218 }
const char * str
@ PG_SQL_ASCII
Definition: pg_wchar.h:226
#define pg_char_to_encoding
Definition: pg_wchar.h:629

References encoding, pg_char_to_encoding, PG_SQL_ASCII, and str.

Referenced by main().

◆ pqFlush()

int pqFlush ( PGconn conn)

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

954 {
955  if (conn->outCount > 0)
956  {
957  if (conn->Pfdebug)
958  fflush(conn->Pfdebug);
959 
960  return pqSendSome(conn, conn->outCount);
961  }
962 
963  return 0;
964 }
static int pqSendSome(PGconn *conn, int len)
Definition: fe-misc.c:784
static void const char fflush(stdout)
FILE * Pfdebug
Definition: libpq-int.h:426
int outCount
Definition: libpq-int.h:533

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

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

◆ pqGetc()

int pqGetc ( char *  result,
PGconn conn 
)

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

78 {
79  if (conn->inCursor >= conn->inEnd)
80  return EOF;
81 
82  *result = conn->inBuffer[conn->inCursor++];
83 
84  return 0;
85 }

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

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

◆ pqGetInt()

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

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

217 {
218  uint16 tmp2;
219  uint32 tmp4;
220 
221  switch (bytes)
222  {
223  case 2:
224  if (conn->inCursor + 2 > conn->inEnd)
225  return EOF;
226  memcpy(&tmp2, conn->inBuffer + conn->inCursor, 2);
227  conn->inCursor += 2;
228  *result = (int) pg_ntoh16(tmp2);
229  break;
230  case 4:
231  if (conn->inCursor + 4 > conn->inEnd)
232  return EOF;
233  memcpy(&tmp4, conn->inBuffer + conn->inCursor, 4);
234  conn->inCursor += 4;
235  *result = (int) pg_ntoh32(tmp4);
236  break;
237  default:
239  "integer of size %lu not supported by pqGetInt",
240  (unsigned long) bytes);
241  return EOF;
242  }
243 
244  return 0;
245 }
unsigned short uint16
Definition: c.h:505
unsigned int uint32
Definition: c.h:506
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
Definition: fe-exec.c:938
#define pg_ntoh32(x)
Definition: pg_bswap.h:125
#define pg_ntoh16(x)
Definition: pg_bswap.h:124
PGNoticeHooks noticeHooks
Definition: libpq-int.h:430

References conn, 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(), pqGetNegotiateProtocolVersion3(), and pqParseInput3().

◆ pqGetnchar()

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

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

166 {
167  if (len > (size_t) (conn->inEnd - conn->inCursor))
168  return EOF;
169 
170  memcpy(s, conn->inBuffer + conn->inCursor, len);
171  /* no terminating null */
172 
173  conn->inCursor += len;
174 
175  return 0;
176 }
const void size_t len

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

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

◆ pqGets()

int pqGets ( PQExpBuffer  buf,
PGconn conn 
)

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

137 {
138  return pqGets_internal(buf, conn, true);
139 }
static int pqGets_internal(PQExpBuffer buf, PGconn *conn, bool resetbuffer)
Definition: fe-misc.c:109
static char * buf
Definition: pg_test_fsync.c:73

References buf, conn, and pqGets_internal().

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

◆ pqGets_append()

int pqGets_append ( PQExpBuffer  buf,
PGconn conn 
)

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

143 {
144  return pqGets_internal(buf, conn, false);
145 }

References buf, conn, and pqGets_internal().

Referenced by PQconnectPoll().

◆ pqGets_internal()

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

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

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

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

Referenced by pqGets(), and pqGets_append().

◆ PQlibVersion()

int PQlibVersion ( void  )

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

64 {
65  return PG_VERSION_NUM;
66 }

◆ PQmblen()

int PQmblen ( const char *  s,
int  encoding 
)

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

1177 {
1178  return pg_encoding_mblen(encoding, s);
1179 }
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition: wchar.c:2069

References encoding, and pg_encoding_mblen().

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

◆ PQmblenBounded()

int PQmblenBounded ( const char *  s,
int  encoding 
)

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

1187 {
1188  return strnlen(s, pg_encoding_mblen(encoding, s));
1189 }
size_t strnlen(const char *str, size_t maxlen)
Definition: strnlen.c:26

References encoding, pg_encoding_mblen(), and strnlen().

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

◆ pqPutc()

int pqPutc ( char  c,
PGconn conn 
)

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

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

References conn, and pqPutMsgBytes().

Referenced by PQsendQueryGuts(), and PQsendTypedCommand().

◆ pqPutInt()

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

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

254 {
255  uint16 tmp2;
256  uint32 tmp4;
257 
258  switch (bytes)
259  {
260  case 2:
261  tmp2 = pg_hton16((uint16) value);
262  if (pqPutMsgBytes((const char *) &tmp2, 2, conn))
263  return EOF;
264  break;
265  case 4:
266  tmp4 = pg_hton32((uint32) value);
267  if (pqPutMsgBytes((const char *) &tmp4, 4, conn))
268  return EOF;
269  break;
270  default:
272  "integer of size %lu not supported by pqPutInt",
273  (unsigned long) bytes);
274  return EOF;
275  }
276 
277  return 0;
278 }
static struct @155 value
#define pg_hton32(x)
Definition: pg_bswap.h:121
#define pg_hton16(x)
Definition: pg_bswap.h:120

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

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

◆ pqPutMsgBytes()

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

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

495 {
496  /* make sure there is room for it */
498  return EOF;
499  /* okay, save the data */
500  memcpy(conn->outBuffer + conn->outMsgEnd, buf, len);
501  conn->outMsgEnd += len;
502  /* no Pfdebug call here, caller should do it */
503  return 0;
504 }
int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn)
Definition: fe-misc.c:287
int outMsgEnd
Definition: libpq-int.h:538

References buf, conn, len, pg_conn::outBuffer, pg_conn::outMsgEnd, and pqCheckOutBufferSpace().

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

◆ pqPutMsgEnd()

int pqPutMsgEnd ( PGconn conn)

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

518 {
519  /* Fill in length word if needed */
520  if (conn->outMsgStart >= 0)
521  {
522  uint32 msgLen = conn->outMsgEnd - conn->outMsgStart;
523 
524  msgLen = pg_hton32(msgLen);
525  memcpy(conn->outBuffer + conn->outMsgStart, &msgLen, 4);
526  }
527 
528  /* trace client-to-server message */
529  if (conn->Pfdebug)
530  {
531  if (conn->outCount < conn->outMsgStart)
533  else
536  }
537 
538  /* Make message eligible to send */
540 
541  if (conn->outCount >= 8192)
542  {
543  int toSend = conn->outCount - (conn->outCount % 8192);
544 
545  if (pqSendSome(conn, toSend) < 0)
546  return EOF;
547  /* in nonblock mode, don't complain if unable to send it all */
548  }
549 
550  return 0;
551 }
void pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer)
Definition: fe-trace.c:529
void pqTraceOutputNoTypeByteMessage(PGconn *conn, const char *message)
Definition: fe-trace.c:704
int outMsgStart
Definition: libpq-int.h:536

References conn, 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(), pqPipelineSyncInternal(), PQputCopyData(), PQputCopyEnd(), PQsendFlushRequest(), PQsendPrepare(), PQsendQueryGuts(), PQsendQueryInternal(), PQsendTypedCommand(), and sendTerminateConn().

◆ pqPutMsgStart()

int pqPutMsgStart ( char  msg_type,
PGconn conn 
)

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

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

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

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

◆ pqPutnchar()

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

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

203 {
204  if (pqPutMsgBytes(s, len, conn))
205  return EOF;
206 
207  return 0;
208 }

References conn, len, and pqPutMsgBytes().

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

◆ pqPuts()

int pqPuts ( const char *  s,
PGconn conn 
)

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

153 {
154  if (pqPutMsgBytes(s, strlen(s) + 1, conn))
155  return EOF;
156 
157  return 0;
158 }

References conn, and pqPutMsgBytes().

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

◆ pqReadData()

int pqReadData ( PGconn conn)

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

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

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

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

◆ pqReadReady()

int pqReadReady ( PGconn conn)

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

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

References conn, and pqSocketCheck().

Referenced by gss_read(), and pqReadData().

◆ pqSendSome()

static int pqSendSome ( PGconn conn,
int  len 
)
static

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

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

References conn, EAGAIN, EINTR, EWOULDBLOCK, len, libpq_gettext, Min, pg_conn::outBuffer, pg_conn::outCount, PGINVALID_SOCKET, 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().

◆ pqSkipnchar()

int pqSkipnchar ( size_t  len,
PGconn conn 
)

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

188 {
189  if (len > (size_t) (conn->inEnd - conn->inCursor))
190  return EOF;
191 
192  conn->inCursor += len;
193 
194  return 0;
195 }

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

Referenced by getAnotherTuple().

◆ pqSocketCheck()

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

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

1039 {
1040  int result;
1041 
1042  if (!conn)
1043  return -1;
1044  if (conn->sock == PGINVALID_SOCKET)
1045  {
1046  libpq_append_conn_error(conn, "invalid socket");
1047  return -1;
1048  }
1049 
1050 #ifdef USE_SSL
1051  /* Check for SSL library buffering read bytes */
1052  if (forRead && conn->ssl_in_use && pgtls_read_pending(conn))
1053  {
1054  /* short-circuit the select */
1055  return 1;
1056  }
1057 #endif
1058 
1059  /* We will retry as long as we get EINTR */
1060  do
1061  result = PQsocketPoll(conn->sock, forRead, forWrite, end_time);
1062  while (result < 0 && SOCK_ERRNO == EINTR);
1063 
1064  if (result < 0)
1065  {
1066  char sebuf[PG_STRERROR_R_BUFLEN];
1067 
1068  libpq_append_conn_error(conn, "%s() failed: %s", "select",
1069  SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
1070  }
1071 
1072  return result;
1073 }
int PQsocketPoll(int sock, int forRead, int forWrite, time_t end_time)
Definition: fe-misc.c:1086
bool pgtls_read_pending(PGconn *conn)
#define SOCK_STRERROR
Definition: libpq-int.h:935
int64 end_time
Definition: pgbench.c:175
#define PG_STRERROR_R_BUFLEN
Definition: port.h:256

References conn, EINTR, end_time, libpq_append_conn_error(), 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().

◆ PQsocketPoll()

int PQsocketPoll ( int  sock,
int  forRead,
int  forWrite,
time_t  end_time 
)

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

1087 {
1088  /* We use poll(2) if available, otherwise select(2) */
1089 #ifdef HAVE_POLL
1090  struct pollfd input_fd;
1091  int timeout_ms;
1092 
1093  if (!forRead && !forWrite)
1094  return 0;
1095 
1096  input_fd.fd = sock;
1097  input_fd.events = POLLERR;
1098  input_fd.revents = 0;
1099 
1100  if (forRead)
1101  input_fd.events |= POLLIN;
1102  if (forWrite)
1103  input_fd.events |= POLLOUT;
1104 
1105  /* Compute appropriate timeout interval */
1106  if (end_time == ((time_t) -1))
1107  timeout_ms = -1;
1108  else
1109  {
1110  time_t now = time(NULL);
1111 
1112  if (end_time > now)
1113  timeout_ms = (end_time - now) * 1000;
1114  else
1115  timeout_ms = 0;
1116  }
1117 
1118  return poll(&input_fd, 1, timeout_ms);
1119 #else /* !HAVE_POLL */
1120 
1121  fd_set input_mask;
1122  fd_set output_mask;
1123  fd_set except_mask;
1124  struct timeval timeout;
1125  struct timeval *ptr_timeout;
1126 
1127  if (!forRead && !forWrite)
1128  return 0;
1129 
1130  FD_ZERO(&input_mask);
1131  FD_ZERO(&output_mask);
1132  FD_ZERO(&except_mask);
1133  if (forRead)
1134  FD_SET(sock, &input_mask);
1135 
1136  if (forWrite)
1137  FD_SET(sock, &output_mask);
1138  FD_SET(sock, &except_mask);
1139 
1140  /* Compute appropriate timeout interval */
1141  if (end_time == ((time_t) -1))
1142  ptr_timeout = NULL;
1143  else
1144  {
1145  time_t now = time(NULL);
1146 
1147  if (end_time > now)
1148  timeout.tv_sec = end_time - now;
1149  else
1150  timeout.tv_sec = 0;
1151  timeout.tv_usec = 0;
1152  ptr_timeout = &timeout;
1153  }
1154 
1155  return select(sock + 1, &input_mask, &output_mask,
1156  &except_mask, ptr_timeout);
1157 #endif /* HAVE_POLL */
1158 }
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1618
#define select(n, r, w, e, timeout)
Definition: win32_port.h:495

References end_time, now(), and select.

Referenced by pqSocketCheck(), and wait_until_connected().

◆ pqWait()

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

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

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

References conn, and pqWaitTimed().

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

◆ pqWaitTimed()

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

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

992 {
993  int result;
994 
995  result = pqSocketCheck(conn, forRead, forWrite, finish_time);
996 
997  if (result < 0)
998  return -1; /* errorMessage is already set */
999 
1000  if (result == 0)
1001  {
1002  libpq_append_conn_error(conn, "timeout expired");
1003  return 1;
1004  }
1005 
1006  return 0;
1007 }

References conn, libpq_append_conn_error(), and pqSocketCheck().

Referenced by pqConnectDBComplete(), and pqWait().

◆ pqWriteReady()

int pqWriteReady ( PGconn conn)

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

1025 {
1026  return pqSocketCheck(conn, 0, 1, (time_t) 0);
1027 }

References conn, and pqSocketCheck().