PostgreSQL Source Code  git master
pqcomm.c File Reference
#include "postgres.h"
#include <poll.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 <netinet/tcp.h>
#include <utime.h>
#include "common/ip.h"
#include "libpq/libpq.h"
#include "miscadmin.h"
#include "port/pg_bswap.h"
#include "storage/ipc.h"
#include "utils/guc_hooks.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 int internal_putbytes (const char *s, size_t len)
 
static int internal_flush (void)
 
static int Lock_AF_UNIX (const char *unixSocketDir, const char *unixSocketPath)
 
static int Setup_AF_UNIX (const char *sock_path)
 
void pq_init (void)
 
int StreamServerPort (int family, const char *hostName, unsigned short portNumber, const 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)
 
bool pq_buffer_has_data (void)
 
void pq_startmsgread (void)
 
void pq_endmsgread (void)
 
bool pq_is_reading_msg (void)
 
int pq_getmessage (StringInfo s, int maxlen)
 
int pq_putmessage_v2 (char msgtype, 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)
 
int pq_gettcpusertimeout (Port *port)
 
int pq_settcpusertimeout (int timeout, Port *port)
 
void assign_tcp_keepalives_idle (int newval, void *extra)
 
const char * show_tcp_keepalives_idle (void)
 
void assign_tcp_keepalives_interval (int newval, void *extra)
 
const char * show_tcp_keepalives_interval (void)
 
void assign_tcp_keepalives_count (int newval, void *extra)
 
const char * show_tcp_keepalives_count (void)
 
void assign_tcp_user_timeout (int newval, void *extra)
 
const char * show_tcp_user_timeout (void)
 
bool pq_check_connection (void)
 

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 const PQcommMethods PqCommSocketMethods
 
const PQcommMethodsPqCommMethods = &PqCommSocketMethods
 
WaitEventSetFeBeWaitSet
 

Macro Definition Documentation

◆ PQ_RECV_BUFFER_SIZE

#define PQ_RECV_BUFFER_SIZE   8192

Definition at line 120 of file pqcomm.c.

◆ PQ_SEND_BUFFER_SIZE

#define PQ_SEND_BUFFER_SIZE   8192

Definition at line 119 of file pqcomm.c.

Function Documentation

◆ assign_tcp_keepalives_count()

void assign_tcp_keepalives_count ( int  newval,
void *  extra 
)

Definition at line 1987 of file pqcomm.c.

1988 {
1989  /* See comments in assign_tcp_keepalives_idle */
1991 }
struct Port * MyProcPort
Definition: globals.c:47
#define newval
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1808

References MyProcPort, newval, and pq_setkeepalivescount().

◆ assign_tcp_keepalives_idle()

void assign_tcp_keepalives_idle ( int  newval,
void *  extra 
)

Definition at line 1931 of file pqcomm.c.

1932 {
1933  /*
1934  * The kernel API provides no way to test a value without setting it; and
1935  * once we set it we might fail to unset it. So there seems little point
1936  * in fully implementing the check-then-assign GUC API for these
1937  * variables. Instead we just do the assignment on demand.
1938  * pq_setkeepalivesidle reports any problems via ereport(LOG).
1939  *
1940  * This approach means that the GUC value might have little to do with the
1941  * actual kernel value, so we use a show_hook that retrieves the kernel
1942  * value rather than trusting GUC's copy.
1943  */
1945 }
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1644

References MyProcPort, newval, and pq_setkeepalivesidle().

◆ assign_tcp_keepalives_interval()

void assign_tcp_keepalives_interval ( int  newval,
void *  extra 
)

Definition at line 1964 of file pqcomm.c.

1965 {
1966  /* See comments in assign_tcp_keepalives_idle */
1968 }
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1729

References MyProcPort, newval, and pq_setkeepalivesinterval().

◆ assign_tcp_user_timeout()

void assign_tcp_user_timeout ( int  newval,
void *  extra 
)

Definition at line 2010 of file pqcomm.c.

2011 {
2012  /* See comments in assign_tcp_keepalives_idle */
2014 }
int pq_settcpusertimeout(int timeout, Port *port)
Definition: pqcomm.c:1883

References MyProcPort, newval, and pq_settcpusertimeout().

◆ internal_flush()

static int internal_flush ( void  )
static

Definition at line 1339 of file pqcomm.c.

1340 {
1341  static int last_reported_send_errno = 0;
1342 
1343  char *bufptr = PqSendBuffer + PqSendStart;
1344  char *bufend = PqSendBuffer + PqSendPointer;
1345 
1346  while (bufptr < bufend)
1347  {
1348  int r;
1349 
1350  r = secure_write(MyProcPort, bufptr, bufend - bufptr);
1351 
1352  if (r <= 0)
1353  {
1354  if (errno == EINTR)
1355  continue; /* Ok if we were interrupted */
1356 
1357  /*
1358  * Ok if no data writable without blocking, and the socket is in
1359  * non-blocking mode.
1360  */
1361  if (errno == EAGAIN ||
1362  errno == EWOULDBLOCK)
1363  {
1364  return 0;
1365  }
1366 
1367  /*
1368  * Careful: an ereport() that tries to write to the client would
1369  * cause recursion to here, leading to stack overflow and core
1370  * dump! This message must go *only* to the postmaster log.
1371  *
1372  * If a client disconnects while we're in the midst of output, we
1373  * might write quite a bit of data before we get to a safe query
1374  * abort point. So, suppress duplicate log messages.
1375  */
1376  if (errno != last_reported_send_errno)
1377  {
1378  last_reported_send_errno = errno;
1381  errmsg("could not send data to client: %m")));
1382  }
1383 
1384  /*
1385  * We drop the buffered data anyway so that processing can
1386  * continue, even though we'll probably quit soon. We also set a
1387  * flag that'll cause the next CHECK_FOR_INTERRUPTS to terminate
1388  * the connection.
1389  */
1390  PqSendStart = PqSendPointer = 0;
1392  InterruptPending = 1;
1393  return EOF;
1394  }
1395 
1396  last_reported_send_errno = 0; /* reset after any successful send */
1397  bufptr += r;
1398  PqSendStart += r;
1399  }
1400 
1401  PqSendStart = PqSendPointer = 0;
1402  return 0;
1403 }
ssize_t secure_write(Port *port, void *ptr, size_t len)
Definition: be-secure.c:258
int errcode_for_socket_access(void)
Definition: elog.c:952
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define COMMERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:149
volatile sig_atomic_t InterruptPending
Definition: globals.c:30
volatile sig_atomic_t ClientConnectionLost
Definition: globals.c:34
static int PqSendStart
Definition: pqcomm.c:125
static int PqSendPointer
Definition: pqcomm.c:124
static char * PqSendBuffer
Definition: pqcomm.c:122
#define EINTR
Definition: win32_port.h:374
#define EWOULDBLOCK
Definition: win32_port.h:380
#define EAGAIN
Definition: win32_port.h:372

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().

