PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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_TOOMANY, CAC_WAITBACKUP
}
 

Functions

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

Variables

ProtocolVersion FrontendProtocol
 

Typedef Documentation

typedef struct Port Port

Enumeration Type Documentation

enum CAC_state
Enumerator
CAC_OK 
CAC_STARTUP 
CAC_SHUTDOWN 
CAC_RECOVERY 
CAC_TOOMANY 
CAC_WAITBACKUP 

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

Function Documentation

int pq_getkeepalivescount ( Port port)

Definition at line 1857 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_count, elog, IS_AF_UNIX, Port::keepalives_count, Port::laddr, LOG, NULL, and Port::sock.

Referenced by pq_setkeepalivescount(), and show_tcp_keepalives_count().

1858 {
1859 #ifdef TCP_KEEPCNT
1860  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1861  return 0;
1862 
1863  if (port->keepalives_count != 0)
1864  return port->keepalives_count;
1865 
1866  if (port->default_keepalives_count == 0)
1867  {
1868  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_count);
1869 
1870  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1871  (char *) &port->default_keepalives_count,
1872  &size) < 0)
1873  {
1874  elog(LOG, "getsockopt(TCP_KEEPCNT) failed: %m");
1875  port->default_keepalives_count = -1; /* don't know */
1876  }
1877  }
1878 
1879  return port->default_keepalives_count;
1880 #else
1881  return 0;
1882 #endif
1883 }
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define LOG
Definition: elog.h:26
int default_keepalives_count
Definition: libpq-be.h:162
pgsocket sock
Definition: libpq-be.h:118
int keepalives_count
Definition: libpq-be.h:165
#define IS_AF_UNIX(fam)
Definition: ip.h:24
SockAddr laddr
Definition: libpq-be.h:121
#define NULL
Definition: c.h:229
#define elog
Definition: elog.h:219
int pq_getkeepalivesidle ( Port port)

Definition at line 1677 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_idle, elog, IS_AF_UNIX, Port::keepalives_idle, Port::laddr, LOG, NULL, and Port::sock.

Referenced by pq_setkeepalivesidle(), and show_tcp_keepalives_idle().

1678 {
1679 #if defined(TCP_KEEPIDLE) || defined(TCP_KEEPALIVE) || defined(WIN32)
1680  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1681  return 0;
1682 
1683  if (port->keepalives_idle != 0)
1684  return port->keepalives_idle;
1685 
1686  if (port->default_keepalives_idle == 0)
1687  {
1688 #ifndef WIN32
1689  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_idle);
1690 
1691 #ifdef TCP_KEEPIDLE
1692  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPIDLE,
1693  (char *) &port->default_keepalives_idle,
1694  &size) < 0)
1695  {
1696  elog(LOG, "getsockopt(TCP_KEEPIDLE) failed: %m");
1697  port->default_keepalives_idle = -1; /* don't know */
1698  }
1699 #else
1700  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPALIVE,
1701  (char *) &port->default_keepalives_idle,
1702  &size) < 0)
1703  {
1704  elog(LOG, "getsockopt(TCP_KEEPALIVE) failed: %m");
1705  port->default_keepalives_idle = -1; /* don't know */
1706  }
1707 #endif /* TCP_KEEPIDLE */
1708 #else /* WIN32 */
1709  /* We can't get the defaults on Windows, so return "don't know" */
1710  port->default_keepalives_idle = -1;
1711 #endif /* WIN32 */
1712  }
1713 
1714  return port->default_keepalives_idle;
1715 #else
1716  return 0;
1717 #endif
1718 }
int keepalives_idle
Definition: libpq-be.h:163
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define LOG
Definition: elog.h:26
pgsocket sock
Definition: libpq-be.h:118
#define IS_AF_UNIX(fam)
Definition: ip.h:24
SockAddr laddr
Definition: libpq-be.h:121
int default_keepalives_idle
Definition: libpq-be.h:160
#define NULL
Definition: c.h:229
#define elog
Definition: elog.h:219
int pq_getkeepalivesinterval ( Port port)

Definition at line 1776 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_interval, elog, IS_AF_UNIX, Port::keepalives_interval, Port::laddr, LOG, NULL, and Port::sock.

Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().

