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 ListenSockets[], int *NumListenSockets, 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 1993 of file pqcomm.c.

1994 {
1995  /* See comments in assign_tcp_keepalives_idle */
1997 }
struct Port * MyProcPort
Definition: globals.c:48
#define newval
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1814

References MyProcPort, newval, and pq_setkeepalivescount().

◆ assign_tcp_keepalives_idle()

void assign_tcp_keepalives_idle ( int  newval,
void *  extra 
)

Definition at line 1937 of file pqcomm.c.

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

References MyProcPort, newval, and pq_setkeepalivesidle().

◆ assign_tcp_keepalives_interval()

void assign_tcp_keepalives_interval ( int  newval,
void *  extra 
)

Definition at line 1970 of file pqcomm.c.

1971 {
1972  /* See comments in assign_tcp_keepalives_idle */
1974 }
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1735

References MyProcPort, newval, and pq_setkeepalivesinterval().

◆ assign_tcp_user_timeout()

void assign_tcp_user_timeout ( int  newval,
void *  extra 
)

Definition at line 2016 of file pqcomm.c.

2017 {
2018  /* See comments in assign_tcp_keepalives_idle */
2020 }
int pq_settcpusertimeout(int timeout, Port *port)
Definition: pqcomm.c:1889

References MyProcPort, newval, and pq_settcpusertimeout().

◆ internal_flush()

static int internal_flush ( void  )
static

Definition at line 1345 of file pqcomm.c.

1346 {
1347  static int last_reported_send_errno = 0;
1348 
1349  char *bufptr = PqSendBuffer + PqSendStart;
1350  char *bufend = PqSendBuffer + PqSendPointer;
1351 
1352  while (bufptr < bufend)
1353  {
1354  int r;
1355 
1356  r = secure_write(MyProcPort, bufptr, bufend - bufptr);
1357 
1358  if (r <= 0)
1359  {
1360  if (errno == EINTR)
1361  continue; /* Ok if we were interrupted */
1362 
1363  /*
1364  * Ok if no data writable without blocking, and the socket is in
1365  * non-blocking mode.
1366  */
1367  if (errno == EAGAIN ||
1368  errno == EWOULDBLOCK)
1369  {
1370  return 0;
1371  }
1372 
1373  /*
1374  * Careful: an ereport() that tries to write to the client would
1375  * cause recursion to here, leading to stack overflow and core
1376  * dump! This message must go *only* to the postmaster log.
1377  *
1378  * If a client disconnects while we're in the midst of output, we
1379  * might write quite a bit of data before we get to a safe query
1380  * abort point. So, suppress duplicate log messages.
1381  */
1382  if (errno != last_reported_send_errno)
1383  {
1384  last_reported_send_errno = errno;
1387  errmsg("could not send data to client: %m")));
1388  }
1389 
1390  /*
1391  * We drop the buffered data anyway so that processing can
1392  * continue, even though we'll probably quit soon. We also set a
1393  * flag that'll cause the next CHECK_FOR_INTERRUPTS to terminate
1394  * the connection.
1395  */
1396  PqSendStart = PqSendPointer = 0;
1398  InterruptPending = 1;
1399  return EOF;
1400  }
1401 
1402  last_reported_send_errno = 0; /* reset after any successful send */
1403  bufptr += r;
1404  PqSendStart += r;
1405  }
1406 
1407  PqSendStart = PqSendPointer = 0;
1408  return 0;
1409 }
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:956
int errmsg(const char *fmt,...)
Definition: elog.c:1073
#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 1292 of file pqcomm.c.

1293 {
1294  size_t amount;
1295 
1296  while (len > 0)
1297  {
1298  /* If buffer is full, then flush it out */
1300  {
1301  socket_set_nonblocking(false);
1302  if (internal_flush())
1303  return EOF;
1304  }
1305  amount = PqSendBufferSize - PqSendPointer;
1306  if (amount > len)
1307  amount = len;
1308  memcpy(PqSendBuffer + PqSendPointer, s, amount);
1309  PqSendPointer += amount;
1310  s += amount;
1311  len -= amount;
1312  }
1313  return 0;
1314 }
const void size_t len
static int internal_flush(void)
Definition: pqcomm.c:1345
static void socket_set_nonblocking(bool nonblocking)
Definition: pqcomm.c:898
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 589 of file pqcomm.c.

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