◆ internal_putbytes()

static int internal_putbytes ( const char *  s,
size_t  len 
)
static

Definition at line 1286 of file pqcomm.c.

1287 {
1288  size_t amount;
1289 
1290  while (len > 0)
1291  {
1292  /* If buffer is full, then flush it out */
1294  {
1295  socket_set_nonblocking(false);
1296  if (internal_flush())
1297  return EOF;
1298  }
1299  amount = PqSendBufferSize - PqSendPointer;
1300  if (amount > len)
1301  amount = len;
1302  memcpy(PqSendBuffer + PqSendPointer, s, amount);
1303  PqSendPointer += amount;
1304  s += amount;
1305  len -= amount;
1306  }
1307  return 0;
1308 }
const void size_t len
static int internal_flush(void)
Definition: pqcomm.c:1339
static void socket_set_nonblocking(bool nonblocking)
Definition: pqcomm.c:902
static int PqSendBufferSize
Definition: pqcomm.c:123

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

Referenced by pq_putmessage_v2(), and socket_putmessage().

◆ Lock_AF_UNIX()

static int Lock_AF_UNIX ( const char *  unixSocketDir,
const char *  unixSocketPath 
)
static

Definition at line 593 of file pqcomm.c.

594 {
595  /* no lock file for abstract sockets */
596  if (unixSocketPath[0] == '@')
597  return STATUS_OK;
598 
599  /*
600  * Grab an interlock file associated with the socket file.
601  *
602  * Note: there are two reasons for using a socket lock file, rather than
603  * trying to interlock directly on the socket itself. First, it's a lot
604  * more portable, and second, it lets us remove any pre-existing socket
605  * file without race conditions.
606  */
607  CreateSocketLockFile(unixSocketPath, true, unixSocketDir);
608 
609  /*
610  * Once we have the interlock, we can safely delete any pre-existing
611  * socket file to avoid failure at bind() time.
612  */
613  (void) unlink(unixSocketPath);
614 
615  /*
616  * Remember socket file pathnames for later maintenance.
617  */
618  sock_paths = lappend(sock_paths, pstrdup(unixSocketPath));
619 
620  return STATUS_OK;
621 }
#define STATUS_OK
Definition: c.h:1182
List * lappend(List *list, void *datum)
Definition: list.c:338
char * pstrdup(const char *in)
Definition: mcxt.c:1644
void CreateSocketLockFile(const char *socketfile, bool amPostmaster, const char *socketDir)
Definition: miscinit.c:1450
static List * sock_paths
Definition: pqcomm.c:110

References CreateSocketLockFile(), lappend(), pstrdup(), sock_paths, and STATUS_OK.

Referenced by StreamServerPort().

◆ pq_buffer_has_data()

bool pq_buffer_has_data ( void  )

Definition at line 1137 of file pqcomm.c.

1138 {
1139  return (PqRecvPointer < PqRecvLength);
1140 }
static int PqRecvLength
Definition: pqcomm.c:129
static int PqRecvPointer
Definition: pqcomm.c:128

References PqRecvLength, and PqRecvPointer.

Referenced by ProcessStartupPacket().

◆ pq_check_connection()

bool pq_check_connection ( void  )

Definition at line 2033 of file pqcomm.c.

2034 {
2035  WaitEvent events[FeBeWaitSetNEvents];
2036  int rc;
2037 
2038  /*
2039  * It's OK to modify the socket event filter without restoring, because
2040  * all FeBeWaitSet socket wait sites do the same.
2041  */
2043 
2044 retry:
2045  rc = WaitEventSetWait(FeBeWaitSet, 0, events, lengthof(events), 0);
2046  for (int i = 0; i < rc; ++i)
2047  {
2048  if (events[i].events & WL_SOCKET_CLOSED)
2049  return false;
2050  if (events[i].events & WL_LATCH_SET)
2051  {
2052  /*
2053  * A latch event might be preventing other events from being
2054  * reported. Reset it and poll again. No need to restore it
2055  * because no code should expect latches to survive across
2056  * CHECK_FOR_INTERRUPTS().
2057  */
2059  goto retry;
2060  }
2061  }
2062 
2063  return true;
2064 }
#define lengthof(array)
Definition: c.h:777
struct Latch * MyLatch
Definition: globals.c:58
int i
Definition: isn.c:73
void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch)
Definition: latch.c:1006
int WaitEventSetWait(WaitEventSet *set, long timeout, WaitEvent *occurred_events, int nevents, uint32 wait_event_info)
Definition: latch.c:1381
void ResetLatch(Latch *latch)
Definition: latch.c:697
#define WL_SOCKET_CLOSED
Definition: latch.h:137
#define WL_LATCH_SET
Definition: latch.h:125
#define FeBeWaitSetNEvents
Definition: libpq.h:65
#define FeBeWaitSetSocketPos
Definition: libpq.h:63
WaitEventSet * FeBeWaitSet
Definition: pqcomm.c:164

References FeBeWaitSet, FeBeWaitSetNEvents, FeBeWaitSetSocketPos, i, lengthof, ModifyWaitEvent(), MyLatch, ResetLatch(), WaitEventSetWait(), WL_LATCH_SET, and WL_SOCKET_CLOSED.

Referenced by ProcessInterrupts().

◆ pq_discardbytes()

static int pq_discardbytes ( size_t  len)
static

Definition at line 1108 of file pqcomm.c.

1109 {
1110  size_t amount;
1111 
1113 
1114  while (len > 0)
1115  {
1116  while (PqRecvPointer >= PqRecvLength)
1117  {
1118  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1119  return EOF; /* Failed to recv data */
1120  }
1121  amount = PqRecvLength - PqRecvPointer;
1122  if (amount > len)
1123  amount = len;
1124  PqRecvPointer += amount;
1125  len -= amount;
1126  }
1127  return 0;
1128 }
Assert(fmt[strlen(fmt) - 1] !='\n')
static int pq_recvbuf(void)
Definition: pqcomm.c:919
static bool PqCommReadingMsg
Definition: pqcomm.c:135

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

