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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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