1777 {
1778 #if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
1779  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1780  return 0;
1781 
1782  if (port->keepalives_interval != 0)
1783  return port->keepalives_interval;
1784 
1785  if (port->default_keepalives_interval == 0)
1786  {
1787 #ifndef WIN32
1788  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_interval);
1789 
1790  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1791  (char *) &port->default_keepalives_interval,
1792  &size) < 0)
1793  {
1794  elog(LOG, "getsockopt(TCP_KEEPINTVL) failed: %m");
1795  port->default_keepalives_interval = -1; /* don't know */
1796  }
1797 #else
1798  /* We can't get the defaults on Windows, so return "don't know" */
1799  port->default_keepalives_interval = -1;
1800 #endif /* WIN32 */
1801  }
1802 
1803  return port->default_keepalives_interval;
1804 #else
1805  return 0;
1806 #endif
1807 }
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define LOG
Definition: elog.h:26
int default_keepalives_interval
Definition: libpq-be.h:161
pgsocket sock
Definition: libpq-be.h:118
#define IS_AF_UNIX(fam)
Definition: ip.h:24
SockAddr laddr
Definition: libpq-be.h:121
#define NULL
Definition: c.h:229
#define elog
Definition: elog.h:219
int keepalives_interval
Definition: libpq-be.h:164
int pq_setkeepalivescount ( int  count,
Port port 
)

Definition at line 1886 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_count, elog, IS_AF_UNIX, Port::keepalives_count, Port::laddr, LOG, NULL, pq_getkeepalivescount(), Port::sock, STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_count(), and StreamConnection().

1887 {
1888  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1889  return STATUS_OK;
1890 
1891 #ifdef TCP_KEEPCNT
1892  if (count == port->keepalives_count)
1893  return STATUS_OK;
1894 
1895  if (port->default_keepalives_count <= 0)
1896  {
1897  if (pq_getkeepalivescount(port) < 0)
1898  {
1899  if (count == 0)
1900  return STATUS_OK; /* default is set but unknown */
1901  else
1902  return STATUS_ERROR;
1903  }
1904  }
1905 
1906  if (count == 0)
1907  count = port->default_keepalives_count;
1908 
1909  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1910  (char *) &count, sizeof(count)) < 0)
1911  {
1912  elog(LOG, "setsockopt(TCP_KEEPCNT) failed: %m");
1913  return STATUS_ERROR;
1914  }
1915 
1916  port->keepalives_count = count;
1917 #else
1918  if (count != 0)
1919  {
1920  elog(LOG, "setsockopt(TCP_KEEPCNT) not supported");
1921  return STATUS_ERROR;
1922  }
1923 #endif
1924 
1925  return STATUS_OK;
1926 }
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:976
#define LOG
Definition: elog.h:26
int default_keepalives_count
Definition: libpq-be.h:162
pgsocket sock
Definition: libpq-be.h:118
int keepalives_count
Definition: libpq-be.h:165
#define IS_AF_UNIX(fam)
Definition: ip.h:24
#define STATUS_OK
Definition: c.h:975
SockAddr laddr
Definition: libpq-be.h:121
#define NULL
Definition: c.h:229
int pq_getkeepalivescount(Port *port)
Definition: pqcomm.c:1857
#define elog
Definition: elog.h:219
int pq_setkeepalivesidle ( int  idle,
Port port 
)

Definition at line 1721 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_idle, elog, IS_AF_UNIX, Port::keepalives_idle, Port::keepalives_interval, Port::laddr, LOG, NULL, pq_getkeepalivesidle(), Port::sock, STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_idle(), and StreamConnection().

