PostgreSQL Source Code  git master
libpq-be.h File Reference
#include <sys/time.h>
#include <netinet/tcp.h>
#include "datatype/timestamp.h"
#include "libpq/hba.h"
#include "libpq/pqcomm.h"
Include dependency graph for libpq-be.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ClientConnectionInfo
 
struct  Port
 
struct  ClientSocket
 

Typedefs

typedef struct ClientConnectionInfo ClientConnectionInfo
 
typedef struct Port Port
 
typedef struct ClientSocket ClientSocket
 

Functions

int pq_getkeepalivesidle (Port *port)
 
int pq_getkeepalivesinterval (Port *port)
 
int pq_getkeepalivescount (Port *port)
 
int pq_gettcpusertimeout (Port *port)
 
int pq_setkeepalivesidle (int idle, Port *port)
 
int pq_setkeepalivesinterval (int interval, Port *port)
 
int pq_setkeepalivescount (int count, Port *port)
 
int pq_settcpusertimeout (int timeout, Port *port)
 

Variables

PGDLLIMPORT ProtocolVersion FrontendProtocol
 
PGDLLIMPORT ClientConnectionInfo MyClientConnectionInfo
 

Typedef Documentation

◆ ClientConnectionInfo

◆ ClientSocket

typedef struct ClientSocket ClientSocket

◆ Port

typedef struct Port Port

Function Documentation

◆ pq_getkeepalivescount()

int pq_getkeepalivescount ( Port port)

Definition at line 1798 of file pqcomm.c.

1799 {
1800 #ifdef TCP_KEEPCNT
1801  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1802  return 0;
1803 
1804  if (port->keepalives_count != 0)
1805  return port->keepalives_count;
1806 
1807  if (port->default_keepalives_count == 0)
1808  {
1809  socklen_t size = sizeof(port->default_keepalives_count);
1810 
1811  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1812  (char *) &port->default_keepalives_count,
1813  &size) < 0)
1814  {
1815  ereport(LOG,
1816  (errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPCNT")));
1817  port->default_keepalives_count = -1; /* don't know */
1818  }
1819  }
1820 
1821  return port->default_keepalives_count;
1822 #else
1823  return 0;
1824 #endif
1825 }
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define LOG
Definition: elog.h:31
#define ereport(elevel,...)
Definition: elog.h:149
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 1629 of file pqcomm.c.

1630 {
1631 #if defined(PG_TCP_KEEPALIVE_IDLE) || defined(SIO_KEEPALIVE_VALS)
1632  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1633  return 0;
1634 
1635  if (port->keepalives_idle != 0)
1636  return port->keepalives_idle;
1637 
1638  if (port->default_keepalives_idle == 0)
1639  {
1640 #ifndef WIN32
1641  socklen_t size = sizeof(port->default_keepalives_idle);
1642 
1643  if (getsockopt(port->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
1644  (char *) &port->default_keepalives_idle,
1645  &size) < 0)
1646  {
1647  ereport(LOG,
1648  (errmsg("%s(%s) failed: %m", "getsockopt", PG_TCP_KEEPALIVE_IDLE_STR)));
1649  port->default_keepalives_idle = -1; /* don't know */
1650  }
1651 #else /* WIN32 */
1652  /* We can't get the defaults on Windows, so return "don't know" */
1653  port->default_keepalives_idle = -1;
1654 #endif /* WIN32 */
1655  }
1656 
1657  return port->default_keepalives_idle;
1658 #else
1659  return 0;
1660 #endif
1661 }

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

1715 {
1716 #if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
1717  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1718  return 0;
1719 
1720  if (port->keepalives_interval != 0)
1721  return port->keepalives_interval;
1722 
1723  if (port->default_keepalives_interval == 0)
1724  {
1725 #ifndef WIN32
1726  socklen_t size = sizeof(port->default_keepalives_interval);
1727 
1728  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1729  (char *) &port->default_keepalives_interval,
1730  &size) < 0)
1731  {
1732  ereport(LOG,
1733  (errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPINTVL")));
1734  port->default_keepalives_interval = -1; /* don't know */
1735  }
1736 #else
1737  /* We can't get the defaults on Windows, so return "don't know" */
1738  port->default_keepalives_interval = -1;
1739 #endif /* WIN32 */
1740  }
1741 
1742  return port->default_keepalives_interval;
1743 #else
1744  return 0;
1745 #endif
1746 }

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

Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().

