PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pqcomm.c File Reference
#include "postgres.h"
#include <signal.h>
#include <fcntl.h>
#include <grp.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "common/ip.h"
#include "libpq/libpq.h"
#include "miscadmin.h"
#include "storage/ipc.h"
#include "utils/guc.h"
#include "utils/memutils.h"
Include dependency graph for pqcomm.c:

Go to the source code of this file.

Macros

#define PQ_SEND_BUFFER_SIZE   8192
 
#define PQ_RECV_BUFFER_SIZE   8192
 

Functions

static void socket_comm_reset (void)
 
static void socket_close (int code, Datum arg)
 
static void socket_set_nonblocking (bool nonblocking)
 
static int socket_flush (void)
 
static int socket_flush_if_writable (void)
 
static bool socket_is_send_pending (void)
 
static int socket_putmessage (char msgtype, const char *s, size_t len)
 
static void socket_putmessage_noblock (char msgtype, const char *s, size_t len)
 
static void socket_startcopyout (void)
 
static void socket_endcopyout (bool errorAbort)
 
static int internal_putbytes (const char *s, size_t len)
 
static int internal_flush (void)
 
void pq_init (void)
 
int StreamServerPort (int family, char *hostName, unsigned short portNumber, char *unixSocketDir, pgsocket ListenSocket[], int MaxListen)
 
int StreamConnection (pgsocket server_fd, Port *port)
 
void StreamClose (pgsocket sock)
 
void TouchSocketFiles (void)
 
void RemoveSocketFiles (void)
 
static int pq_recvbuf (void)
 
int pq_getbyte (void)
 
int pq_peekbyte (void)
 
int pq_getbyte_if_available (unsigned char *c)
 
int pq_getbytes (char *s, size_t len)
 
static int pq_discardbytes (size_t len)
 
int pq_getstring (StringInfo s)
 
void pq_startmsgread (void)
 
void pq_endmsgread (void)
 
bool pq_is_reading_msg (void)
 
int pq_getmessage (StringInfo s, int maxlen)
 
int pq_putbytes (const char *s, size_t len)
 
int pq_getkeepalivesidle (Port *port)
 
int pq_setkeepalivesidle (int idle, Port *port)
 
int pq_getkeepalivesinterval (Port *port)
 
int pq_setkeepalivesinterval (int interval, Port *port)
 
int pq_getkeepalivescount (Port *port)
 
int pq_setkeepalivescount (int count, Port *port)
 

Variables

int Unix_socket_permissions
 
char * Unix_socket_group
 
static Listsock_paths = NIL
 
static char * PqSendBuffer
 
static int PqSendBufferSize
 
static int PqSendPointer
 
static int PqSendStart
 
static char PqRecvBuffer [PQ_RECV_BUFFER_SIZE]
 
static int PqRecvPointer
 
static int PqRecvLength
 
static bool PqCommBusy
 
static bool PqCommReadingMsg
 
static bool DoingCopyOut
 
static PQcommMethods PqCommSocketMethods
 
PQcommMethodsPqCommMethods = &PqCommSocketMethods
 
WaitEventSetFeBeWaitSet
 

Macro Definition Documentation

#define PQ_RECV_BUFFER_SIZE   8192

Definition at line 116 of file pqcomm.c.

Referenced by pq_recvbuf().

#define PQ_SEND_BUFFER_SIZE   8192

Definition at line 115 of file pqcomm.c.

Referenced by pq_init(), and StreamConnection().

Function Documentation

static int internal_flush ( void  )
static

Definition at line 1403 of file pqcomm.c.

References ClientConnectionLost, COMMERROR, EAGAIN, EINTR, ereport, errcode_for_socket_access(), errmsg(), EWOULDBLOCK, InterruptPending, MyProcPort, PqSendBuffer, PqSendPointer, PqSendStart, and secure_write().

Referenced by internal_putbytes(), socket_flush(), and socket_flush_if_writable().

1404 {
1405  static int last_reported_send_errno = 0;
1406 
1407  char *bufptr = PqSendBuffer + PqSendStart;
1408  char *bufend = PqSendBuffer + PqSendPointer;
1409 
1410  while (bufptr < bufend)
1411  {
1412  int r;
1413 
1414  r = secure_write(MyProcPort, bufptr, bufend - bufptr);
1415 
1416  if (r <= 0)
1417  {
1418  if (errno == EINTR)
1419  continue; /* Ok if we were interrupted */
1420 
1421  /*
1422  * Ok if no data writable without blocking, and the socket is in
1423  * non-blocking mode.
1424  */
1425  if (errno == EAGAIN ||
1426  errno == EWOULDBLOCK)
1427  {
1428  return 0;
1429  }
1430 
1431  /*
1432  * Careful: an ereport() that tries to write to the client would
1433  * cause recursion to here, leading to stack overflow and core
1434  * dump! This message must go *only* to the postmaster log.
1435  *
1436  * If a client disconnects while we're in the midst of output, we
1437  * might write quite a bit of data before we get to a safe query
1438  * abort point. So, suppress duplicate log messages.
1439  */
1440  if (errno != last_reported_send_errno)
1441  {
1442  last_reported_send_errno = errno;
1445  errmsg("could not send data to client: %m")));
1446  }
1447 
1448  /*
1449  * We drop the buffered data anyway so that processing can
1450  * continue, even though we'll probably quit soon. We also set a
1451  * flag that'll cause the next CHECK_FOR_INTERRUPTS to terminate
1452  * the connection.
1453  */
1454  PqSendStart = PqSendPointer = 0;
1456  InterruptPending = 1;
1457  return EOF;
1458  }
1459 
1460  last_reported_send_errno = 0; /* reset after any successful send */
1461  bufptr += r;
1462  PqSendStart += r;
1463  }
1464 
1465  PqSendStart = PqSendPointer = 0;
1466  return 0;
1467 }
#define EWOULDBLOCK
Definition: win32.h:291
struct Port * MyProcPort
Definition: globals.c:40
static char * PqSendBuffer
Definition: pqcomm.c:118
static int PqSendStart
Definition: pqcomm.c:121
#define EAGAIN
Definition: win32.h:283
volatile bool ClientConnectionLost
Definition: globals.c:32
static int PqSendPointer
Definition: pqcomm.c:120
#define COMMERROR
Definition: elog.h:30
ssize_t secure_write(Port *port, void *ptr, size_t len)
Definition: be-secure.c:240
#define ereport(elevel, rest)
Definition: elog.h:122
int errcode_for_socket_access(void)
Definition: elog.c:669
#define EINTR
Definition: win32.h:285
volatile bool InterruptPending
Definition: globals.c:29
int errmsg(const char *fmt,...)
Definition: elog.c:797
static int internal_putbytes ( const char *  s,
size_t  len 
)
static

Definition at line 1350 of file pqcomm.c.

References internal_flush(), PqSendBuffer, PqSendBufferSize, PqSendPointer, and socket_set_nonblocking().

Referenced by pq_putbytes(), and socket_putmessage().

1351 {
1352  size_t amount;
1353 
1354  while (len > 0)
1355  {
1356  /* If buffer is full, then flush it out */
1358  {
1359  socket_set_nonblocking(false);
1360  if (internal_flush())
1361  return EOF;
1362  }
1363  amount = PqSendBufferSize - PqSendPointer;
1364  if (amount > len)
1365  amount = len;
1366  memcpy(PqSendBuffer + PqSendPointer, s, amount);
1367  PqSendPointer += amount;
1368  s += amount;
1369  len -= amount;
1370  }
1371  return 0;
1372 }
static char * PqSendBuffer
Definition: pqcomm.c:118
static int internal_flush(void)
Definition: pqcomm.c:1403
static void socket_set_nonblocking(bool nonblocking)
Definition: pqcomm.c:903
static int PqSendPointer
Definition: pqcomm.c:120
static int PqSendBufferSize
Definition: pqcomm.c:119
static int pq_discardbytes ( size_t  len)
static

Definition at line 1109 of file pqcomm.c.

References Assert, pq_recvbuf(), PqCommReadingMsg, PqRecvLength, and PqRecvPointer.

Referenced by pq_getmessage().

1110 {
1111  size_t amount;
1112 
1114 
1115  while (len > 0)
1116  {
1117  while (PqRecvPointer >= PqRecvLength)
1118  {
1119  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1120  return EOF; /* Failed to recv data */
1121  }
1122  amount = PqRecvLength - PqRecvPointer;
1123  if (amount > len)
1124  amount = len;
1125  PqRecvPointer += amount;
1126  len -= amount;
1127  }
1128  return 0;
1129 }
static int PqRecvLength
Definition: pqcomm.c:125
static int pq_recvbuf(void)
Definition: pqcomm.c:920
#define Assert(condition)
Definition: c.h:675
static int PqRecvPointer
Definition: pqcomm.c:124
static bool PqCommReadingMsg
Definition: pqcomm.c:131
void pq_endmsgread ( void  )