1144 {
1145  return (PqRecvPointer < PqRecvLength);
1146 }
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 2039 of file pqcomm.c.

2040 {
2041  WaitEvent events[FeBeWaitSetNEvents];
2042  int rc;
2043 
2044  /*
2045  * It's OK to modify the socket event filter without restoring, because
2046  * all FeBeWaitSet socket wait sites do the same.
2047  */
2049 
2050 retry:
2051  rc = WaitEventSetWait(FeBeWaitSet, 0, events, lengthof(events), 0);
2052  for (int i = 0; i < rc; ++i)
2053  {
2054  if (events[i].events & WL_SOCKET_CLOSED)
2055  return false;
2056  if (events[i].events & WL_LATCH_SET)
2057  {
2058  /*
2059  * A latch event might be preventing other events from being
2060  * reported. Reset it and poll again. No need to restore it
2061  * because no code should expect latches to survive across
2062  * CHECK_FOR_INTERRUPTS().
2063  */
2065  goto retry;
2066  }
2067  }
2068 
2069  return true;
2070 }
#define lengthof(array)
Definition: c.h:775
struct Latch * MyLatch
Definition: globals.c:59
int i
Definition: isn.c:73
void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch)
Definition: latch.c:1050
int WaitEventSetWait(WaitEventSet *set, long timeout, WaitEvent *occurred_events, int nevents, uint32 wait_event_info)
Definition: latch.c:1425
void ResetLatch(Latch *latch)
Definition: latch.c:725
#define WL_SOCKET_CLOSED
Definition: latch.h:139
#define WL_LATCH_SET
Definition: latch.h:127
#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 1114 of file pqcomm.c.

1115 {
1116  size_t amount;
1117 
1119 
1120  while (len > 0)
1121  {
1122  while (PqRecvPointer >= PqRecvLength)
1123  {
1124  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1125  return EOF; /* Failed to recv data */
1126  }
1127  amount = PqRecvLength - PqRecvPointer;
1128  if (amount > len)
1129  amount = len;
1130  PqRecvPointer += amount;
1131  len -= amount;
1132  }
1133  return 0;
1134 }
Assert(fmt[strlen(fmt) - 1] !='\n')
static int pq_recvbuf(void)
Definition: pqcomm.c:915
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 1180 of file pqcomm.c.

1181 {
1183 
1184  PqCommReadingMsg = false;
1185 }

References Assert(), and PqCommReadingMsg.

Referenced by ProcessRepliesIfAny(), and ProcessStartupPacket().

◆ pq_getbyte()

int pq_getbyte ( void  )

Definition at line 981 of file pqcomm.c.

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:127

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

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

◆ pq_getbyte_if_available()

int pq_getbyte_if_available ( unsigned char *  c)

Definition at line 1021 of file pqcomm.c.

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  errno = 0;
1037 
1038  r = secure_read(MyProcPort, c, 1);
1039  if (r < 0)
1040  {
1041  /*
1042  * Ok if no data available without blocking or interrupted (though
1043  * EINTR really shouldn't happen with a non-blocking socket). Report
1044  * other errors.
1045  */
1046  if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
1047  r = 0;
1048  else
1049  {
1050  /*
1051  * Careful: an ereport() that tries to write to the client would
1052  * cause recursion to here, leading to stack overflow and core
1053  * dump! This message must go *only* to the postmaster log.
1054  *
1055  * If errno is zero, assume it's EOF and let the caller complain.
1056  */
1057  if (errno != 0)
1060  errmsg("could not receive data from client: %m")));
1061  r = EOF;
1062  }
1063  }
1064  else if (r == 0)
1065  {
1066  /* EOF detected */
1067  r = EOF;
1068  }
1069 
1070  return r;
1071 }
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 1080 of file pqcomm.c.

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

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 1784 of file pqcomm.c.

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

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

