PostgreSQL Source Code  git master
libpq-be.h File Reference
#include <sys/time.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  Port
 

Typedefs

typedef enum CAC_state CAC_state
 
typedef struct Port Port
 

Enumerations

enum  CAC_state {
  CAC_OK , CAC_STARTUP , CAC_SHUTDOWN , CAC_RECOVERY ,
  CAC_NOTCONSISTENT , CAC_TOOMANY
}
 

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
 

Typedef Documentation

◆ CAC_state

typedef enum CAC_state CAC_state

◆ Port

typedef struct Port Port

Enumeration Type Documentation

◆ CAC_state

enum CAC_state
Enumerator
CAC_OK 
CAC_STARTUP 
CAC_SHUTDOWN 
CAC_RECOVERY 
CAC_NOTCONSISTENT 
CAC_TOOMANY 

Definition at line 71 of file libpq-be.h.

72 {
73  CAC_OK,
79 } CAC_state;
CAC_state
Definition: libpq-be.h:72
@ CAC_TOOMANY
Definition: libpq-be.h:78
@ CAC_OK
Definition: libpq-be.h:73
@ CAC_RECOVERY
Definition: libpq-be.h:76
@ CAC_NOTCONSISTENT
Definition: libpq-be.h:77
@ CAC_STARTUP
Definition: libpq-be.h:74
@ CAC_SHUTDOWN
Definition: libpq-be.h:75

Function Documentation

◆ pq_getkeepalivescount()

int pq_getkeepalivescount ( Port port)

Definition at line 1792 of file pqcomm.c.

1793 {
1794 #ifdef TCP_KEEPCNT
1795  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1796  return 0;
1797 
1798  if (port->keepalives_count != 0)
1799  return port->keepalives_count;
1800 
1801  if (port->default_keepalives_count == 0)
1802  {
1803  socklen_t size = sizeof(port->default_keepalives_count);
1804 
1805  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1806  (char *) &port->default_keepalives_count,
1807  &size) < 0)
1808  {
1809  ereport(LOG,
1810  (errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPCNT")));
1811  port->default_keepalives_count = -1; /* don't know */
1812  }
1813  }
1814 
1815  return port->default_keepalives_count;
1816 #else
1817  return 0;
1818 #endif
1819 }
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define LOG
Definition: elog.h:25
#define ereport(elevel,...)
Definition: elog.h:143
static int port
Definition: pg_regress.c:92
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 1623 of file pqcomm.c.

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

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

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

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

Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().

◆ pq_gettcpusertimeout()

int pq_gettcpusertimeout ( Port port)

Definition at line 1867 of file pqcomm.c.

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

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

Referenced by pq_settcpusertimeout(), and show_tcp_user_timeout().

◆ pq_setkeepalivescount()

int pq_setkeepalivescount ( int  count,
Port port 
)

Definition at line 1822 of file pqcomm.c.

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

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

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

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

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

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

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

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

Referenced by assign_tcp_user_timeout(), and StreamConnection().

Variable Documentation

◆ FrontendProtocol