Definition at line 1215 of file pqcomm.c.

References Assert, and PqCommReadingMsg.

Referenced by CopyFrom(), ProcessRepliesIfAny(), ProcessStartupPacket(), and SocketBackend().

1216 {
1218 
1219  PqCommReadingMsg = false;
1220 }
#define Assert(condition)
Definition: c.h:675
static bool PqCommReadingMsg
Definition: pqcomm.c:131
int pq_getbyte ( void  )

Definition at line 981 of file pqcomm.c.

References Assert, pq_recvbuf(), PqCommReadingMsg, PqRecvBuffer, PqRecvLength, and PqRecvPointer.

Referenced by CheckSCRAMAuth(), CopyGetData(), recv_password_packet(), and SocketBackend().

982 {
984 
985  while (PqRecvPointer >= PqRecvLength)
986  {
987  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
988  return EOF; /* Failed to recv data */
989  }
990  return (unsigned char) PqRecvBuffer[PqRecvPointer++];
991 }
static char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
Definition: pqcomm.c:123
static int PqRecvLength
Definition: pqcomm.c:125
static int pq_recvbuf(void)
Definition: pqcomm.c:920
#define Assert(condition)
Definition: c.h:675
static int PqRecvPointer
Definition: pqcomm.c:124
static bool PqCommReadingMsg
Definition: pqcomm.c:131
int pq_getbyte_if_available ( unsigned char *  c)

Definition at line 1021 of file pqcomm.c.

References Assert, COMMERROR, EAGAIN, EINTR, ereport, errcode_for_socket_access(), errmsg(), EWOULDBLOCK, MyProcPort, PqCommReadingMsg, PqRecvBuffer, PqRecvLength, PqRecvPointer, secure_read(), and socket_set_nonblocking().

Referenced by ProcessRepliesIfAny().

1022 {
1023  int r;
1024 
1026 
1028  {
1030  return 1;
1031  }
1032 
1033  /* Put the socket into non-blocking mode */
1034  socket_set_nonblocking(true);
1035 
1036  r = secure_read(MyProcPort, c, 1);
1037  if (r < 0)
1038  {
1039  /*
1040  * Ok if no data available without blocking or interrupted (though
1041  * EINTR really shouldn't happen with a non-blocking socket). Report
1042  * other errors.
1043  */
1044  if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
1045  r = 0;
1046  else
1047  {
1048  /*
1049  * Careful: an ereport() that tries to write to the client would
1050  * cause recursion to here, leading to stack overflow and core
1051  * dump! This message must go *only* to the postmaster log.
1052  */
1055  errmsg("could not receive data from client: %m")));
1056  r = EOF;
1057  }
1058  }
1059  else if (r == 0)
1060  {
1061  /* EOF detected */
1062  r = EOF;
1063  }
1064 
1065  return r;
1066 }
#define EWOULDBLOCK
Definition: win32.h:291
static char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
Definition: pqcomm.c:123
struct Port * MyProcPort
Definition: globals.c:40
ssize_t secure_read(Port *port, void *ptr, size_t len)
Definition: be-secure.c:137
#define EAGAIN
Definition: win32.h:283
static void socket_set_nonblocking(bool nonblocking)
Definition: pqcomm.c:903
static int PqRecvLength
Definition: pqcomm.c:125
char * c
#define COMMERROR
Definition: elog.h:30
#define ereport(elevel, rest)
Definition: elog.h:122
int errcode_for_socket_access(void)
Definition: elog.c:669
#define EINTR
Definition: win32.h:285
#define Assert(condition)
Definition: c.h:675
int errmsg(const char *fmt,...)
Definition: elog.c:797
static int PqRecvPointer
Definition: pqcomm.c:124
static bool PqCommReadingMsg
Definition: pqcomm.c:131
int pq_getbytes ( char *  s,
size_t  len 
)

Definition at line 1075 of file pqcomm.c.

References Assert, pq_recvbuf(), PqCommReadingMsg, PqRecvBuffer, PqRecvLength, and PqRecvPointer.

Referenced by CopyGetData(), GetOldFunctionMessage(), pq_getmessage(), and ProcessStartupPacket().

1076 {
1077  size_t amount;
1078 
1080 
1081  while (len > 0)
1082  {
1083  while (PqRecvPointer >= PqRecvLength)
1084  {
1085  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1086  return EOF; /* Failed to recv data */
1087  }
1088  amount = PqRecvLength - PqRecvPointer;
1089  if (amount > len)
1090  amount = len;
1091  memcpy(s, PqRecvBuffer + PqRecvPointer, amount);
1092  PqRecvPointer += amount;
1093  s += amount;
1094  len -= amount;
1095  }
1096  return 0;
1097 }
static char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
Definition: pqcomm.c:123
static int PqRecvLength
Definition: pqcomm.c:125
static int pq_recvbuf(void)
Definition: pqcomm.c:920
#define Assert(condition)
Definition: c.h:675
static int PqRecvPointer
Definition: pqcomm.c:124
static bool PqCommReadingMsg
Definition: pqcomm.c:131
int pq_getkeepalivescount ( Port port)

Definition at line 1857 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_count, elog, IS_AF_UNIX, Port::keepalives_count, Port::laddr, LOG, NULL, and Port::sock.

Referenced by pq_setkeepalivescount(), and show_tcp_keepalives_count().

1858 {
1859 #ifdef TCP_KEEPCNT
1860  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1861  return 0;
1862 
1863  if (port->keepalives_count != 0)
1864  return port->keepalives_count;
1865 
1866  if (port->default_keepalives_count == 0)
1867  {
1868  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_count);
1869 
1870  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1871  (char *) &port->default_keepalives_count,
1872  &size) < 0)
1873  {
1874  elog(LOG, "getsockopt(TCP_KEEPCNT) failed: %m");
1875  port->default_keepalives_count = -1; /* don't know */
1876  }
1877  }
1878 
1879  return port->default_keepalives_count;
1880 #else
1881  return 0;
1882 #endif
1883 }
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define LOG
Definition: elog.h:26
int default_keepalives_count
Definition: libpq-be.h:162
pgsocket sock
Definition: libpq-be.h:118
int keepalives_count
Definition: libpq-be.h:165
#define IS_AF_UNIX(fam)
Definition: ip.h:24
SockAddr laddr
Definition: libpq-be.h:121
#define NULL
Definition: c.h:229
#define elog
Definition: elog.h:219
int pq_getkeepalivesidle ( Port port)

Definition at line 1677 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_idle, elog, IS_AF_UNIX, Port::keepalives_idle, Port::laddr, LOG, NULL, and Port::sock.

Referenced by pq_setkeepalivesidle(), and show_tcp_keepalives_idle().

1678 {
1679 #if defined(TCP_KEEPIDLE) || defined(TCP_KEEPALIVE) || defined(WIN32)
1680  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1681  return 0;
1682 
1683  if (port->keepalives_idle != 0)
1684  return port->keepalives_idle;
1685 
1686  if (port->default_keepalives_idle == 0)
1687  {
1688 #ifndef WIN32
1689  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_idle);
1690 
1691 #ifdef TCP_KEEPIDLE
1692  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPIDLE,
1693  (char *) &port->default_keepalives_idle,
1694  &size) < 0)
1695  {
1696  elog(LOG, "getsockopt(TCP_KEEPIDLE) failed: %m");
1697  port->default_keepalives_idle = -1; /* don't know */
1698  }
1699 #else
1700  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPALIVE,
1701  (char *) &port->default_keepalives_idle,
1702  &size) < 0)
1703  {
1704  elog(LOG, "getsockopt(TCP_KEEPALIVE) failed: %m");
1705  port->default_keepalives_idle = -1; /* don't know */
1706  }
1707 #endif /* TCP_KEEPIDLE */
1708 #else /* WIN32 */
1709  /* We can't get the defaults on Windows, so return "don't know" */
1710  port->default_keepalives_idle = -1;
1711 #endif /* WIN32 */
1712  }
1713 
1714  return port->default_keepalives_idle;
1715 #else
1716  return 0;
1717 #endif
1718 }
int keepalives_idle
Definition: libpq-be.h:163
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define LOG
Definition: elog.h:26
pgsocket sock
Definition: libpq-be.h:118
#define IS_AF_UNIX(fam)
Definition: ip.h:24
SockAddr laddr
Definition: libpq-be.h:121
int default_keepalives_idle
Definition: libpq-be.h:160
#define NULL
Definition: c.h:229
#define elog
Definition: elog.h:219
int pq_getkeepalivesinterval ( Port port)