Referenced by pq_setkeepalivescount(), and show_tcp_keepalives_count().

◆ pq_getkeepalivesidle()

int pq_getkeepalivesidle ( Port port)

Definition at line 1615 of file pqcomm.c.

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

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

Referenced by pq_setkeepalivesidle(), and show_tcp_keepalives_idle().

◆ pq_getkeepalivesinterval()

int pq_getkeepalivesinterval ( Port port)

Definition at line 1700 of file pqcomm.c.

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

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

Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().

◆ pq_getmessage()

int pq_getmessage ( StringInfo  s,
int  maxlen 
)

Definition at line 1218 of file pqcomm.c.

1219 {
1220  int32 len;
1221 
1223 
1224  resetStringInfo(s);
1225 
1226  /* Read message length word */
1227  if (pq_getbytes((char *) &len, 4) == EOF)
1228  {
1230  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1231  errmsg("unexpected EOF within message length word")));
1232  return EOF;
1233  }
1234 
1235  len = pg_ntoh32(len);
1236 
1237  if (len < 4 || len > maxlen)
1238  {
1240  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1241  errmsg("invalid message length")));
1242  return EOF;
1243  }
1244 
1245  len -= 4; /* discount length itself */
1246 
1247  if (len > 0)
1248  {
1249  /*
1250  * Allocate space for message. If we run out of room (ridiculously
1251  * large message), we will elog(ERROR), but we want to discard the
1252  * message body so as not to lose communication sync.
1253  */
1254  PG_TRY();
1255  {
1256  enlargeStringInfo(s, len);
1257  }
1258  PG_CATCH();
1259  {
1260  if (pq_discardbytes(len) == EOF)
1262  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1263  errmsg("incomplete message from client")));
1264 
1265  /* we discarded the rest of the message so we're back in sync. */
1266  PqCommReadingMsg = false;
1267  PG_RE_THROW();
1268  }
1269  PG_END_TRY();
1270 
1271  /* And grab the message */
1272  if (pq_getbytes(s->data, len) == EOF)
1273  {
1275  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1276  errmsg("incomplete message from client")));
1277  return EOF;
1278  }
1279  s->len = len;
1280  /* Place a trailing null per StringInfo convention */
1281  s->data[len] = '\0';
1282  }
1283 
1284  /* finished reading the message. */
1285  PqCommReadingMsg = false;
1286 
1287  return 0;
1288 }
signed int int32
Definition: c.h:481
int errcode(int sqlerrcode)
Definition: elog.c:860
#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:1114
int pq_getbytes(char *s, size_t len)
Definition: pqcomm.c:1080
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:78
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:289

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(), HandleUploadManifestPacket(), ProcessRepliesIfAny(), recv_password_packet(), and SocketBackend().

◆ pq_gettcpusertimeout()

int pq_gettcpusertimeout ( Port port)

Definition at line 1859 of file pqcomm.c.

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

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

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:169
#define FATAL
Definition: elog.h:41
#define elog(elevel,...)
Definition: elog.h:224
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:309
WaitEventSet * CreateWaitEventSet(ResourceOwner resowner, int nevents)
Definition: latch.c:752
int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, void *user_data)
Definition: latch.c:964
#define WL_POSTMASTER_DEATH
Definition: latch.h:131
#define WL_SOCKET_WRITEABLE
Definition: latch.h:129
#define FeBeWaitSetLatchPos
Definition: libpq.h:64
MemoryContext TopMemoryContext
Definition: mcxt.c:141
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1066
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 1196 of file pqcomm.c.

1197 {
1198  return PqCommReadingMsg;
1199 }

References PqCommReadingMsg.

Referenced by PostgresMain().

◆ pq_peekbyte()

int pq_peekbyte ( void  )

Definition at line 1000 of file pqcomm.c.

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 }

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 1544 of file pqcomm.c.