◆ pq_gettcpusertimeout()

int pq_gettcpusertimeout ( Port port)

Definition at line 1873 of file pqcomm.c.

1874 {
1875 #ifdef TCP_USER_TIMEOUT
1876  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1877  return 0;
1878 
1879  if (port->tcp_user_timeout != 0)
1880  return port->tcp_user_timeout;
1881 
1882  if (port->default_tcp_user_timeout == 0)
1883  {
1884  socklen_t size = sizeof(port->default_tcp_user_timeout);
1885 
1886  if (getsockopt(port->sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
1887  (char *) &port->default_tcp_user_timeout,
1888  &size) < 0)
1889  {
1890  ereport(LOG,
1891  (errmsg("%s(%s) failed: %m", "getsockopt", "TCP_USER_TIMEOUT")));
1892  port->default_tcp_user_timeout = -1; /* don't know */
1893  }
1894  }
1895 
1896  return port->default_tcp_user_timeout;
1897 #else
1898  return 0;
1899 #endif
1900 }

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

Referenced by pq_settcpusertimeout(), and show_tcp_user_timeout().

◆ pq_setkeepalivescount()

int pq_setkeepalivescount ( int  count,
Port port 
)

Definition at line 1828 of file pqcomm.c.

1829 {
1830  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1831  return STATUS_OK;
1832 
1833 #ifdef TCP_KEEPCNT
1834  if (count == port->keepalives_count)
1835  return STATUS_OK;
1836 
1837  if (port->default_keepalives_count <= 0)
1838  {
1839  if (pq_getkeepalivescount(port) < 0)
1840  {
1841  if (count == 0)
1842  return STATUS_OK; /* default is set but unknown */
1843  else
1844  return STATUS_ERROR;
1845  }
1846  }
1847 
1848  if (count == 0)
1849  count = port->default_keepalives_count;
1850 
1851  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1852  (char *) &count, sizeof(count)) < 0)
1853  {
1854  ereport(LOG,
1855  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_KEEPCNT")));
1856  return STATUS_ERROR;
1857  }
1858 
1859  port->keepalives_count = count;
1860 #else
1861  if (count != 0)
1862  {
1863  ereport(LOG,
1864  (errmsg("%s(%s) not supported", "setsockopt", "TCP_KEEPCNT")));
1865  return STATUS_ERROR;
1866  }
1867 #endif
1868 
1869  return STATUS_OK;
1870 }
#define STATUS_OK
Definition: c.h:1169
#define STATUS_ERROR
Definition: c.h:1170
int pq_getkeepalivescount(Port *port)
Definition: pqcomm.c:1798

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

Referenced by assign_tcp_keepalives_count(), and pq_init().

◆ pq_setkeepalivesidle()

int pq_setkeepalivesidle ( int  idle,
Port port 
)

Definition at line 1664 of file pqcomm.c.

1665 {
1666  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1667  return STATUS_OK;
1668 
1669 /* check SIO_KEEPALIVE_VALS here, not just WIN32, as some toolchains lack it */
1670 #if defined(PG_TCP_KEEPALIVE_IDLE) || defined(SIO_KEEPALIVE_VALS)
1671  if (idle == port->keepalives_idle)
1672  return STATUS_OK;
1673 
1674 #ifndef WIN32
1675  if (port->default_keepalives_idle <= 0)
1676  {
1677  if (pq_getkeepalivesidle(port) < 0)
1678  {
1679  if (idle == 0)
1680  return STATUS_OK; /* default is set but unknown */
1681  else
1682  return STATUS_ERROR;
1683  }
1684  }
1685 
1686  if (idle == 0)
1687  idle = port->default_keepalives_idle;
1688 
1689  if (setsockopt(port->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
1690  (char *) &idle, sizeof(idle)) < 0)
1691  {
1692  ereport(LOG,
1693  (errmsg("%s(%s) failed: %m", "setsockopt", PG_TCP_KEEPALIVE_IDLE_STR)));
1694  return STATUS_ERROR;
1695  }
1696 
1697  port->keepalives_idle = idle;
1698 #else /* WIN32 */
1699  return pq_setkeepaliveswin32(port, idle, port->keepalives_interval);
1700 #endif
1701 #else
1702  if (idle != 0)
1703  {
1704  ereport(LOG,
1705  (errmsg("setting the keepalive idle time is not supported")));
1706  return STATUS_ERROR;
1707  }
1708 #endif
1709 
1710  return STATUS_OK;
1711 }
int pq_getkeepalivesidle(Port *port)
Definition: pqcomm.c:1629

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