Definition at line 1776 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_interval, elog, IS_AF_UNIX, Port::keepalives_interval, Port::laddr, LOG, NULL, and Port::sock.

Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().

1777 {
1778 #if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
1779  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1780  return 0;
1781 
1782  if (port->keepalives_interval != 0)
1783  return port->keepalives_interval;
1784 
1785  if (port->default_keepalives_interval == 0)
1786  {
1787 #ifndef WIN32
1788  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_interval);
1789 
1790  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1791  (char *) &port->default_keepalives_interval,
1792  &size) < 0)
1793  {
1794  elog(LOG, "getsockopt(TCP_KEEPINTVL) failed: %m");
1795  port->default_keepalives_interval = -1; /* don't know */
1796  }
1797 #else
1798  /* We can't get the defaults on Windows, so return "don't know" */
1799  port->default_keepalives_interval = -1;
1800 #endif /* WIN32 */
1801  }
1802 
1803  return port->default_keepalives_interval;
1804 #else
1805  return 0;
1806 #endif
1807 }
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define LOG
Definition: elog.h:26
int default_keepalives_interval
Definition: libpq-be.h:161
pgsocket sock
Definition: libpq-be.h:118
#define IS_AF_UNIX(fam)
Definition: ip.h:24
SockAddr laddr
Definition: libpq-be.h:121
#define NULL
Definition: c.h:229
#define elog
Definition: elog.h:219
int keepalives_interval
Definition: libpq-be.h:164
int pq_getmessage ( StringInfo  s,
int  maxlen 
)

Definition at line 1253 of file pqcomm.c.

References Assert, COMMERROR, StringInfoData::data, enlargeStringInfo(), ereport, errcode(), errmsg(), StringInfoData::len, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pq_discardbytes(), pq_getbytes(), PqCommReadingMsg, and resetStringInfo().

Referenced by CheckSCRAMAuth(), CopyGetData(), ProcessRepliesIfAny(), recv_password_packet(), and SocketBackend().

1254 {
1255  int32 len;
1256 
1258 
1259  resetStringInfo(s);
1260 
1261  /* Read message length word */
1262  if (pq_getbytes((char *) &len, 4) == EOF)
1263  {
1265  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1266  errmsg("unexpected EOF within message length word")));
1267  return EOF;
1268  }
1269 
1270  len = ntohl(len);
1271 
1272  if (len < 4 ||
1273  (maxlen > 0 && len > maxlen))
1274  {
1276  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1277  errmsg("invalid message length")));
1278  return EOF;
1279  }
1280 
1281  len -= 4; /* discount length itself */
1282 
1283  if (len > 0)
1284  {
1285  /*
1286  * Allocate space for message. If we run out of room (ridiculously
1287  * large message), we will elog(ERROR), but we want to discard the
1288  * message body so as not to lose communication sync.
1289  */
1290  PG_TRY();
1291  {
1292  enlargeStringInfo(s, len);
1293  }
1294  PG_CATCH();
1295  {
1296  if (pq_discardbytes(len) == EOF)
1298  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1299  errmsg("incomplete message from client")));
1300 
1301  /* we discarded the rest of the message so we're back in sync. */
1302  PqCommReadingMsg = false;
1303  PG_RE_THROW();
1304  }
1305  PG_END_TRY();
1306 
1307  /* And grab the message */
1308  if (pq_getbytes(s->data, len) == EOF)
1309  {
1311  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1312  errmsg("incomplete message from client")));
1313  return EOF;
1314  }
1315  s->len = len;
1316  /* Place a trailing null per StringInfo convention */
1317  s->data[len] = '\0';
1318  }
1319 
1320  /* finished reading the message. */
1321  PqCommReadingMsg = false;
1322 
1323  return 0;
1324 }
static int pq_discardbytes(size_t len)
Definition: pqcomm.c:1109
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:256
int pq_getbytes(char *s, size_t len)
Definition: pqcomm.c:1075
#define COMMERROR
Definition: elog.h:30
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:277
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:94
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_CATCH()
Definition: elog.h:293
#define Assert(condition)
Definition: c.h:675
#define PG_RE_THROW()
Definition: elog.h:314
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool PqCommReadingMsg
Definition: pqcomm.c:131
#define PG_TRY()
Definition: elog.h:284
#define PG_END_TRY()
Definition: elog.h:300
int pq_getstring ( StringInfo  s)

Definition at line 1147 of file pqcomm.c.

References appendBinaryStringInfo(), Assert, i, pq_recvbuf(), PqCommReadingMsg, PqRecvBuffer, PqRecvLength, PqRecvPointer, and resetStringInfo().

Referenced by GetOldFunctionMessage(), and SocketBackend().

1148 {
1149  int i;
1150 
1152 
1153  resetStringInfo(s);
1154 
1155  /* Read until we get the terminating '\0' */
1156  for (;;)
1157  {
1158  while (PqRecvPointer >= PqRecvLength)
1159  {
1160  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1161  return EOF; /* Failed to recv data */
1162  }
1163 
1164  for (i = PqRecvPointer; i < PqRecvLength; i++)
1165  {
1166  if (PqRecvBuffer[i] == '\0')
1167  {
1168  /* include the '\0' in the copy */
1170  i - PqRecvPointer + 1);
1171  PqRecvPointer = i + 1; /* advance past \0 */
1172  return 0;
1173  }
1174  }
1175 
1176  /* If we're here we haven't got the \0 in the buffer yet. */
1178  PqRecvLength - PqRecvPointer);
1180  }
1181 }
static char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
Definition: pqcomm.c:123
static int PqRecvLength
Definition: pqcomm.c:125
static int pq_recvbuf(void)
Definition: pqcomm.c:920
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:94
#define Assert(condition)
Definition: c.h:675
int i
static int PqRecvPointer
Definition: pqcomm.c:124
static bool PqCommReadingMsg
Definition: pqcomm.c:131
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:240
void pq_init ( void  )

Definition at line 175 of file pqcomm.c.

References AddWaitEventToSet(), COMMERROR, CreateWaitEventSet(), DoingCopyOut, ereport, errmsg(), MemoryContextAlloc(), MyLatch, MyProcPort, NULL, on_proc_exit(), pg_set_noblock(), PQ_SEND_BUFFER_SIZE, PqCommBusy, PqCommReadingMsg, PqRecvLength, PqRecvPointer, PqSendBuffer, PqSendBufferSize, PqSendPointer, PqSendStart, Port::sock, socket_close(), TopMemoryContext, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_SOCKET_WRITEABLE.

Referenced by BackendInitialize().

176 {
177  /* initialize state variables */
181  PqCommBusy = false;
182  PqCommReadingMsg = false;
183  DoingCopyOut = false;
184 
185  /* set up process-exit hook to close the socket */
187 
188  /*
189  * In backends (as soon as forked) we operate the underlying socket in
190  * nonblocking mode and use latches to implement blocking semantics if
191  * needed. That allows us to provide safely interruptible reads and
192  * writes.
193  *
194  * Use COMMERROR on failure, because ERROR would try to send the error to
195  * the client, which might require changing the mode again, leading to
196  * infinite recursion.
197  */
198 #ifndef WIN32
201  (errmsg("could not set socket to nonblocking mode: %m")));
202 #endif
203 
206  NULL, NULL);
209 }
#define WL_SOCKET_WRITEABLE
Definition: latch.h:126
static bool DoingCopyOut
Definition: pqcomm.c:132
struct Port * MyProcPort
Definition: globals.c:40
int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, void *user_data)
Definition: latch.c:601
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:292
static char * PqSendBuffer
Definition: pqcomm.c:118
static int PqSendStart
Definition: pqcomm.c:121
WaitEventSet * FeBeWaitSet
Definition: pqcomm.c:167
pgsocket sock
Definition: libpq-be.h:118
WaitEventSet * CreateWaitEventSet(MemoryContext context, int nevents)
Definition: latch.c:473
static int PqRecvLength
Definition: pqcomm.c:125
static int PqSendPointer
Definition: pqcomm.c:120
#define COMMERROR
Definition: elog.h:30
#define ereport(elevel, rest)
Definition: elog.h:122
MemoryContext TopMemoryContext
Definition: mcxt.c:43
static int PqSendBufferSize
Definition: pqcomm.c:119
static bool PqCommBusy
Definition: pqcomm.c:130
#define WL_POSTMASTER_DEATH
Definition: latch.h:128
#define NULL
Definition: c.h:229
bool pg_set_noblock(pgsocket sock)
Definition: noblock.c:25
static void socket_close(int code, Datum arg)
Definition: pqcomm.c:237
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:707
struct Latch * MyLatch
Definition: globals.c:51
static int PqRecvPointer
Definition: pqcomm.c:124
static bool PqCommReadingMsg
Definition: pqcomm.c:131
#define WL_LATCH_SET
Definition: latch.h:124
#define PQ_SEND_BUFFER_SIZE
Definition: pqcomm.c:115
bool pq_is_reading_msg ( void  )