1545 {
1546  Assert(msgtype != 0);
1547 
1548  if (PqCommBusy)
1549  return 0;
1550  PqCommBusy = true;
1551  if (internal_putbytes(&msgtype, 1))
1552  goto fail;
1553 
1554  if (internal_putbytes(s, len))
1555  goto fail;
1556  PqCommBusy = false;
1557  return 0;
1558 
1559 fail:
1560  PqCommBusy = false;
1561  return EOF;
1562 }
static int internal_putbytes(const char *s, size_t len)
Definition: pqcomm.c:1292

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

Referenced by send_message_to_frontend().

◆ pq_recvbuf()

static int pq_recvbuf ( void  )
static

Definition at line 915 of file pqcomm.c.

916 {
917  if (PqRecvPointer > 0)
918  {
920  {
921  /* still some unread data, left-justify it in the buffer */
925  PqRecvPointer = 0;
926  }
927  else
929  }
930 
931  /* Ensure that we're in blocking mode */
932  socket_set_nonblocking(false);
933 
934  /* Can fill buffer from PqRecvLength and upwards */
935  for (;;)
936  {
937  int r;
938 
939  errno = 0;
940 
943 
944  if (r < 0)
945  {
946  if (errno == EINTR)
947  continue; /* Ok if interrupted */
948 
949  /*
950  * Careful: an ereport() that tries to write to the client would
951  * cause recursion to here, leading to stack overflow and core
952  * dump! This message must go *only* to the postmaster log.
953  *
954  * If errno is zero, assume it's EOF and let the caller complain.
955  */
956  if (errno != 0)
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 }
#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 1814 of file pqcomm.c.

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

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 1650 of file pqcomm.c.

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

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 1735 of file pqcomm.c.

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

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 1889 of file pqcomm.c.

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

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 1156 of file pqcomm.c.

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

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

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

◆ RemoveSocketFiles()

void RemoveSocketFiles ( void  )

Definition at line 865 of file pqcomm.c.

866 {
867  ListCell *l;
868 
869  /* Loop through all created sockets... */
870  foreach(l, sock_paths)
871  {
872  char *sock_path = (char *) lfirst(l);
873 
874  /* Ignore any error. */
875  (void) unlink(sock_path);
876  }
877  /* Since we're about to exit, no need to reclaim storage */
878  sock_paths = NIL;
879 }
#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 624 of file pqcomm.c.

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

2004 {
2005  /* See comments in assign_tcp_keepalives_idle */
2006  static char nbuf[16];
2007 
2008  snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
2009  return nbuf;
2010 }
#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 1957 of file pqcomm.c.

1958 {
1959  /* See comments in assign_tcp_keepalives_idle */
1960  static char nbuf[16];
1961 
1962  snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
1963  return nbuf;
1964 }

References MyProcPort, pq_getkeepalivesidle(), and snprintf.

◆ show_tcp_keepalives_interval()

const char* show_tcp_keepalives_interval ( void  )

Definition at line 1980 of file pqcomm.c.

1981 {
1982  /* See comments in assign_tcp_keepalives_idle */
1983  static char nbuf[16];
1984 
1985  snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
1986  return nbuf;
1987 }

References MyProcPort, pq_getkeepalivesinterval(), and snprintf.

◆ show_tcp_user_timeout()

const char* show_tcp_user_timeout ( void  )

Definition at line 2026 of file pqcomm.c.

2027 {
2028  /* See comments in assign_tcp_keepalives_idle */
2029  static char nbuf[16];
2030 
2031  snprintf(nbuf, sizeof(nbuf), "%d", pq_gettcpusertimeout(MyProcPort));
2032  return nbuf;
2033 }

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 1323 of file pqcomm.c.

1324 {
1325  int res;
1326 
1327  /* No-op if reentrant call */
1328  if (PqCommBusy)
1329  return 0;
1330  PqCommBusy = true;
1331  socket_set_nonblocking(false);
1332  res = internal_flush();
1333  PqCommBusy = false;
1334  return res;
1335 }

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

◆ socket_flush_if_writable()

static int socket_flush_if_writable ( void  )
static

Definition at line 1418 of file pqcomm.c.

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

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 1444 of file pqcomm.c.

1445 {
1446  return (PqSendStart < PqSendPointer);
1447 }

References PqSendPointer, and PqSendStart.

◆ socket_putmessage()

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

Definition at line 1474 of file pqcomm.c.

1475 {
1476  uint32 n32;
1477 
1478  Assert(msgtype != 0);
1479 
1480  if (PqCommBusy)
1481  return 0;
1482  PqCommBusy = true;
1483  if (internal_putbytes(&msgtype, 1))
1484  goto fail;
1485 
1486  n32 = pg_hton32((uint32) (len + 4));
1487  if (internal_putbytes((char *) &n32, 4))
1488  goto fail;
1489 
1490  if (internal_putbytes(s, len))
1491  goto fail;
1492  PqCommBusy = false;
1493  return 0;
1494 
1495 fail:
1496  PqCommBusy = false;
1497  return EOF;
1498 }
unsigned int uint32
Definition: c.h:493
#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 1507 of file pqcomm.c.

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

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 898 of file pqcomm.c.

899 {
900  if (MyProcPort == NULL)
901  ereport(ERROR,
902  (errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
903  errmsg("there is no client connection")));
904 
905  MyProcPort->noblock = nonblocking;
906 }
#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 831 of file pqcomm.c.

832 {
833  if (closesocket(sock) != 0)
834  elog(LOG, "could not close client or listen socket: %m");
835 }
#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 697 of file pqcomm.c.

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  ereport(LOG,
727  (errmsg("%s() failed: %m", "getsockname")));
728  return STATUS_ERROR;
729  }
730 
731  /* select NODELAY and KEEPALIVE options if it's a TCP connection */
732  if (port->laddr.addr.ss_family != AF_UNIX)
733  {
734  int on;
735 #ifdef WIN32
736  int oldopt;
737  int optlen;
738  int newopt;
739 #endif
740 
741 #ifdef TCP_NODELAY
742  on = 1;
743  if (setsockopt(port->sock, IPPROTO_TCP, TCP_NODELAY,
744  (char *) &on, sizeof(on)) < 0)
745  {
746  ereport(LOG,
747  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_NODELAY")));
748  return STATUS_ERROR;
749  }
750 #endif
751  on = 1;
752  if (setsockopt(port->sock, SOL_SOCKET, SO_KEEPALIVE,
753  (char *) &on, sizeof(on)) < 0)
754  {
755  ereport(LOG,
756  (errmsg("%s(%s) failed: %m", "setsockopt", "SO_KEEPALIVE")));
757  return STATUS_ERROR;
758  }
759 
760 #ifdef WIN32
761 
762  /*
763  * This is a Win32 socket optimization. The OS send buffer should be
764  * large enough to send the whole Postgres send buffer in one go, or
765  * performance suffers. The Postgres send buffer can be enlarged if a
766  * very large message needs to be sent, but we won't attempt to
767  * enlarge the OS buffer if that happens, so somewhat arbitrarily
768  * ensure that the OS buffer is at least PQ_SEND_BUFFER_SIZE * 4.
769  * (That's 32kB with the current default).
770  *
771  * The default OS buffer size used to be 8kB in earlier Windows
772  * versions, but was raised to 64kB in Windows 2012. So it shouldn't
773  * be necessary to change it in later versions anymore. Changing it
774  * unnecessarily can even reduce performance, because setting
775  * SO_SNDBUF in the application disables the "dynamic send buffering"
776  * feature that was introduced in Windows 7. So before fiddling with
777  * SO_SNDBUF, check if the current buffer size is already large enough
778  * and only increase it if necessary.
779  *
780  * See https://support.microsoft.com/kb/823764/EN-US/ and
781  * https://msdn.microsoft.com/en-us/library/bb736549%28v=vs.85%29.aspx
782  */
783  optlen = sizeof(oldopt);
784  if (getsockopt(port->sock, SOL_SOCKET, SO_SNDBUF, (char *) &oldopt,
785  &optlen) < 0)
786  {
787  ereport(LOG,
788  (errmsg("%s(%s) failed: %m", "getsockopt", "SO_SNDBUF")));
789  return STATUS_ERROR;
790  }
791  newopt = PQ_SEND_BUFFER_SIZE * 4;
792  if (oldopt < newopt)
793  {
794  if (setsockopt(port->sock, SOL_SOCKET, SO_SNDBUF, (char *) &newopt,
795  sizeof(newopt)) < 0)
796  {
797  ereport(LOG,
798  (errmsg("%s(%s) failed: %m", "setsockopt", "SO_SNDBUF")));
799  return STATUS_ERROR;
800  }
801  }
802 #endif
803 
804  /*
805  * Also apply the current keepalive parameters. If we fail to set a
806  * parameter, don't error out, because these aren't universally
807  * supported. (Note: you might think we need to reset the GUC
808  * variables to 0 in such a case, but it's not necessary because the
809  * show hooks for these variables report the truth anyway.)
810  */
815  }
816 
817  return STATUS_OK;
818 }
int tcp_keepalives_idle
Definition: guc_tables.c:546
int tcp_keepalives_interval
Definition: guc_tables.c:547
int tcp_keepalives_count
Definition: guc_tables.c:548
int tcp_user_timeout
Definition: guc_tables.c:549
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  ListenSockets[],
int *  NumListenSockets,
int  MaxListen 
)