Referenced by pq_getmessage().

◆ pq_endmsgread()

void pq_endmsgread ( void  )

Definition at line 1174 of file pqcomm.c.

1175 {
1177 
1178  PqCommReadingMsg = false;
1179 }

References Assert(), and PqCommReadingMsg.

Referenced by ProcessRepliesIfAny(), and ProcessStartupPacket().

◆ pq_getbyte()

int pq_getbyte ( void  )

Definition at line 980 of file pqcomm.c.

981 {
983 
984  while (PqRecvPointer >= PqRecvLength)
985  {
986  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
987  return EOF; /* Failed to recv data */
988  }
989  return (unsigned char) PqRecvBuffer[PqRecvPointer++];
990 }
static char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
Definition: pqcomm.c:127

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

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

◆ pq_getbyte_if_available()

int pq_getbyte_if_available ( unsigned char *  c)

Definition at line 1020 of file pqcomm.c.

1021 {
1022  int r;
1023 
1025 
1027  {
1029  return 1;
1030  }
1031 
1032  /* Put the socket into non-blocking mode */
1033  socket_set_nonblocking(true);
1034 
1035  r = secure_read(MyProcPort, c, 1);
1036  if (r < 0)
1037  {
1038  /*
1039  * Ok if no data available without blocking or interrupted (though
1040  * EINTR really shouldn't happen with a non-blocking socket). Report
1041  * other errors.
1042  */
1043  if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
1044  r = 0;
1045  else
1046  {
1047  /*
1048  * Careful: an ereport() that tries to write to the client would
1049  * cause recursion to here, leading to stack overflow and core
1050  * dump! This message must go *only* to the postmaster log.
1051  */
1054  errmsg("could not receive data from client: %m")));
1055  r = EOF;
1056  }
1057  }
1058  else if (r == 0)
1059  {
1060  /* EOF detected */
1061  r = EOF;
1062  }
1063 
1064  return r;
1065 }
ssize_t secure_read(Port *port, void *ptr, size_t len)
Definition: be-secure.c:145
char * 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().

◆ pq_getbytes()

int pq_getbytes ( char *  s,
size_t  len 
)

Definition at line 1074 of file pqcomm.c.

1075 {
1076  size_t amount;
1077 
1079 
1080  while (len > 0)
1081  {
1082  while (PqRecvPointer >= PqRecvLength)
1083  {
1084  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1085  return EOF; /* Failed to recv data */
1086  }
1087  amount = PqRecvLength - PqRecvPointer;
1088  if (amount > len)
1089  amount = len;
1090  memcpy(s, PqRecvBuffer + PqRecvPointer, amount);
1091  PqRecvPointer += amount;
1092  s += amount;
1093  len -= amount;
1094  }
1095  return 0;
1096 }

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

Referenced by pq_getmessage(), and ProcessStartupPacket().

◆ pq_getkeepalivescount()

int pq_getkeepalivescount ( Port port)

Definition at line 1778 of file pqcomm.c.

1779 {
1780 #ifdef TCP_KEEPCNT
1781  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1782  return 0;
1783 
1784  if (port->keepalives_count != 0)
1785  return port->keepalives_count;
1786 
1787  if (port->default_keepalives_count == 0)
1788  {
1789  socklen_t size = sizeof(port->default_keepalives_count);
1790 
1791  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1792  (char *) &port->default_keepalives_count,
1793  &size) < 0)
1794  {
1795  ereport(LOG,
1796  (errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPCNT")));
1797  port->default_keepalives_count = -1; /* don't know */
1798  }
1799  }
1800 
1801  return port->default_keepalives_count;
1802 #else
1803  return 0;
1804 #endif
1805 }
#define LOG
Definition: elog.h:31
static int port
Definition: pg_regress.c:109
unsigned int socklen_t
Definition: port.h:40

References ereport, errmsg(), LOG, and port.

Referenced by pq_setkeepalivescount(), and show_tcp_keepalives_count().

◆ pq_getkeepalivesidle()

int pq_getkeepalivesidle ( Port port)

Definition at line 1609 of file pqcomm.c.

1610 {
1611 #if defined(PG_TCP_KEEPALIVE_IDLE) || defined(SIO_KEEPALIVE_VALS)
1612  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1613  return 0;
1614 
1615  if (port->keepalives_idle != 0)
1616  return port->keepalives_idle;
1617 
1618  if (port->default_keepalives_idle == 0)
1619  {
1620 #ifndef WIN32
1621  socklen_t size = sizeof(port->default_keepalives_idle);
1622 
1623  if (getsockopt(port->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
1624  (char *) &port->default_keepalives_idle,
1625  &size) < 0)
1626  {
1627  ereport(LOG,
1628  (errmsg("%s(%s) failed: %m", "getsockopt", PG_TCP_KEEPALIVE_IDLE_STR)));
1629  port->default_keepalives_idle = -1; /* don't know */
1630  }
1631 #else /* WIN32 */
1632  /* We can't get the defaults on Windows, so return "don't know" */
1633  port->default_keepalives_idle = -1;
1634 #endif /* WIN32 */
1635  }
1636 
1637  return port->default_keepalives_idle;
1638 #else
1639  return 0;
1640 #endif
1641 }

References ereport, errmsg(), LOG, and port.

Referenced by pq_setkeepalivesidle(), and show_tcp_keepalives_idle().

◆ pq_getkeepalivesinterval()

int pq_getkeepalivesinterval ( Port port)

Definition at line 1694 of file pqcomm.c.

1695 {
1696 #if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
1697  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1698  return 0;
1699 
1700  if (port->keepalives_interval != 0)
1701  return port->keepalives_interval;
1702 
1703  if (port->default_keepalives_interval == 0)
1704  {
1705 #ifndef WIN32
1706  socklen_t size = sizeof(port->default_keepalives_interval);
1707 
1708  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1709  (char *) &port->default_keepalives_interval,
1710  &size) < 0)
1711  {
1712  ereport(LOG,
1713  (errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPINTVL")));
1714  port->default_keepalives_interval = -1; /* don't know */
1715  }
1716 #else
1717  /* We can't get the defaults on Windows, so return "don't know" */
1718  port->default_keepalives_interval = -1;
1719 #endif /* WIN32 */
1720  }
1721 
1722  return port->default_keepalives_interval;
1723 #else
1724  return 0;
1725 #endif
1726 }