Definition at line 1231 of file pqcomm.c.

References PqCommReadingMsg.

Referenced by PostgresMain().

1232 {
1233  return PqCommReadingMsg;
1234 }
static bool PqCommReadingMsg
Definition: pqcomm.c:131
int pq_peekbyte ( void  )

Definition at line 1000 of file pqcomm.c.

References Assert, pq_recvbuf(), PqCommReadingMsg, PqRecvBuffer, PqRecvLength, and PqRecvPointer.

Referenced by recv_password_packet().

1001 {
1003 
1004  while (PqRecvPointer >= PqRecvLength)
1005  {
1006  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1007  return EOF; /* Failed to recv data */
1008  }
1009  return (unsigned char) PqRecvBuffer[PqRecvPointer];
1010 }
static char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
Definition: pqcomm.c:123
static int PqRecvLength
Definition: pqcomm.c:125
static int pq_recvbuf(void)
Definition: pqcomm.c:920
#define Assert(condition)
Definition: c.h:675
static int PqRecvPointer
Definition: pqcomm.c:124
static bool PqCommReadingMsg
Definition: pqcomm.c:131
int pq_putbytes ( const char *  s,
size_t  len 
)

Definition at line 1334 of file pqcomm.c.

References Assert, DoingCopyOut, internal_putbytes(), and PqCommBusy.

Referenced by CopySendEndOfRow(), and socket_endcopyout().

1335 {
1336  int res;
1337 
1338  /* Should only be called by old-style COPY OUT */
1340  /* No-op if reentrant call */
1341  if (PqCommBusy)
1342  return 0;
1343  PqCommBusy = true;
1344  res = internal_putbytes(s, len);
1345  PqCommBusy = false;
1346  return res;
1347 }
static bool DoingCopyOut
Definition: pqcomm.c:132
static int internal_putbytes(const char *s, size_t len)
Definition: pqcomm.c:1350
static bool PqCommBusy
Definition: pqcomm.c:130
#define Assert(condition)
Definition: c.h:675
static int pq_recvbuf ( void  )
static

Definition at line 920 of file pqcomm.c.

References COMMERROR, EINTR, ereport, errcode_for_socket_access(), errmsg(), memmove, MyProcPort, PQ_RECV_BUFFER_SIZE, PqRecvBuffer, PqRecvLength, PqRecvPointer, secure_read(), and socket_set_nonblocking().

Referenced by pq_discardbytes(), pq_getbyte(), pq_getbytes(), pq_getstring(), and pq_peekbyte().

921 {
922  if (PqRecvPointer > 0)
923  {
925  {
926  /* still some unread data, left-justify it in the buffer */
930  PqRecvPointer = 0;
931  }
932  else
934  }
935 
936  /* Ensure that we're in blocking mode */
937  socket_set_nonblocking(false);
938 
939  /* Can fill buffer from PqRecvLength and upwards */
940  for (;;)
941  {
942  int r;
943 
946 
947  if (r < 0)
948  {
949  if (errno == EINTR)
950  continue; /* Ok if interrupted */
951 
952  /*
953  * Careful: an ereport() that tries to write to the client would
954  * cause recursion to here, leading to stack overflow and core
955  * dump! This message must go *only* to the postmaster log.
956  */
959  errmsg("could not receive data from client: %m")));
960  return EOF;
961  }
962  if (r == 0)
963  {
964  /*
965  * EOF detected. We used to write a log message here, but it's
966  * better to expect the ultimate caller to do that.
967  */
968  return EOF;
969  }
970  /* r contains number of bytes read, so just incr length */
971  PqRecvLength += r;
972  return 0;
973  }
974 }
static char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
Definition: pqcomm.c:123
struct Port * MyProcPort
Definition: globals.c:40
ssize_t secure_read(Port *port, void *ptr, size_t len)
Definition: be-secure.c:137
static void socket_set_nonblocking(bool nonblocking)
Definition: pqcomm.c:903
static int PqRecvLength
Definition: pqcomm.c:125
#define memmove(d, s, c)
Definition: c.h:1058
#define COMMERROR
Definition: elog.h:30
#define ereport(elevel, rest)
Definition: elog.h:122
int errcode_for_socket_access(void)
Definition: elog.c:669
#define EINTR
Definition: win32.h:285
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PQ_RECV_BUFFER_SIZE
Definition: pqcomm.c:116
static int PqRecvPointer
Definition: pqcomm.c:124
int pq_setkeepalivescount ( int  count,
Port port 
)

Definition at line 1886 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_count, elog, IS_AF_UNIX, Port::keepalives_count, Port::laddr, LOG, NULL, pq_getkeepalivescount(), Port::sock, STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_count(), and StreamConnection().

1887 {
1888  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1889  return STATUS_OK;
1890 
1891 #ifdef TCP_KEEPCNT
1892  if (count == port->keepalives_count)
1893  return STATUS_OK;
1894 
1895  if (port->default_keepalives_count <= 0)
1896  {
1897  if (pq_getkeepalivescount(port) < 0)
1898  {
1899  if (count == 0)
1900  return STATUS_OK; /* default is set but unknown */
1901  else
1902  return STATUS_ERROR;
1903  }
1904  }
1905 
1906  if (count == 0)
1907  count = port->default_keepalives_count;
1908 
1909  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1910  (char *) &count, sizeof(count)) < 0)
1911  {
1912  elog(LOG, "setsockopt(TCP_KEEPCNT) failed: %m");
1913  return STATUS_ERROR;
1914  }
1915 
1916  port->keepalives_count = count;
1917 #else
1918  if (count != 0)
1919  {
1920  elog(LOG, "setsockopt(TCP_KEEPCNT) not supported");
1921  return STATUS_ERROR;
1922  }
1923 #endif
1924 
1925  return STATUS_OK;
1926 }
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:976
#define LOG
Definition: elog.h:26
int default_keepalives_count
Definition: libpq-be.h:162
pgsocket sock
Definition: libpq-be.h:118
int keepalives_count
Definition: libpq-be.h:165
#define IS_AF_UNIX(fam)
Definition: ip.h:24
#define STATUS_OK
Definition: c.h:975
SockAddr laddr
Definition: libpq-be.h:121
#define NULL
Definition: c.h:229
int pq_getkeepalivescount(Port *port)
Definition: pqcomm.c:1857
#define elog
Definition: elog.h:219
int pq_setkeepalivesidle ( int  idle,
Port port 
)

Definition at line 1721 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_idle, elog, IS_AF_UNIX, Port::keepalives_idle, Port::keepalives_interval, Port::laddr, LOG, NULL, pq_getkeepalivesidle(), Port::sock, STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_idle(), and StreamConnection().

1722 {
1723  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1724  return STATUS_OK;
1725 
1726 #if defined(TCP_KEEPIDLE) || defined(TCP_KEEPALIVE) || defined(SIO_KEEPALIVE_VALS)
1727  if (idle == port->keepalives_idle)
1728  return STATUS_OK;
1729 
1730 #ifndef WIN32
1731  if (port->default_keepalives_idle <= 0)
1732  {
1733  if (pq_getkeepalivesidle(port) < 0)
1734  {
1735  if (idle == 0)
1736  return STATUS_OK; /* default is set but unknown */
1737  else
1738  return STATUS_ERROR;
1739  }
1740  }
1741 
1742  if (idle == 0)
1743  idle = port->default_keepalives_idle;
1744 
1745 #ifdef TCP_KEEPIDLE
1746  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPIDLE,
1747  (char *) &idle, sizeof(idle)) < 0)
1748  {
1749  elog(LOG, "setsockopt(TCP_KEEPIDLE) failed: %m");
1750  return STATUS_ERROR;
1751  }
1752 #else
1753  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPALIVE,
1754  (char *) &idle, sizeof(idle)) < 0)
1755  {
1756  elog(LOG, "setsockopt(TCP_KEEPALIVE) failed: %m");
1757  return STATUS_ERROR;
1758  }
1759 #endif
1760 
1761  port->keepalives_idle = idle;
1762 #else /* WIN32 */
1763  return pq_setkeepaliveswin32(port, idle, port->keepalives_interval);
1764 #endif
1765 #else /* TCP_KEEPIDLE || SIO_KEEPALIVE_VALS */
1766  if (idle != 0)
1767  {
1768  elog(LOG, "setting the keepalive idle time is not supported");
1769  return STATUS_ERROR;
1770  }
1771 #endif
1772  return STATUS_OK;
1773 }
int keepalives_idle
Definition: libpq-be.h:163
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:976
#define LOG
Definition: elog.h:26
pgsocket sock
Definition: libpq-be.h:118
#define IS_AF_UNIX(fam)
Definition: ip.h:24
#define STATUS_OK
Definition: c.h:975
SockAddr laddr
Definition: libpq-be.h:121
int default_keepalives_idle
Definition: libpq-be.h:160
#define NULL
Definition: c.h:229
int pq_getkeepalivesidle(Port *port)
Definition: pqcomm.c:1677
#define elog
Definition: elog.h:219
int keepalives_interval
Definition: libpq-be.h:164
int pq_setkeepalivesinterval ( int  interval,
Port port 
)