Definition at line 322 of file pqcomm.c.

325 {
326  pgsocket fd;
327  int err;
328  int maxconn;
329  int ret;
330  char portNumberStr[32];
331  const char *familyDesc;
332  char familyDescBuf[64];
333  const char *addrDesc;
334  char addrBuf[NI_MAXHOST];
335  char *service;
336  struct addrinfo *addrs = NULL,
337  *addr;
338  struct addrinfo hint;
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  if (*NumListenSockets == 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  case AF_INET6:
419  familyDesc = _("IPv6");
420  break;
421  case AF_UNIX:
422  familyDesc = _("Unix");
423  break;
424  default:
425  snprintf(familyDescBuf, sizeof(familyDescBuf),
426  _("unrecognized address family %d"),
427  addr->ai_family);
428  familyDesc = familyDescBuf;
429  break;
430  }
431 
432  /* set up text form of address for log messages */
433  if (addr->ai_family == AF_UNIX)
434  addrDesc = unixSocketPath;
435  else
436  {
437  pg_getnameinfo_all((const struct sockaddr_storage *) addr->ai_addr,
438  addr->ai_addrlen,
439  addrBuf, sizeof(addrBuf),
440  NULL, 0,
441  NI_NUMERICHOST);
442  addrDesc = addrBuf;
443  }
444 
445  if ((fd = socket(addr->ai_family, SOCK_STREAM, 0)) == PGINVALID_SOCKET)
446  {
447  ereport(LOG,
449  /* translator: first %s is IPv4, IPv6, or Unix */
450  errmsg("could not create %s socket for address \"%s\": %m",
451  familyDesc, addrDesc)));
452  continue;
453  }
454 
455 #ifndef WIN32
456  /* Don't give the listen socket to any subprograms we execute. */
457  if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
458  elog(FATAL, "fcntl(F_SETFD) failed on socket: %m");
459 
460  /*
461  * Without the SO_REUSEADDR flag, a new postmaster can't be started
462  * right away after a stop or crash, giving "address already in use"
463  * error on TCP ports.
464  *
465  * On win32, however, this behavior only happens if the
466  * SO_EXCLUSIVEADDRUSE is set. With SO_REUSEADDR, win32 allows
467  * multiple servers to listen on the same address, resulting in
468  * unpredictable behavior. With no flags at all, win32 behaves as Unix
469  * with SO_REUSEADDR.
470  */
471  if (addr->ai_family != AF_UNIX)
472  {
473  if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
474  (char *) &one, sizeof(one))) == -1)
475  {
476  ereport(LOG,
478  /* translator: third %s is IPv4, IPv6, or Unix */
479  errmsg("%s(%s) failed for %s address \"%s\": %m",
480  "setsockopt", "SO_REUSEADDR",
481  familyDesc, addrDesc)));
482  closesocket(fd);
483  continue;
484  }
485  }
486 #endif
487 
488 #ifdef IPV6_V6ONLY
489  if (addr->ai_family == AF_INET6)
490  {
491  if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
492  (char *) &one, sizeof(one)) == -1)
493  {
494  ereport(LOG,
496  /* translator: third %s is IPv4, IPv6, or Unix */
497  errmsg("%s(%s) failed for %s address \"%s\": %m",
498  "setsockopt", "IPV6_V6ONLY",
499  familyDesc, addrDesc)));
500  closesocket(fd);
501  continue;
502  }
503  }
504 #endif
505 
506  /*
507  * Note: This might fail on some OS's, like Linux older than
508  * 2.4.21-pre3, that don't have the IPV6_V6ONLY socket option, and map
509  * ipv4 addresses to ipv6. It will show ::ffff:ipv4 for all ipv4
510  * connections.
511  */
512  err = bind(fd, addr->ai_addr, addr->ai_addrlen);
513  if (err < 0)
514  {
515  int saved_errno = errno;
516 
517  ereport(LOG,
519  /* translator: first %s is IPv4, IPv6, or Unix */
520  errmsg("could not bind %s address \"%s\": %m",
521  familyDesc, addrDesc),
522  saved_errno == EADDRINUSE ?
523  (addr->ai_family == AF_UNIX ?
524  errhint("Is another postmaster already running on port %d?",
525  (int) portNumber) :
526  errhint("Is another postmaster already running on port %d?"
527  " If not, wait a few seconds and retry.",
528  (int) portNumber)) : 0));
529  closesocket(fd);
530  continue;
531  }
532 
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 
542  /*
543  * Select appropriate accept-queue length limit. It seems reasonable
544  * to use a value similar to the maximum number of child processes
545  * that the postmaster will permit.
546  */
547  maxconn = MaxConnections * 2;
548 
549  err = listen(fd, maxconn);
550  if (err < 0)
551  {
552  ereport(LOG,
554  /* translator: first %s is IPv4, IPv6, or Unix */
555  errmsg("could not listen on %s address \"%s\": %m",
556  familyDesc, addrDesc)));
557  closesocket(fd);
558  continue;
559  }
560 
561  if (addr->ai_family == AF_UNIX)
562  ereport(LOG,
563  (errmsg("listening on Unix socket \"%s\"",
564  addrDesc)));
565  else
566  ereport(LOG,
567  /* translator: first %s is IPv4 or IPv6 */
568  (errmsg("listening on %s address \"%s\", port %d",
569  familyDesc, addrDesc, (int) portNumber)));
570 
572  (*NumListenSockets)++;
573  added++;
574  }
575 
576  pg_freeaddrinfo_all(hint.ai_family, addrs);
577 
578  if (!added)
579  return STATUS_ERROR;
580 
581  return STATUS_OK;
582 }
#define MemSet(start, val, len)
Definition: c.h:1007
int errhint(const char *fmt,...)
Definition: elog.c:1320
#define _(x)
Definition: elog.c:91
void err(int eval, const char *fmt,...)
Definition: err.c:43
int MaxConnections
Definition: globals.c:140
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 * ListenSockets
Definition: postmaster.c:231
static int NumListenSockets
Definition: postmaster.c:230
static int Lock_AF_UNIX(const char *unixSocketDir, const char *unixSocketPath)
Definition: pqcomm.c:589
static int Setup_AF_UNIX(const char *sock_path)
Definition: pqcomm.c:624
#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
const char * gai_strerror(int ecode)
#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(), gai_strerror(), listen, ListenSockets, Lock_AF_UNIX(), LOG, MaxConnections, MAXPGPATH, MemSet, NumListenSockets, 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 847 of file pqcomm.c.

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

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:1418
static int socket_flush(void)
Definition: pqcomm.c:1323
static void socket_comm_reset(void)
Definition: pqcomm.c:235
static bool socket_is_send_pending(void)
Definition: pqcomm.c:1444
static int socket_putmessage(char msgtype, const char *s, size_t len)
Definition: pqcomm.c:1474
static void socket_putmessage_noblock(char msgtype, const char *s, size_t len)
Definition: pqcomm.c:1507

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