References ereport, errmsg(), LOG, and port.

Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().

◆ pq_getmessage()

int pq_getmessage ( StringInfo  s,
int  maxlen 
)

Definition at line 1212 of file pqcomm.c.

1213 {
1214  int32 len;
1215 
1217 
1218  resetStringInfo(s);
1219 
1220  /* Read message length word */
1221  if (pq_getbytes((char *) &len, 4) == EOF)
1222  {
1224  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1225  errmsg("unexpected EOF within message length word")));
1226  return EOF;
1227  }
1228 
1229  len = pg_ntoh32(len);
1230 
1231  if (len < 4 || len > maxlen)
1232  {
1234  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1235  errmsg("invalid message length")));
1236  return EOF;
1237  }
1238 
1239  len -= 4; /* discount length itself */
1240 
1241  if (len > 0)
1242  {
1243  /*
1244  * Allocate space for message. If we run out of room (ridiculously
1245  * large message), we will elog(ERROR), but we want to discard the
1246  * message body so as not to lose communication sync.
1247  */
1248  PG_TRY();
1249  {
1250  enlargeStringInfo(s, len);
1251  }
1252  PG_CATCH();
1253  {
1254  if (pq_discardbytes(len) == EOF)
1256  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1257  errmsg("incomplete message from client")));
1258 
1259  /* we discarded the rest of the message so we're back in sync. */
1260  PqCommReadingMsg = false;
1261  PG_RE_THROW();
1262  }
1263  PG_END_TRY();
1264 
1265  /* And grab the message */
1266  if (pq_getbytes(s->data, len) == EOF)
1267  {
1269  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1270  errmsg("incomplete message from client")));
1271  return EOF;
1272  }
1273  s->len = len;
1274  /* Place a trailing null per StringInfo convention */
1275  s->data[len] = '\0';
1276  }
1277 
1278  /* finished reading the message. */
1279  PqCommReadingMsg = false;
1280 
1281  return 0;
1282 }
signed int int32
Definition: c.h:483
int errcode(int sqlerrcode)
Definition: elog.c:858
#define PG_RE_THROW()
Definition: elog.h:411
#define PG_TRY(...)
Definition: elog.h:370
#define PG_END_TRY(...)
Definition: elog.h:395
#define PG_CATCH(...)
Definition: elog.h:380
#define pg_ntoh32(x)
Definition: pg_bswap.h:125
static int pq_discardbytes(size_t len)
Definition: pqcomm.c:1108
int pq_getbytes(char *s, size_t len)
Definition: pqcomm.c:1074
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:75
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:283

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

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

◆ pq_gettcpusertimeout()

int pq_gettcpusertimeout ( Port port)

Definition at line 1853 of file pqcomm.c.

1854 {
1855 #ifdef TCP_USER_TIMEOUT
1856  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1857  return 0;
1858 
1859  if (port->tcp_user_timeout != 0)
1860  return port->tcp_user_timeout;
1861 
1862  if (port->default_tcp_user_timeout == 0)
1863  {
1864  socklen_t size = sizeof(port->default_tcp_user_timeout);
1865 
1866  if (getsockopt(port->sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
1867  (char *) &port->default_tcp_user_timeout,
1868  &size) < 0)
1869  {
1870  ereport(LOG,
1871  (errmsg("%s(%s) failed: %m", "getsockopt", "TCP_USER_TIMEOUT")));
1872  port->default_tcp_user_timeout = -1; /* don't know */
1873  }
1874  }
1875 
1876  return port->default_tcp_user_timeout;
1877 #else
1878  return 0;
1879 #endif
1880 }

References ereport, errmsg(), LOG, and port.

Referenced by pq_settcpusertimeout(), and show_tcp_user_timeout().

◆ pq_init()

void pq_init ( void  )

Definition at line 172 of file pqcomm.c.

173 {
174  int socket_pos PG_USED_FOR_ASSERTS_ONLY;
175  int latch_pos PG_USED_FOR_ASSERTS_ONLY;
176 
177  /* initialize state variables */
181  PqCommBusy = false;
182  PqCommReadingMsg = false;
183 
184  /* set up process-exit hook to close the socket */
186 
187  /*
188  * In backends (as soon as forked) we operate the underlying socket in
189  * nonblocking mode and use latches to implement blocking semantics if
190  * needed. That allows us to provide safely interruptible reads and
191  * writes.
192  *
193  * Use COMMERROR on failure, because ERROR would try to send the error to
194  * the client, which might require changing the mode again, leading to
195  * infinite recursion.
196  */
197 #ifndef WIN32
200  (errmsg("could not set socket to nonblocking mode: %m")));
201 #endif
202 
203 #ifndef WIN32
204 
205  /* Don't give the socket to any subprograms we execute. */
206  if (fcntl(MyProcPort->sock, F_SETFD, FD_CLOEXEC) < 0)
207  elog(FATAL, "fcntl(F_SETFD) failed on socket: %m");
208 #endif
209 
212  MyProcPort->sock, NULL, NULL);
214  MyLatch, NULL);
216  NULL, NULL);
217 
218  /*
219  * The event positions match the order we added them, but let's sanity
220  * check them to be sure.
221  */
222  Assert(socket_pos == FeBeWaitSetSocketPos);
223  Assert(latch_pos == FeBeWaitSetLatchPos);
224 }
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:171
#define FATAL
Definition: elog.h:41
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:305
WaitEventSet * CreateWaitEventSet(MemoryContext context, int nevents)
Definition: latch.c:721
int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, void *user_data)
Definition: latch.c:920
#define WL_POSTMASTER_DEATH
Definition: latch.h:129
#define WL_SOCKET_WRITEABLE
Definition: latch.h:127
#define FeBeWaitSetLatchPos
Definition: libpq.h:64
MemoryContext TopMemoryContext
Definition: mcxt.c:141
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1021
bool pg_set_noblock(pgsocket sock)
Definition: noblock.c:25
#define PGINVALID_SOCKET
Definition: port.h:31
#define PQ_SEND_BUFFER_SIZE
Definition: pqcomm.c:119
static bool PqCommBusy
Definition: pqcomm.c:134
static void socket_close(int code, Datum arg)
Definition: pqcomm.c:250
pgsocket sock
Definition: libpq-be.h:148