Definition at line 1810 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_interval, elog, IS_AF_UNIX, Port::keepalives_idle, Port::keepalives_interval, Port::laddr, LOG, NULL, pq_getkeepalivesinterval(), Port::sock, STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_interval(), and StreamConnection().

1811 {
1812  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1813  return STATUS_OK;
1814 
1815 #if defined(TCP_KEEPINTVL) || defined (SIO_KEEPALIVE_VALS)
1816  if (interval == port->keepalives_interval)
1817  return STATUS_OK;
1818 
1819 #ifndef WIN32
1820  if (port->default_keepalives_interval <= 0)
1821  {
1822  if (pq_getkeepalivesinterval(port) < 0)
1823  {
1824  if (interval == 0)
1825  return STATUS_OK; /* default is set but unknown */
1826  else
1827  return STATUS_ERROR;
1828  }
1829  }
1830 
1831  if (interval == 0)
1833 
1834  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1835  (char *) &interval, sizeof(interval)) < 0)
1836  {
1837  elog(LOG, "setsockopt(TCP_KEEPINTVL) failed: %m");
1838  return STATUS_ERROR;
1839  }
1840 
1841  port->keepalives_interval = interval;
1842 #else /* WIN32 */
1843  return pq_setkeepaliveswin32(port, port->keepalives_idle, interval);
1844 #endif
1845 #else
1846  if (interval != 0)
1847  {
1848  elog(LOG, "setsockopt(TCP_KEEPINTVL) not supported");
1849  return STATUS_ERROR;
1850  }
1851 #endif
1852 
1853  return STATUS_OK;
1854 }
int keepalives_idle
Definition: libpq-be.h:163
int pq_getkeepalivesinterval(Port *port)
Definition: pqcomm.c:1776
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:976
#define LOG
Definition: elog.h:26
int default_keepalives_interval
Definition: libpq-be.h:161
pgsocket sock
Definition: libpq-be.h:118
#define IS_AF_UNIX(fam)
Definition: ip.h:24
#define STATUS_OK
Definition: c.h:975
SockAddr laddr
Definition: libpq-be.h:121
#define NULL
Definition: c.h:229
#define elog
Definition: elog.h:219
int keepalives_interval
Definition: libpq-be.h:164
void pq_startmsgread ( void  )

Definition at line 1191 of file pqcomm.c.

References ereport, errcode(), errmsg(), FATAL, and PqCommReadingMsg.

Referenced by CheckSCRAMAuth(), CopyGetData(), ProcessRepliesIfAny(), ProcessStartupPacket(), ReceiveCopyBegin(), recv_password_packet(), and SocketBackend().

1192 {
1193  /*
1194  * There shouldn't be a read active already, but let's check just to be
1195  * sure.
1196  */
1197  if (PqCommReadingMsg)
1198  ereport(FATAL,
1199  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1200  errmsg("terminating connection because protocol synchronization was lost")));
1201 
1202  PqCommReadingMsg = true;
1203 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define FATAL
Definition: elog.h:52
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool PqCommReadingMsg
Definition: pqcomm.c:131
void RemoveSocketFiles ( void  )

Definition at line 870 of file pqcomm.c.

References lfirst, NIL, and unlink().

Referenced by CloseServerPorts().

871 {
872  ListCell *l;
873 
874  /* Loop through all created sockets... */
875  foreach(l, sock_paths)
876  {
877  char *sock_path = (char *) lfirst(l);
878 
879  /* Ignore any error. */
880  (void) unlink(sock_path);
881  }
882  /* Since we're about to exit, no need to reclaim storage */
883  sock_paths = NIL;
884 }
#define NIL
Definition: pg_list.h:69
static List * sock_paths
Definition: pqcomm.c:106
int unlink(const char *filename)
#define lfirst(lc)
Definition: pg_list.h:106
static void socket_close ( int  code,
Datum  arg 
)
static

Definition at line 237 of file pqcomm.c.

References free, Port::gss, MyProcPort, NULL, PGINVALID_SOCKET, secure_close(), and Port::sock.

Referenced by pq_init().

238 {
239  /* Nothing to do in a standalone backend, where MyProcPort is NULL. */
240  if (MyProcPort != NULL)
241  {
242 #if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
243 #ifdef ENABLE_GSS
244  OM_uint32 min_s;
245 
246  /*
247  * Shutdown GSSAPI layer. This section does nothing when interrupting
248  * BackendInitialize(), because pg_GSS_recvauth() makes first use of
249  * "ctx" and "cred".
250  */
251  if (MyProcPort->gss->ctx != GSS_C_NO_CONTEXT)
252  gss_delete_sec_context(&min_s, &MyProcPort->gss->ctx, NULL);
253 
254  if (MyProcPort->gss->cred != GSS_C_NO_CREDENTIAL)
255  gss_release_cred(&min_s, &MyProcPort->gss->cred);
256 #endif /* ENABLE_GSS */
257 
258  /*
259  * GSS and SSPI share the port->gss struct. Since nowhere else does a
260  * postmaster child free this, doing so is safe when interrupting
261  * BackendInitialize().
262  */
263  free(MyProcPort->gss);
264 #endif /* ENABLE_GSS || ENABLE_SSPI */
265 
266  /*
267  * Cleanly shut down SSL layer. Nowhere else does a postmaster child
268  * call this, so this is safe when interrupting BackendInitialize().
269  */
271 
272  /*
273  * Formerly we did an explicit close() here, but it seems better to
274  * leave the socket open until the process dies. This allows clients
275  * to perform a "synchronous close" if they care --- wait till the
276  * transport layer reports connection closure, and you can be sure the
277  * backend has exited.
278  *
279  * We do set sock to PGINVALID_SOCKET to prevent any further I/O,
280  * though.
281  */
283  }
284 }
struct Port * MyProcPort
Definition: globals.c:40
pgsocket sock
Definition: libpq-be.h:118
#define PGINVALID_SOCKET
Definition: port.h:24
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
void secure_close(Port *port)
Definition: be-secure.c:125
void * gss
Definition: libpq-be.h:175
static void socket_comm_reset ( void  )
static

Definition at line 220 of file pqcomm.c.

References pq_endcopyout, and PqCommBusy.

221 {
222  /* Do not throw away pending data, but do reset the busy flag */
223  PqCommBusy = false;
224  /* We can abort any old-style COPY OUT, too */
225  pq_endcopyout(true);
226 }
static bool PqCommBusy
Definition: pqcomm.c:130
#define pq_endcopyout(errorAbort)
Definition: libpq.h:47
static void socket_endcopyout ( bool  errorAbort)
static

Definition at line 1617 of file pqcomm.c.

References DoingCopyOut, and pq_putbytes().

1618 {
1619  if (!DoingCopyOut)
1620  return;
1621  if (errorAbort)
1622  pq_putbytes("\n\n\\.\n", 5);
1623  /* in non-error case, copy.c will have emitted the terminator line */
1624  DoingCopyOut = false;
1625 }
static bool DoingCopyOut
Definition: pqcomm.c:132
int pq_putbytes(const char *s, size_t len)
Definition: pqcomm.c:1334
static int socket_flush ( void  )
static

Definition at line 1381 of file pqcomm.c.

References internal_flush(), PqCommBusy, and socket_set_nonblocking().

1382 {
1383  int res;
1384 
1385  /* No-op if reentrant call */
1386  if (PqCommBusy)
1387  return 0;
1388  PqCommBusy = true;
1389  socket_set_nonblocking(false);
1390  res = internal_flush();
1391  PqCommBusy = false;
1392  return res;
1393 }
static int internal_flush(void)
Definition: pqcomm.c:1403
static void socket_set_nonblocking(bool nonblocking)
Definition: pqcomm.c:903
static bool PqCommBusy
Definition: pqcomm.c:130
static int socket_flush_if_writable ( void  )
static

Definition at line 1476 of file pqcomm.c.

References internal_flush(), PqCommBusy, PqSendPointer, PqSendStart, and socket_set_nonblocking().