1722 {
1723  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1724  return STATUS_OK;
1725 
1726 #if defined(TCP_KEEPIDLE) || defined(TCP_KEEPALIVE) || defined(SIO_KEEPALIVE_VALS)
1727  if (idle == port->keepalives_idle)
1728  return STATUS_OK;
1729 
1730 #ifndef WIN32
1731  if (port->default_keepalives_idle <= 0)
1732  {
1733  if (pq_getkeepalivesidle(port) < 0)
1734  {
1735  if (idle == 0)
1736  return STATUS_OK; /* default is set but unknown */
1737  else
1738  return STATUS_ERROR;
1739  }
1740  }
1741 
1742  if (idle == 0)
1743  idle = port->default_keepalives_idle;
1744 
1745 #ifdef TCP_KEEPIDLE
1746  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPIDLE,
1747  (char *) &idle, sizeof(idle)) < 0)
1748  {
1749  elog(LOG, "setsockopt(TCP_KEEPIDLE) failed: %m");
1750  return STATUS_ERROR;
1751  }
1752 #else
1753  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPALIVE,
1754  (char *) &idle, sizeof(idle)) < 0)
1755  {
1756  elog(LOG, "setsockopt(TCP_KEEPALIVE) failed: %m");
1757  return STATUS_ERROR;
1758  }
1759 #endif
1760 
1761  port->keepalives_idle = idle;
1762 #else /* WIN32 */
1763  return pq_setkeepaliveswin32(port, idle, port->keepalives_interval);
1764 #endif
1765 #else /* TCP_KEEPIDLE || SIO_KEEPALIVE_VALS */
1766  if (idle != 0)
1767  {
1768  elog(LOG, "setting the keepalive idle time is not supported");
1769  return STATUS_ERROR;
1770  }
1771 #endif
1772  return STATUS_OK;
1773 }
int keepalives_idle
Definition: libpq-be.h:163
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:976
#define LOG
Definition: elog.h:26
pgsocket sock
Definition: libpq-be.h:118
#define IS_AF_UNIX(fam)
Definition: ip.h:24
#define STATUS_OK
Definition: c.h:975
SockAddr laddr
Definition: libpq-be.h:121
int default_keepalives_idle
Definition: libpq-be.h:160
#define NULL
Definition: c.h:229
int pq_getkeepalivesidle(Port *port)
Definition: pqcomm.c:1677
#define elog
Definition: elog.h:219
int keepalives_interval
Definition: libpq-be.h:164
int pq_setkeepalivesinterval ( int  interval,
Port port 
)

Definition at line 1810 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_interval, elog, IS_AF_UNIX, Port::keepalives_idle, Port::keepalives_interval, Port::laddr, LOG, NULL, pq_getkeepalivesinterval(), Port::sock, STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_interval(), and StreamConnection().

1811 {
1812  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1813  return STATUS_OK;
1814 
1815 #if defined(TCP_KEEPINTVL) || defined (SIO_KEEPALIVE_VALS)
1816  if (interval == port->keepalives_interval)
1817  return STATUS_OK;
1818 
1819 #ifndef WIN32
1820  if (port->default_keepalives_interval <= 0)
1821  {
1822  if (pq_getkeepalivesinterval(port) < 0)
1823  {
1824  if (interval == 0)
1825  return STATUS_OK; /* default is set but unknown */
1826  else
1827  return STATUS_ERROR;
1828  }
1829  }
1830 
1831  if (interval == 0)
1833 
1834  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1835  (char *) &interval, sizeof(interval)) < 0)
1836  {
1837  elog(LOG, "setsockopt(TCP_KEEPINTVL) failed: %m");
1838  return STATUS_ERROR;
1839  }
1840 
1841  port->keepalives_interval = interval;
1842 #else /* WIN32 */
1843  return pq_setkeepaliveswin32(port, port->keepalives_idle, interval);
1844 #endif
1845 #else
1846  if (interval != 0)
1847  {
1848  elog(LOG, "setsockopt(TCP_KEEPINTVL) not supported");
1849  return STATUS_ERROR;
1850  }
1851 #endif
1852 
1853  return STATUS_OK;
1854 }
int keepalives_idle
Definition: libpq-be.h:163
int pq_getkeepalivesinterval(Port *port)
Definition: pqcomm.c:1776
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:976
#define LOG
Definition: elog.h:26
int default_keepalives_interval
Definition: libpq-be.h:161
pgsocket sock
Definition: libpq-be.h:118
#define IS_AF_UNIX(fam)
Definition: ip.h:24
#define STATUS_OK
Definition: c.h:975
SockAddr laddr
Definition: libpq-be.h:121
#define NULL
Definition: c.h:229
#define elog
Definition: elog.h:219
int keepalives_interval
Definition: libpq-be.h:164

Variable Documentation