References AddWaitEventToSet(), Assert(), COMMERROR, CreateWaitEventSet(), elog(), ereport, errmsg(), FATAL, FeBeWaitSet, FeBeWaitSetLatchPos, FeBeWaitSetNEvents, FeBeWaitSetSocketPos, MemoryContextAlloc(), MyLatch, MyProcPort, on_proc_exit(), pg_set_noblock(), PG_USED_FOR_ASSERTS_ONLY, PGINVALID_SOCKET, 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().

◆ pq_is_reading_msg()

bool pq_is_reading_msg ( void  )

Definition at line 1190 of file pqcomm.c.

1191 {
1192  return PqCommReadingMsg;
1193 }

References PqCommReadingMsg.

Referenced by PostgresMain().

◆ pq_peekbyte()

int pq_peekbyte ( void  )

Definition at line 999 of file pqcomm.c.

1000 {
1002 
1003  while (PqRecvPointer >= PqRecvLength)
1004  {
1005  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1006  return EOF; /* Failed to recv data */
1007  }
1008  return (unsigned char) PqRecvBuffer[PqRecvPointer];
1009 }

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

◆ pq_putmessage_v2()

int pq_putmessage_v2 ( char  msgtype,
const char *  s,
size_t  len 
)

Definition at line 1538 of file pqcomm.c.

1539 {
1540  Assert(msgtype != 0);
1541 
1542  if (PqCommBusy)
1543  return 0;
1544  PqCommBusy = true;
1545  if (internal_putbytes(&msgtype, 1))
1546  goto fail;
1547 
1548  if (internal_putbytes(s, len))
1549  goto fail;
1550  PqCommBusy = false;
1551  return 0;
1552 
1553 fail:
1554  PqCommBusy = false;
1555  return EOF;
1556 }
static int internal_putbytes(const char *s, size_t len)
Definition: pqcomm.c:1286

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

Referenced by send_message_to_frontend().

◆ pq_recvbuf()

static int pq_recvbuf ( void  )
static

Definition at line 919 of file pqcomm.c.

920 {
921  if (PqRecvPointer > 0)
922  {
924  {
925  /* still some unread data, left-justify it in the buffer */
929  PqRecvPointer = 0;
930  }
931  else
933  }
934 
935  /* Ensure that we're in blocking mode */
936  socket_set_nonblocking(false);
937 
938  /* Can fill buffer from PqRecvLength and upwards */
939  for (;;)
940  {
941  int r;
942 
945 
946  if (r < 0)
947  {
948  if (errno == EINTR)
949  continue; /* Ok if interrupted */
950 
951  /*
952  * Careful: an ereport() that tries to write to the client would
953  * cause recursion to here, leading to stack overflow and core
954  * dump! This message must go *only* to the postmaster log.
955  */
958  errmsg("could not receive data from client: %m")));
959  return EOF;
960  }
961  if (r == 0)
962  {
963  /*
964  * EOF detected. We used to write a log message here, but it's
965  * better to expect the ultimate caller to do that.
966  */
967  return EOF;
968  }
969  /* r contains number of bytes read, so just incr length */
970  PqRecvLength += r;
971  return 0;
972  }
973 }
#define PQ_RECV_BUFFER_SIZE
Definition: pqcomm.c:120

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

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

◆ pq_setkeepalivescount()

int pq_setkeepalivescount ( int  count,
Port port 
)

Definition at line 1808 of file pqcomm.c.

1809 {
1810  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1811  return STATUS_OK;
1812 
1813 #ifdef TCP_KEEPCNT
1814  if (count == port->keepalives_count)
1815  return STATUS_OK;
1816 
1817  if (port->default_keepalives_count <= 0)
1818  {
1819  if (pq_getkeepalivescount(port) < 0)
1820  {
1821  if (count == 0)
1822  return STATUS_OK; /* default is set but unknown */
1823  else
1824  return STATUS_ERROR;
1825  }
1826  }
1827 
1828  if (count == 0)
1829  count = port->default_keepalives_count;
1830 
1831  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1832  (char *) &count, sizeof(count)) < 0)
1833  {
1834  ereport(LOG,
1835  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_KEEPCNT")));
1836  return STATUS_ERROR;
1837  }
1838 
1839  port->keepalives_count = count;
1840 #else
1841  if (count != 0)
1842  {
1843  ereport(LOG,
1844  (errmsg("%s(%s) not supported", "setsockopt", "TCP_KEEPCNT")));
1845  return STATUS_ERROR;
1846  }
1847 #endif
1848 
1849  return STATUS_OK;
1850 }
#define STATUS_ERROR
Definition: c.h:1183
int pq_getkeepalivescount(Port *port)
Definition: pqcomm.c:1778

References ereport, errmsg(), LOG, port, pq_getkeepalivescount(), STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_count(), and StreamConnection().

◆ pq_setkeepalivesidle()

int pq_setkeepalivesidle ( int  idle,
Port port 
)

Definition at line 1644 of file pqcomm.c.

1645 {
1646  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1647  return STATUS_OK;
1648 
1649 /* check SIO_KEEPALIVE_VALS here, not just WIN32, as some toolchains lack it */
1650 #if defined(PG_TCP_KEEPALIVE_IDLE) || defined(SIO_KEEPALIVE_VALS)
1651  if (idle == port->keepalives_idle)
1652  return STATUS_OK;
1653 
1654 #ifndef WIN32
1655  if (port->default_keepalives_idle <= 0)
1656  {
1657  if (pq_getkeepalivesidle(port) < 0)
1658  {
1659  if (idle == 0)
1660  return STATUS_OK; /* default is set but unknown */
1661  else
1662  return STATUS_ERROR;
1663  }
1664  }
1665 
1666  if (idle == 0)
1667  idle = port->default_keepalives_idle;
1668 
1669  if (setsockopt(port->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
1670  (char *) &idle, sizeof(idle)) < 0)
1671  {
1672  ereport(LOG,
1673  (errmsg("%s(%s) failed: %m", "setsockopt", PG_TCP_KEEPALIVE_IDLE_STR)));
1674  return STATUS_ERROR;
1675  }
1676 
1677  port->keepalives_idle = idle;
1678 #else /* WIN32 */
1679  return pq_setkeepaliveswin32(port, idle, port->keepalives_interval);
1680 #endif
1681 #else
1682  if (idle != 0)
1683  {
1684  ereport(LOG,
1685  (errmsg("setting the keepalive idle time is not supported")));
1686  return STATUS_ERROR;
1687  }
1688 #endif
1689 
1690  return STATUS_OK;
1691 }
int pq_getkeepalivesidle(Port *port)
Definition: pqcomm.c:1609