1477 {
1478  int res;
1479 
1480  /* Quick exit if nothing to do */
1481  if (PqSendPointer == PqSendStart)
1482  return 0;
1483 
1484  /* No-op if reentrant call */
1485  if (PqCommBusy)
1486  return 0;
1487 
1488  /* Temporarily put the socket into non-blocking mode */
1489  socket_set_nonblocking(true);
1490 
1491  PqCommBusy = true;
1492  res = internal_flush();
1493  PqCommBusy = false;
1494  return res;
1495 }
static int PqSendStart
Definition: pqcomm.c:121
static int internal_flush(void)
Definition: pqcomm.c:1403
static void socket_set_nonblocking(bool nonblocking)
Definition: pqcomm.c:903
static int PqSendPointer
Definition: pqcomm.c:120
static bool PqCommBusy
Definition: pqcomm.c:130
static bool socket_is_send_pending ( void  )
static

Definition at line 1502 of file pqcomm.c.

References PqSendPointer, and PqSendStart.

1503 {
1504  return (PqSendStart < PqSendPointer);
1505 }
static int PqSendStart
Definition: pqcomm.c:121
static int PqSendPointer
Definition: pqcomm.c:120
static int socket_putmessage ( char  msgtype,
const char *  s,
size_t  len 
)
static

Definition at line 1541 of file pqcomm.c.

References DoingCopyOut, FrontendProtocol, internal_putbytes(), PG_PROTOCOL_MAJOR, and PqCommBusy.

1542 {
1543  if (DoingCopyOut || PqCommBusy)
1544  return 0;
1545  PqCommBusy = true;
1546  if (msgtype)
1547  if (internal_putbytes(&msgtype, 1))
1548  goto fail;
1550  {
1551  uint32 n32;
1552 
1553  n32 = htonl((uint32) (len + 4));
1554  if (internal_putbytes((char *) &n32, 4))
1555  goto fail;
1556  }
1557  if (internal_putbytes(s, len))
1558  goto fail;
1559  PqCommBusy = false;
1560  return 0;
1561 
1562 fail:
1563  PqCommBusy = false;
1564  return EOF;
1565 }
static bool DoingCopyOut
Definition: pqcomm.c:132
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
unsigned int uint32
Definition: c.h:268
static int internal_putbytes(const char *s, size_t len)
Definition: pqcomm.c:1350
static bool PqCommBusy
Definition: pqcomm.c:130
ProtocolVersion FrontendProtocol
Definition: globals.c:27
static void socket_putmessage_noblock ( char  msgtype,
const char *  s,
size_t  len 
)
static

Definition at line 1574 of file pqcomm.c.

References Assert, PG_USED_FOR_ASSERTS_ONLY, pq_putmessage, PqSendBuffer, PqSendBufferSize, PqSendPointer, and repalloc().

1575 {
1576  int res PG_USED_FOR_ASSERTS_ONLY;
1577  int required;
1578 
1579  /*
1580  * Ensure we have enough space in the output buffer for the message header
1581  * as well as the message itself.
1582  */
1583  required = PqSendPointer + 1 + 4 + len;
1584  if (required > PqSendBufferSize)
1585  {
1586  PqSendBuffer = repalloc(PqSendBuffer, required);
1587  PqSendBufferSize = required;
1588  }
1589  res = pq_putmessage(msgtype, s, len);
1590  Assert(res == 0); /* should not fail when the message fits in
1591  * buffer */
1592 }
static char * PqSendBuffer
Definition: pqcomm.c:118
static int PqSendPointer
Definition: pqcomm.c:120
static int PqSendBufferSize
Definition: pqcomm.c:119
#define Assert(condition)
Definition: c.h:675
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:963
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:42
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:990
static void socket_set_nonblocking ( bool  nonblocking)
static

Definition at line 903 of file pqcomm.c.

References ereport, errcode(), errmsg(), ERROR, MyProcPort, Port::noblock, and NULL.

Referenced by internal_putbytes(), pq_getbyte_if_available(), pq_recvbuf(), socket_flush(), and socket_flush_if_writable().

904 {
905  if (MyProcPort == NULL)
906  ereport(ERROR,
907  (errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
908  errmsg("there is no client connection")));
909 
910  MyProcPort->noblock = nonblocking;
911 }
struct Port * MyProcPort
Definition: globals.c:40
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:229
bool noblock
Definition: libpq-be.h:119
int errmsg(const char *fmt,...)
Definition: elog.c:797
static void socket_startcopyout ( void  )
static

Definition at line 1601 of file pqcomm.c.

References DoingCopyOut.

1602 {
1603  DoingCopyOut = true;
1604 }
static bool DoingCopyOut
Definition: pqcomm.c:132
void StreamClose ( pgsocket  sock)

Definition at line 825 of file pqcomm.c.

References closesocket.

Referenced by ClosePostmasterPorts(), CloseServerPorts(), ConnCreate(), and ServerLoop().

826 {
827  closesocket(sock);
828 }
#define closesocket
Definition: port.h:328
int StreamConnection ( pgsocket  server_fd,
Port port 
)

Definition at line 697 of file pqcomm.c.

References accept, SockAddr::addr, elog, ereport, errcode_for_socket_access(), errmsg(), IS_AF_UNIX, Port::laddr, LOG, pg_usleep(), PGINVALID_SOCKET, PQ_SEND_BUFFER_SIZE, pq_setkeepalivescount(), pq_setkeepalivesidle(), pq_setkeepalivesinterval(), Port::raddr, SockAddr::salen, Port::sock, STATUS_ERROR, STATUS_OK, tcp_keepalives_count, tcp_keepalives_idle, and tcp_keepalives_interval.

Referenced by ConnCreate().

698 {
699  /* accept connection and fill in the client (remote) address */
700  port->raddr.salen = sizeof(port->raddr.addr);
701  if ((port->sock = accept(server_fd,
702  (struct sockaddr *) & port->raddr.addr,
703  &port->raddr.salen)) == PGINVALID_SOCKET)
704  {
705  ereport(LOG,
707  errmsg("could not accept new connection: %m")));
708 
709  /*
710  * If accept() fails then postmaster.c will still see the server
711  * socket as read-ready, and will immediately try again. To avoid
712  * uselessly sucking lots of CPU, delay a bit before trying again.
713  * (The most likely reason for failure is being out of kernel file
714  * table slots; we can do little except hope some will get freed up.)
715  */
716  pg_usleep(100000L); /* wait 0.1 sec */
717  return STATUS_ERROR;
718  }
719 
720  /* fill in the server (local) address */
721  port->laddr.salen = sizeof(port->laddr.addr);
722  if (getsockname(port->sock,
723  (struct sockaddr *) & port->laddr.addr,
724  &port->laddr.salen) < 0)
725  {
726  elog(LOG, "getsockname() failed: %m");
727  return STATUS_ERROR;
728  }
729 
730  /* select NODELAY and KEEPALIVE options if it's a TCP connection */
731  if (!IS_AF_UNIX(port->laddr.addr.ss_family))
732  {
733  int on;
734 #ifdef WIN32
735  int oldopt;
736  int optlen;
737  int newopt;
738 #endif
739 
740 #ifdef TCP_NODELAY
741  on = 1;
742  if (setsockopt(port->sock, IPPROTO_TCP, TCP_NODELAY,
743  (char *) &on, sizeof(on)) < 0)
744  {
745  elog(LOG, "setsockopt(TCP_NODELAY) failed: %m");
746  return STATUS_ERROR;
747  }
748 #endif
749  on = 1;
750  if (setsockopt(port->sock, SOL_SOCKET, SO_KEEPALIVE,
751  (char *) &on, sizeof(on)) < 0)
752  {
753  elog(LOG, "setsockopt(SO_KEEPALIVE) failed: %m");
754  return STATUS_ERROR;
755  }
756 
757 #ifdef WIN32
758 
759  /*
760  * This is a Win32 socket optimization. The OS send buffer should be
761  * large enough to send the whole Postgres send buffer in one go, or
762  * performance suffers. The Postgres send buffer can be enlarged if a
763  * very large message needs to be sent, but we won't attempt to
764  * enlarge the OS buffer if that happens, so somewhat arbitrarily
765  * ensure that the OS buffer is at least PQ_SEND_BUFFER_SIZE * 4.
766  * (That's 32kB with the current default).
767  *
768  * The default OS buffer size used to be 8kB in earlier Windows
769  * versions, but was raised to 64kB in Windows 2012. So it shouldn't
770  * be necessary to change it in later versions anymore. Changing it
771  * unnecessarily can even reduce performance, because setting
772  * SO_SNDBUF in the application disables the "dynamic send buffering"
773  * feature that was introduced in Windows 7. So before fiddling with
774  * SO_SNDBUF, check if the current buffer size is already large enough
775  * and only increase it if necessary.
776  *
777  * See https://support.microsoft.com/kb/823764/EN-US/ and
778  * https://msdn.microsoft.com/en-us/library/bb736549%28v=vs.85%29.aspx
779  */
780  optlen = sizeof(oldopt);
781  if (getsockopt(port->sock, SOL_SOCKET, SO_SNDBUF, (char *) &oldopt,
782  &optlen) < 0)
783  {
784  elog(LOG, "getsockopt(SO_SNDBUF) failed: %m");
785  return STATUS_ERROR;
786  }
787  newopt = PQ_SEND_BUFFER_SIZE * 4;
788  if (oldopt < newopt)
789  {
790  if (setsockopt(port->sock, SOL_SOCKET, SO_SNDBUF, (char *) &newopt,
791  sizeof(newopt)) < 0)
792  {
793  elog(LOG, "setsockopt(SO_SNDBUF) failed: %m");
794  return STATUS_ERROR;
795  }
796  }
797 #endif
798 
799  /*
800  * Also apply the current keepalive parameters. If we fail to set a
801  * parameter, don't error out, because these aren't universally
802  * supported. (Note: you might think we need to reset the GUC
803  * variables to 0 in such a case, but it's not necessary because the
804  * show hooks for these variables report the truth anyway.)
805  */
809  }
810 
811  return STATUS_OK;
812 }
#define accept(s, addr, addrlen)
Definition: win32.h:372
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1810
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:976
#define LOG
Definition: elog.h:26
pgsocket sock
Definition: libpq-be.h:118
int tcp_keepalives_idle
Definition: guc.c:475
SockAddr raddr
Definition: libpq-be.h:122
void pg_usleep(long microsec)
Definition: signal.c:53
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1721
#define IS_AF_UNIX(fam)
Definition: ip.h:24
ACCEPT_TYPE_ARG3 salen
Definition: pqcomm.h:65
#define ereport(elevel, rest)
Definition: elog.h:122
#define STATUS_OK
Definition: c.h:975
int tcp_keepalives_interval
Definition: guc.c:476
int errcode_for_socket_access(void)
Definition: elog.c:669
SockAddr laddr
Definition: libpq-be.h:121
#define PGINVALID_SOCKET
Definition: port.h:24
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1886
int errmsg(const char *fmt,...)
Definition: elog.c:797
int tcp_keepalives_count
Definition: guc.c:477
#define elog
Definition: elog.h:219
#define PQ_SEND_BUFFER_SIZE
Definition: pqcomm.c:115
int StreamServerPort ( int  family,
char *  hostName,
unsigned short  portNumber,
char *  unixSocketDir,
pgsocket  ListenSocket[],
int  MaxListen 
)