Referenced by assign_tcp_keepalives_idle(), and pq_init().

◆ pq_setkeepalivesinterval()

int pq_setkeepalivesinterval ( int  interval,
Port port 
)

Definition at line 1749 of file pqcomm.c.

1750 {
1751  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1752  return STATUS_OK;
1753 
1754 #if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
1755  if (interval == port->keepalives_interval)
1756  return STATUS_OK;
1757 
1758 #ifndef WIN32
1759  if (port->default_keepalives_interval <= 0)
1760  {
1761  if (pq_getkeepalivesinterval(port) < 0)
1762  {
1763  if (interval == 0)
1764  return STATUS_OK; /* default is set but unknown */
1765  else
1766  return STATUS_ERROR;
1767  }
1768  }
1769 
1770  if (interval == 0)
1771  interval = port->default_keepalives_interval;
1772 
1773  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1774  (char *) &interval, sizeof(interval)) < 0)
1775  {
1776  ereport(LOG,
1777  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_KEEPINTVL")));
1778  return STATUS_ERROR;
1779  }
1780 
1781  port->keepalives_interval = interval;
1782 #else /* WIN32 */
1783  return pq_setkeepaliveswin32(port, port->keepalives_idle, interval);
1784 #endif
1785 #else
1786  if (interval != 0)
1787  {
1788  ereport(LOG,
1789  (errmsg("%s(%s) not supported", "setsockopt", "TCP_KEEPINTVL")));
1790  return STATUS_ERROR;
1791  }
1792 #endif
1793 
1794  return STATUS_OK;
1795 }
int pq_getkeepalivesinterval(Port *port)
Definition: pqcomm.c:1714

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

Referenced by assign_tcp_keepalives_interval(), and pq_init().

◆ pq_settcpusertimeout()

int pq_settcpusertimeout ( int  timeout,
Port port 
)

Definition at line 1903 of file pqcomm.c.

1904 {
1905  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1906  return STATUS_OK;
1907 
1908 #ifdef TCP_USER_TIMEOUT
1909  if (timeout == port->tcp_user_timeout)
1910  return STATUS_OK;
1911 
1912  if (port->default_tcp_user_timeout <= 0)
1913  {
1914  if (pq_gettcpusertimeout(port) < 0)
1915  {
1916  if (timeout == 0)
1917  return STATUS_OK; /* default is set but unknown */
1918  else
1919  return STATUS_ERROR;
1920  }
1921  }
1922 
1923  if (timeout == 0)
1924  timeout = port->default_tcp_user_timeout;
1925 
1926  if (setsockopt(port->sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
1927  (char *) &timeout, sizeof(timeout)) < 0)
1928  {
1929  ereport(LOG,
1930  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_USER_TIMEOUT")));
1931  return STATUS_ERROR;
1932  }
1933 
1934  port->tcp_user_timeout = timeout;
1935 #else
1936  if (timeout != 0)
1937  {
1938  ereport(LOG,
1939  (errmsg("%s(%s) not supported", "setsockopt", "TCP_USER_TIMEOUT")));
1940  return STATUS_ERROR;
1941  }
1942 #endif
1943 
1944  return STATUS_OK;
1945 }
int pq_gettcpusertimeout(Port *port)
Definition: pqcomm.c:1873

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

Referenced by assign_tcp_user_timeout(), and pq_init().

Variable Documentation

◆ FrontendProtocol

◆ MyClientConnectionInfo