References ereport, errmsg(), LOG, port, pq_getkeepalivesidle(), STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_idle(), and StreamConnection().

◆ pq_setkeepalivesinterval()

int pq_setkeepalivesinterval ( int  interval,
Port port 
)

Definition at line 1729 of file pqcomm.c.

1730 {
1731  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1732  return STATUS_OK;
1733 
1734 #if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
1735  if (interval == port->keepalives_interval)
1736  return STATUS_OK;
1737 
1738 #ifndef WIN32
1739  if (port->default_keepalives_interval <= 0)
1740  {
1741  if (pq_getkeepalivesinterval(port) < 0)
1742  {
1743  if (interval == 0)
1744  return STATUS_OK; /* default is set but unknown */
1745  else
1746  return STATUS_ERROR;
1747  }
1748  }
1749 
1750  if (interval == 0)
1751  interval = port->default_keepalives_interval;
1752 
1753  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1754  (char *) &interval, sizeof(interval)) < 0)
1755  {
1756  ereport(LOG,
1757  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_KEEPINTVL")));
1758  return STATUS_ERROR;
1759  }
1760 
1761  port->keepalives_interval = interval;
1762 #else /* WIN32 */
1763  return pq_setkeepaliveswin32(port, port->keepalives_idle, interval);
1764 #endif
1765 #else
1766  if (interval != 0)
1767  {
1768  ereport(LOG,
1769  (errmsg("%s(%s) not supported", "setsockopt", "TCP_KEEPINTVL")));
1770  return STATUS_ERROR;
1771  }
1772 #endif
1773 
1774  return STATUS_OK;
1775 }
int pq_getkeepalivesinterval(Port *port)
Definition: pqcomm.c:1694

References ereport, errmsg(), LOG, port, pq_getkeepalivesinterval(), STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_interval(), and StreamConnection().

◆ pq_settcpusertimeout()

int pq_settcpusertimeout ( int  timeout,
Port port 
)

Definition at line 1883 of file pqcomm.c.

1884 {
1885  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1886  return STATUS_OK;
1887 
1888 #ifdef TCP_USER_TIMEOUT
1889  if (timeout == port->tcp_user_timeout)
1890  return STATUS_OK;
1891 
1892  if (port->default_tcp_user_timeout <= 0)
1893  {
1894  if (pq_gettcpusertimeout(port) < 0)
1895  {
1896  if (timeout == 0)
1897  return STATUS_OK; /* default is set but unknown */
1898  else
1899  return STATUS_ERROR;
1900  }
1901  }
1902 
1903  if (timeout == 0)
1904  timeout = port->default_tcp_user_timeout;
1905 
1906  if (setsockopt(port->sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
1907  (char *) &timeout, sizeof(timeout)) < 0)
1908  {
1909  ereport(LOG,
1910  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_USER_TIMEOUT")));
1911  return STATUS_ERROR;
1912  }
1913 
1914  port->tcp_user_timeout = timeout;
1915 #else
1916  if (timeout != 0)
1917  {
1918  ereport(LOG,
1919  (errmsg("%s(%s) not supported", "setsockopt", "TCP_USER_TIMEOUT")));
1920  return STATUS_ERROR;
1921  }
1922 #endif
1923 
1924  return STATUS_OK;
1925 }
int pq_gettcpusertimeout(Port *port)
Definition: pqcomm.c:1853

References ereport, errmsg(), LOG, port, pq_gettcpusertimeout(), STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_user_timeout(), and StreamConnection().

◆ pq_startmsgread()

void pq_startmsgread ( void  )

Definition at line 1150 of file pqcomm.c.

1151 {
1152  /*
1153  * There shouldn't be a read active already, but let's check just to be
1154  * sure.
1155  */
1156  if (PqCommReadingMsg)
1157  ereport(FATAL,
1158  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1159  errmsg("terminating connection because protocol synchronization was lost")));
1160 
1161  PqCommReadingMsg = true;
1162 }

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

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

◆ RemoveSocketFiles()

void RemoveSocketFiles ( void  )

Definition at line 869 of file pqcomm.c.

870 {
871  ListCell *l;
872 
873  /* Loop through all created sockets... */
874  foreach(l, sock_paths)
875  {
876  char *sock_path = (char *) lfirst(l);
877 
878  /* Ignore any error. */
879  (void) unlink(sock_path);
880  }
881  /* Since we're about to exit, no need to reclaim storage */
882  sock_paths = NIL;
883 }
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68

References lfirst, NIL, and sock_paths.

Referenced by CloseServerPorts().

◆ Setup_AF_UNIX()

static int Setup_AF_UNIX ( const char *  sock_path)
static

Definition at line 628 of file pqcomm.c.