Definition at line 311 of file pqcomm.c.

References _, addrinfo::ai_family, addrinfo::ai_flags, addrinfo::ai_next, AI_PASSIVE, addrinfo::ai_socktype, bind, closesocket, ereport, errcode_for_socket_access(), errhint(), errmsg(), fd(), gai_strerror, IS_AF_UNIX, listen, LOG, MaxBackends, MAXPGPATH, MemSet, NI_MAXHOST, NI_NUMERICHOST, NULL, pg_freeaddrinfo_all(), pg_getaddrinfo_all(), pg_getnameinfo_all(), PG_SOMAXCONN, PGINVALID_SOCKET, snprintf(), socket, STATUS_ERROR, STATUS_OK, UNIXSOCK_PATH, and UNIXSOCK_PATH_BUFLEN.

Referenced by PostmasterMain().

314 {
315  pgsocket fd;
316  int err;
317  int maxconn;
318  int ret;
319  char portNumberStr[32];
320  const char *familyDesc;
321  char familyDescBuf[64];
322  const char *addrDesc;
323  char addrBuf[NI_MAXHOST];
324  char *service;
325  struct addrinfo *addrs = NULL,
326  *addr;
327  struct addrinfo hint;
328  int listen_index = 0;
329  int added = 0;
330 
331 #ifdef HAVE_UNIX_SOCKETS
332  char unixSocketPath[MAXPGPATH];
333 #endif
334 #if !defined(WIN32) || defined(IPV6_V6ONLY)
335  int one = 1;
336 #endif
337 
338  /* Initialize hint structure */
339  MemSet(&hint, 0, sizeof(hint));
340  hint.ai_family = family;
341  hint.ai_flags = AI_PASSIVE;
342  hint.ai_socktype = SOCK_STREAM;
343 
344 #ifdef HAVE_UNIX_SOCKETS
345  if (family == AF_UNIX)
346  {
347  /*
348  * Create unixSocketPath from portNumber and unixSocketDir and lock
349  * that file path
350  */
351  UNIXSOCK_PATH(unixSocketPath, portNumber, unixSocketDir);
352  if (strlen(unixSocketPath) >= UNIXSOCK_PATH_BUFLEN)
353  {
354  ereport(LOG,
355  (errmsg("Unix-domain socket path \"%s\" is too long (maximum %d bytes)",
356  unixSocketPath,
357  (int) (UNIXSOCK_PATH_BUFLEN - 1))));
358  return STATUS_ERROR;
359  }
360  if (Lock_AF_UNIX(unixSocketDir, unixSocketPath) != STATUS_OK)
361  return STATUS_ERROR;
362  service = unixSocketPath;
363  }
364  else
365 #endif /* HAVE_UNIX_SOCKETS */
366  {
367  snprintf(portNumberStr, sizeof(portNumberStr), "%d", portNumber);
368  service = portNumberStr;
369  }
370 
371  ret = pg_getaddrinfo_all(hostName, service, &hint, &addrs);
372  if (ret || !addrs)
373  {
374  if (hostName)
375  ereport(LOG,
376  (errmsg("could not translate host name \"%s\", service \"%s\" to address: %s",
377  hostName, service, gai_strerror(ret))));
378  else
379  ereport(LOG,
380  (errmsg("could not translate service \"%s\" to address: %s",
381  service, gai_strerror(ret))));
382  if (addrs)
383  pg_freeaddrinfo_all(hint.ai_family, addrs);
384  return STATUS_ERROR;
385  }
386 
387  for (addr = addrs; addr; addr = addr->ai_next)
388  {
389  if (!IS_AF_UNIX(family) && IS_AF_UNIX(addr->ai_family))
390  {
391  /*
392  * Only set up a unix domain socket when they really asked for it.
393  * The service/port is different in that case.
394  */
395  continue;
396  }
397 
398  /* See if there is still room to add 1 more socket. */
399  for (; listen_index < MaxListen; listen_index++)
400  {
401  if (ListenSocket[listen_index] == PGINVALID_SOCKET)
402  break;
403  }
404  if (listen_index >= MaxListen)
405  {
406  ereport(LOG,
407  (errmsg("could not bind to all requested addresses: MAXLISTEN (%d) exceeded",
408  MaxListen)));
409  break;
410  }
411 
412  /* set up address family name for log messages */
413  switch (addr->ai_family)
414  {
415  case AF_INET:
416  familyDesc = _("IPv4");
417  break;
418 #ifdef HAVE_IPV6
419  case AF_INET6:
420  familyDesc = _("IPv6");
421  break;
422 #endif
423 #ifdef HAVE_UNIX_SOCKETS
424  case AF_UNIX:
425  familyDesc = _("Unix");
426  break;
427 #endif
428  default:
429  snprintf(familyDescBuf, sizeof(familyDescBuf),
430  _("unrecognized address family %d"),
431  addr->ai_family);
432  familyDesc = familyDescBuf;
433  break;
434  }
435 
436  /* set up text form of address for log messages */
437 #ifdef HAVE_UNIX_SOCKETS
438  if (addr->ai_family == AF_UNIX)
439  addrDesc = unixSocketPath;
440  else
441 #endif
442  {
443  pg_getnameinfo_all((const struct sockaddr_storage *) addr->ai_addr,
444  addr->ai_addrlen,
445  addrBuf, sizeof(addrBuf),
446  NULL, 0,
448  addrDesc = addrBuf;
449  }
450 
451  if ((fd = socket(addr->ai_family, SOCK_STREAM, 0)) == PGINVALID_SOCKET)
452  {
453  ereport(LOG,
455  /* translator: first %s is IPv4, IPv6, or Unix */
456  errmsg("could not create %s socket for address \"%s\": %m",
457  familyDesc, addrDesc)));
458  continue;
459  }
460 
461 #ifndef WIN32
462 
463  /*
464  * Without the SO_REUSEADDR flag, a new postmaster can't be started
465  * right away after a stop or crash, giving "address already in use"
466  * error on TCP ports.
467  *
468  * On win32, however, this behavior only happens if the
469  * SO_EXLUSIVEADDRUSE is set. With SO_REUSEADDR, win32 allows multiple
470  * servers to listen on the same address, resulting in unpredictable
471  * behavior. With no flags at all, win32 behaves as Unix with
472  * SO_REUSEADDR.
473  */
474  if (!IS_AF_UNIX(addr->ai_family))
475  {
476  if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
477  (char *) &one, sizeof(one))) == -1)
478  {
479  ereport(LOG,
481  /* translator: first %s is IPv4, IPv6, or Unix */
482  errmsg("setsockopt(SO_REUSEADDR) failed for %s address \"%s\": %m",
483  familyDesc, addrDesc)));
484  closesocket(fd);
485  continue;
486  }
487  }
488 #endif
489 
490 #ifdef IPV6_V6ONLY
491  if (addr->ai_family == AF_INET6)
492  {
493  if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
494  (char *) &one, sizeof(one)) == -1)
495  {
496  ereport(LOG,
498  /* translator: first %s is IPv4, IPv6, or Unix */
499  errmsg("setsockopt(IPV6_V6ONLY) failed for %s address \"%s\": %m",
500  familyDesc, addrDesc)));
501  closesocket(fd);
502  continue;
503  }
504  }
505 #endif
506 
507  /*
508  * Note: This might fail on some OS's, like Linux older than
509  * 2.4.21-pre3, that don't have the IPV6_V6ONLY socket option, and map
510  * ipv4 addresses to ipv6. It will show ::ffff:ipv4 for all ipv4
511  * connections.
512  */
513  err = bind(fd, addr->ai_addr, addr->ai_addrlen);
514  if (err < 0)
515  {
516  ereport(LOG,
518  /* translator: first %s is IPv4, IPv6, or Unix */
519  errmsg("could not bind %s address \"%s\": %m",
520  familyDesc, addrDesc),
521  (IS_AF_UNIX(addr->ai_family)) ?
522  errhint("Is another postmaster already running on port %d?"
523  " If not, remove socket file \"%s\" and retry.",
524  (int) portNumber, service) :
525  errhint("Is another postmaster already running on port %d?"
526  " If not, wait a few seconds and retry.",
527  (int) portNumber)));
528  closesocket(fd);
529  continue;
530  }
531 
532 #ifdef HAVE_UNIX_SOCKETS
533  if (addr->ai_family == AF_UNIX)
534  {
535  if (Setup_AF_UNIX(service) != STATUS_OK)
536  {
537  closesocket(fd);
538  break;
539  }
540  }
541 #endif
542 
543  /*
544  * Select appropriate accept-queue length limit. PG_SOMAXCONN is only
545  * intended to provide a clamp on the request on platforms where an
546  * overly large request provokes a kernel error (are there any?).
547  */
548  maxconn = MaxBackends * 2;
549  if (maxconn > PG_SOMAXCONN)
550  maxconn = PG_SOMAXCONN;
551 
552  err = listen(fd, maxconn);
553  if (err < 0)
554  {
555  ereport(LOG,
557  /* translator: first %s is IPv4, IPv6, or Unix */
558  errmsg("could not listen on %s address \"%s\": %m",
559  familyDesc, addrDesc)));
560  closesocket(fd);
561  continue;
562  }
563 
564 #ifdef HAVE_UNIX_SOCKETS
565  if (addr->ai_family == AF_UNIX)
566  ereport(LOG,
567  (errmsg("listening on Unix socket \"%s\"",
568  addrDesc)));
569  else
570 #endif
571  ereport(LOG,
572  /* translator: first %s is IPv4 or IPv6 */
573  (errmsg("listening on %s address \"%s\", port %d",
574  familyDesc, addrDesc, (int) portNumber)));
575 
576  ListenSocket[listen_index] = fd;
577  added++;
578  }
579 
580  pg_freeaddrinfo_all(hint.ai_family, addrs);
581 
582  if (!added)
583  return STATUS_ERROR;
584 
585  return STATUS_OK;
586 }
void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
Definition: ip.c:88
#define UNIXSOCK_PATH(path, port, sockdir)
Definition: pqcomm.h:70
int errhint(const char *fmt,...)
Definition: elog.c:987
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
#define UNIXSOCK_PATH_BUFLEN
Definition: pqcomm.h:86
#define closesocket
Definition: port.h:328
#define socket(af, type, protocol)
Definition: win32.h:369
#define STATUS_ERROR
Definition: c.h:976
#define MemSet(start, val, len)
Definition: c.h:857
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define LOG
Definition: elog.h:26
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define gai_strerror
Definition: getaddrinfo.h:146
int pg_getaddrinfo_all(const char *hostname, const char *servname, const struct addrinfo *hintp, struct addrinfo **result)
Definition: ip.c:57
#define NI_MAXHOST
Definition: getaddrinfo.h:88
#define bind(s, addr, addrlen)
Definition: win32.h:370
#define IS_AF_UNIX(fam)
Definition: ip.h:24
#define MAXPGPATH
int MaxBackends
Definition: globals.c:126
#define AI_PASSIVE
Definition: getaddrinfo.h:62
int pgsocket
Definition: port.h:22
#define ereport(elevel, rest)
Definition: elog.h:122
#define STATUS_OK
Definition: c.h:975
int errcode_for_socket_access(void)
Definition: elog.c:669
static pgsocket ListenSocket[MAXLISTEN]
Definition: postmaster.c:215
#define listen(s, backlog)
Definition: win32.h:371
#define PGINVALID_SOCKET
Definition: port.h:24
#define PG_SOMAXCONN
#define NULL
Definition: c.h:229
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
Definition: ip.c:122
struct addrinfo * ai_next
Definition: getaddrinfo.h:107
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define _(x)
Definition: elog.c:84
void TouchSocketFiles ( void  )

Definition at line 840 of file pqcomm.c.

References lfirst, and NULL.

Referenced by ServerLoop().

841 {
842  ListCell *l;
843 
844  /* Loop through all created sockets... */
845  foreach(l, sock_paths)
846  {
847  char *sock_path = (char *) lfirst(l);
848 
849  /*
850  * utime() is POSIX standard, utimes() is a common alternative. If we
851  * have neither, there's no way to affect the mod or access time of
852  * the socket :-(
853  *
854  * In either path, we ignore errors; there's no point in complaining.
855  */
856 #ifdef HAVE_UTIME
857  utime(sock_path, NULL);
858 #else /* !HAVE_UTIME */
859 #ifdef HAVE_UTIMES
860  utimes(sock_path, NULL);
861 #endif /* HAVE_UTIMES */
862 #endif /* HAVE_UTIME */
863  }
864 }
static List * sock_paths
Definition: pqcomm.c:106
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106

Variable Documentation

bool DoingCopyOut
static
WaitEventSet* FeBeWaitSet

Definition at line 167 of file pqcomm.c.

Referenced by secure_read(), secure_write(), SwitchBackToLocalLatch(), and SwitchToSharedLatch().

bool PqCommBusy
static

Definition at line 165 of file pqcomm.c.

Referenced by pq_redirect_to_shm_mq(), and pq_set_parallel_master().

PQcommMethods PqCommSocketMethods
static
Initial value:
= {
}
static int socket_flush_if_writable(void)
Definition: pqcomm.c:1476
static bool socket_is_send_pending(void)
Definition: pqcomm.c:1502
static void socket_comm_reset(void)
Definition: pqcomm.c:220
static void socket_startcopyout(void)
Definition: pqcomm.c:1601
static void socket_endcopyout(bool errorAbort)
Definition: pqcomm.c:1617
static int socket_putmessage(char msgtype, const char *s, size_t len)
Definition: pqcomm.c:1541
static int socket_flush(void)
Definition: pqcomm.c:1381
static void socket_putmessage_noblock(char msgtype, const char *s, size_t len)
Definition: pqcomm.c:1574

Definition at line 154 of file pqcomm.c.

char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
static
int PqRecvLength
static
int PqRecvPointer
static
char* PqSendBuffer
static

Definition at line 118 of file pqcomm.c.

Referenced by internal_flush(), internal_putbytes(), pq_init(), and socket_putmessage_noblock().

int PqSendBufferSize
static

Definition at line 119 of file pqcomm.c.

Referenced by internal_putbytes(), pq_init(), and socket_putmessage_noblock().

int PqSendStart
static
List* sock_paths = NIL
static

Definition at line 106 of file pqcomm.c.

char* Unix_socket_group

Definition at line 103 of file pqcomm.c.

int Unix_socket_permissions

Definition at line 102 of file pqcomm.c.

Referenced by show_unix_socket_permissions().