629 {
630  /* no file system permissions for abstract sockets */
631  if (sock_path[0] == '@')
632  return STATUS_OK;
633 
634  /*
635  * Fix socket ownership/permission if requested. Note we must do this
636  * before we listen() to avoid a window where unwanted connections could
637  * get accepted.
638  */
640  if (Unix_socket_group[0] != '\0')
641  {
642 #ifdef WIN32
643  elog(WARNING, "configuration item unix_socket_group is not supported on this platform");
644 #else
645  char *endptr;
646  unsigned long val;
647  gid_t gid;
648 
649  val = strtoul(Unix_socket_group, &endptr, 10);
650  if (*endptr == '\0')
651  { /* numeric group id */
652  gid = val;
653  }
654  else
655  { /* convert group name to id */
656  struct group *gr;
657 
658  gr = getgrnam(Unix_socket_group);
659  if (!gr)
660  {
661  ereport(LOG,
662  (errmsg("group \"%s\" does not exist",
664  return STATUS_ERROR;
665  }
666  gid = gr->gr_gid;
667  }
668  if (chown(sock_path, -1, gid) == -1)
669  {
670  ereport(LOG,
672  errmsg("could not set group of file \"%s\": %m",
673  sock_path)));
674  return STATUS_ERROR;
675  }
676 #endif
677  }
678 
679  if (chmod(sock_path, Unix_socket_permissions) == -1)
680  {
681  ereport(LOG,
683  errmsg("could not set permissions of file \"%s\": %m",
684  sock_path)));
685  return STATUS_ERROR;
686  }
687  return STATUS_OK;
688 }
int errcode_for_file_access(void)
Definition: elog.c:881
#define WARNING
Definition: elog.h:36
long val
Definition: informix.c:664
int Unix_socket_permissions
Definition: pqcomm.c:106
char * Unix_socket_group
Definition: pqcomm.c:107
int gid_t
Definition: win32_port.h:245

References Assert(), elog(), ereport, errcode_for_file_access(), errmsg(), LOG, STATUS_ERROR, STATUS_OK, Unix_socket_group, Unix_socket_permissions, val, and WARNING.

Referenced by StreamServerPort().

◆ show_tcp_keepalives_count()

const char* show_tcp_keepalives_count ( void  )

Definition at line 1997 of file pqcomm.c.

1998 {
1999  /* See comments in assign_tcp_keepalives_idle */
2000  static char nbuf[16];
2001 
2002  snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
2003  return nbuf;
2004 }
#define snprintf
Definition: port.h:238

References MyProcPort, pq_getkeepalivescount(), and snprintf.

◆ show_tcp_keepalives_idle()

const char* show_tcp_keepalives_idle ( void  )

Definition at line 1951 of file pqcomm.c.

1952 {
1953  /* See comments in assign_tcp_keepalives_idle */
1954  static char nbuf[16];
1955 
1956  snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
1957  return nbuf;
1958 }

References MyProcPort, pq_getkeepalivesidle(), and snprintf.

◆ show_tcp_keepalives_interval()

const char* show_tcp_keepalives_interval ( void  )

Definition at line 1974 of file pqcomm.c.

1975 {
1976  /* See comments in assign_tcp_keepalives_idle */
1977  static char nbuf[16];
1978 
1979  snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
1980  return nbuf;
1981 }

References MyProcPort, pq_getkeepalivesinterval(), and snprintf.

◆ show_tcp_user_timeout()

const char* show_tcp_user_timeout ( void  )

Definition at line 2020 of file pqcomm.c.

2021 {
2022  /* See comments in assign_tcp_keepalives_idle */
2023  static char nbuf[16];
2024 
2025  snprintf(nbuf, sizeof(nbuf), "%d", pq_gettcpusertimeout(MyProcPort));
2026  return nbuf;
2027 }

References MyProcPort, pq_gettcpusertimeout(), and snprintf.

◆ socket_close()

static void socket_close ( int  code,
Datum  arg 
)
static

Definition at line 250 of file pqcomm.c.

251 {
252  /* Nothing to do in a standalone backend, where MyProcPort is NULL. */
253  if (MyProcPort != NULL)
254  {
255 #ifdef ENABLE_GSS
256  /*
257  * Shutdown GSSAPI layer. This section does nothing when interrupting
258  * BackendInitialize(), because pg_GSS_recvauth() makes first use of
259  * "ctx" and "cred".
260  *
261  * Note that we don't bother to free MyProcPort->gss, since we're
262  * about to exit anyway.
263  */
264  if (MyProcPort->gss)
265  {
266  OM_uint32 min_s;
267 
268  if (MyProcPort->gss->ctx != GSS_C_NO_CONTEXT)
269  gss_delete_sec_context(&min_s, &MyProcPort->gss->ctx, NULL);
270 
271  if (MyProcPort->gss->cred != GSS_C_NO_CREDENTIAL)
272  gss_release_cred(&min_s, &MyProcPort->gss->cred);
273  }
274 #endif /* ENABLE_GSS */
275 
276  /*
277  * Cleanly shut down SSL layer. Nowhere else does a postmaster child
278  * call this, so this is safe when interrupting BackendInitialize().
279  */
281 
282  /*
283  * Formerly we did an explicit close() here, but it seems better to
284  * leave the socket open until the process dies. This allows clients
285  * to perform a "synchronous close" if they care --- wait till the
286  * transport layer reports connection closure, and you can be sure the
287  * backend has exited.
288  *
289  * We do set sock to PGINVALID_SOCKET to prevent any further I/O,
290  * though.
291  */
293  }
294 }
void secure_close(Port *port)
Definition: be-secure.c:133
void * gss
Definition: libpq-be.h:211

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

Referenced by pq_init().

◆ socket_comm_reset()

static void socket_comm_reset ( void  )
static

Definition at line 235 of file pqcomm.c.

236 {
237  /* Do not throw away pending data, but do reset the busy flag */
238  PqCommBusy = false;
239 }

References PqCommBusy.

◆ socket_flush()

static int socket_flush ( void  )
static

Definition at line 1317 of file pqcomm.c.

1318 {
1319  int res;
1320 
1321  /* No-op if reentrant call */
1322  if (PqCommBusy)
1323  return 0;
1324  PqCommBusy = true;
1325  socket_set_nonblocking(false);
1326  res = internal_flush();
1327  PqCommBusy = false;
1328  return res;
1329 }

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

◆ socket_flush_if_writable()

static int socket_flush_if_writable ( void  )
static

Definition at line 1412 of file pqcomm.c.

1413 {
1414  int res;
1415 
1416  /* Quick exit if nothing to do */
1417  if (PqSendPointer == PqSendStart)
1418  return 0;
1419 
1420  /* No-op if reentrant call */
1421  if (PqCommBusy)
1422  return 0;
1423 
1424  /* Temporarily put the socket into non-blocking mode */
1425  socket_set_nonblocking(true);
1426 
1427  PqCommBusy = true;
1428  res = internal_flush();
1429  PqCommBusy = false;
1430  return res;
1431 }

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

◆ socket_is_send_pending()

static bool socket_is_send_pending ( void  )
static

Definition at line 1438 of file pqcomm.c.

1439 {
1440  return (PqSendStart < PqSendPointer);
1441 }

References PqSendPointer, and PqSendStart.

◆ socket_putmessage()

static int socket_putmessage ( char  msgtype,
const char *  s,
size_t  len 
)
static

Definition at line 1468 of file pqcomm.c.

1469 {
1470  uint32 n32;
1471 
1472  Assert(msgtype != 0);
1473 
1474  if (PqCommBusy)
1475  return 0;
1476  PqCommBusy = true;
1477  if (internal_putbytes(&msgtype, 1))
1478  goto fail;
1479 
1480  n32 = pg_hton32((uint32) (len + 4));
1481  if (internal_putbytes((char *) &n32, 4))
1482  goto fail;
1483 
1484  if (internal_putbytes(s, len))
1485  goto fail;
1486  PqCommBusy = false;
1487  return 0;
1488 
1489 fail:
1490  PqCommBusy = false;
1491  return EOF;
1492 }
unsigned int uint32
Definition: c.h:495
#define pg_hton32(x)
Definition: pg_bswap.h:121

References Assert(), internal_putbytes(), len, pg_hton32, and PqCommBusy.

◆ socket_putmessage_noblock()

static void socket_putmessage_noblock ( char  msgtype,
const char *  s,
size_t  len 
)
static

Definition at line 1501 of file pqcomm.c.

1502 {
1504  int required;
1505 
1506  /*
1507  * Ensure we have enough space in the output buffer for the message header
1508  * as well as the message itself.
1509  */
1510  required = PqSendPointer + 1 + 4 + len;
1511  if (required > PqSendBufferSize)
1512  {
1515  }
1516  res = pq_putmessage(msgtype, s, len);
1517  Assert(res == 0); /* should not fail when the message fits in
1518  * buffer */
1519 }
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:49
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1476

References Assert(), len, PG_USED_FOR_ASSERTS_ONLY, pq_putmessage, PqSendBuffer, PqSendBufferSize, PqSendPointer, repalloc(), generate_unaccent_rules::required, and res.

◆ socket_set_nonblocking()

static void socket_set_nonblocking ( bool  nonblocking)
static

Definition at line 902 of file pqcomm.c.

903 {
904  if (MyProcPort == NULL)
905  ereport(ERROR,
906  (errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
907  errmsg("there is no client connection")));
908 
909  MyProcPort->noblock = nonblocking;
910 }
#define ERROR
Definition: elog.h:39
bool noblock
Definition: libpq-be.h:149

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

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

◆ StreamClose()

void StreamClose ( pgsocket  sock)

Definition at line 835 of file pqcomm.c.

836 {
837  if (closesocket(sock) != 0)
838  elog(LOG, "could not close client or listen socket: %m");
839 }
#define closesocket
Definition: port.h:349

References closesocket, elog(), and LOG.

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

◆ StreamConnection()

int StreamConnection ( pgsocket  server_fd,
Port port 
)

Definition at line 701 of file pqcomm.c.

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

References accept, ereport, errcode_for_socket_access(), errmsg(), LOG, pg_usleep(), PGINVALID_SOCKET, port, PQ_SEND_BUFFER_SIZE, pq_setkeepalivescount(), pq_setkeepalivesidle(), pq_setkeepalivesinterval(), pq_settcpusertimeout(), STATUS_ERROR, STATUS_OK, tcp_keepalives_count, tcp_keepalives_idle, tcp_keepalives_interval, and tcp_user_timeout.

Referenced by ConnCreate().

◆ StreamServerPort()

int StreamServerPort ( int  family,
const char *  hostName,
unsigned short  portNumber,
const char *  unixSocketDir,
pgsocket  ListenSocket[],
int  MaxListen 
)

Definition at line 321 of file pqcomm.c.

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

References _, bind, closesocket, EADDRINUSE, elog(), ereport, err(), errcode_for_socket_access(), errhint(), errmsg(), FATAL, fd(), listen, ListenSocket, Lock_AF_UNIX(), LOG, MaxConnections, MAXPGPATH, MemSet, pg_freeaddrinfo_all(), pg_getaddrinfo_all(), pg_getnameinfo_all(), PGINVALID_SOCKET, Setup_AF_UNIX(), snprintf, socket, STATUS_ERROR, STATUS_OK, UNIXSOCK_PATH, and UNIXSOCK_PATH_BUFLEN.

Referenced by PostmasterMain().

◆ TouchSocketFiles()

void TouchSocketFiles ( void  )

Definition at line 851 of file pqcomm.c.

852 {
853  ListCell *l;
854 
855  /* Loop through all created sockets... */
856  foreach(l, sock_paths)
857  {
858  char *sock_path = (char *) lfirst(l);
859 
860  /* Ignore errors; there's no point in complaining */
861  (void) utime(sock_path, NULL);
862  }
863 }

References lfirst, and sock_paths.

Referenced by ServerLoop().

Variable Documentation

◆ FeBeWaitSet

◆ PqCommBusy

bool PqCommBusy
static

◆ PqCommMethods

const PQcommMethods* PqCommMethods = &PqCommSocketMethods

Definition at line 162 of file pqcomm.c.

Referenced by pq_redirect_to_shm_mq(), and pq_set_parallel_leader().

◆ PqCommReadingMsg

◆ PqCommSocketMethods

const PQcommMethods PqCommSocketMethods
static
Initial value:
= {
.comm_reset = socket_comm_reset,
.flush = socket_flush,
.flush_if_writable = socket_flush_if_writable,
.is_send_pending = socket_is_send_pending,
.putmessage = socket_putmessage,
.putmessage_noblock = socket_putmessage_noblock
}
static int socket_flush_if_writable(void)
Definition: pqcomm.c:1412
static int socket_flush(void)
Definition: pqcomm.c:1317
static void socket_comm_reset(void)
Definition: pqcomm.c:235
static bool socket_is_send_pending(void)
Definition: pqcomm.c:1438
static int socket_putmessage(char msgtype, const char *s, size_t len)
Definition: pqcomm.c:1468
static void socket_putmessage_noblock(char msgtype, const char *s, size_t len)
Definition: pqcomm.c:1501

Definition at line 153 of file pqcomm.c.

◆ PqRecvBuffer

char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
static

Definition at line 127 of file pqcomm.c.

Referenced by pq_getbyte(), pq_getbyte_if_available(), pq_getbytes(), pq_peekbyte(), and pq_recvbuf().

◆ PqRecvLength

int PqRecvLength
static

◆ PqRecvPointer

int PqRecvPointer
static

◆ PqSendBuffer

char* PqSendBuffer
static

Definition at line 122 of file pqcomm.c.

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

◆ PqSendBufferSize

int PqSendBufferSize
static

Definition at line 123 of file pqcomm.c.

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

◆ PqSendPointer

◆ PqSendStart

int PqSendStart
static

◆ sock_paths

List* sock_paths = NIL
static

Definition at line 110 of file pqcomm.c.

Referenced by Lock_AF_UNIX(), RemoveSocketFiles(), and TouchSocketFiles().

◆ Unix_socket_group

char* Unix_socket_group

Definition at line 107 of file pqcomm.c.

Referenced by Setup_AF_UNIX().

◆ Unix_socket_permissions

int Unix_socket_permissions

Definition at line 106 of file pqcomm.c.

Referenced by Setup_AF_UNIX(), and show_unix_socket_permissions().