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

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

Referenced by pq_setkeepalivescount(), and show_tcp_keepalives_count().

1860 {
1861 #ifdef TCP_KEEPCNT
1862  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1863  return 0;
1864 
1865  if (port->keepalives_count != 0)
1866  return port->keepalives_count;
1867 
1868  if (port->default_keepalives_count == 0)
1869  {
1870  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_count);
1871 
1872  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1873  (char *) &port->default_keepalives_count,
1874  &size) < 0)
1875  {
1876  elog(LOG, "getsockopt(%s) failed: %m", "TCP_KEEPCNT");
1877  port->default_keepalives_count = -1; /* don't know */
1878  }
1879  }
1880 
1881  return port->default_keepalives_count;
1882 #else
1883  return 0;
1884 #endif
1885 }
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 elog
Definition: elog.h:219
int pq_getkeepalivesidle ( Port port)

Definition at line 1696 of file pqcomm.c.

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

Referenced by pq_setkeepalivesidle(), and show_tcp_keepalives_idle().

1697 {
1698 #if defined(PG_TCP_KEEPALIVE_IDLE) || defined(SIO_KEEPALIVE_VALS)
1699  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1700  return 0;
1701 
1702  if (port->keepalives_idle != 0)
1703  return port->keepalives_idle;
1704 
1705  if (port->default_keepalives_idle == 0)
1706  {
1707 #ifndef WIN32
1708  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_idle);
1709 
1710  if (getsockopt(port->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
1711  (char *) &port->default_keepalives_idle,
1712  &size) < 0)
1713  {
1714  elog(LOG, "getsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_IDLE_STR);
1715  port->default_keepalives_idle = -1; /* don't know */
1716  }
1717 #else /* WIN32 */
1718  /* We can't get the defaults on Windows, so return "don't know" */
1719  port->default_keepalives_idle = -1;
1720 #endif /* WIN32 */
1721  }
1722 
1723  return port->default_keepalives_idle;
1724 #else
1725  return 0;
1726 #endif
1727 }
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 elog
Definition: elog.h:219
int pq_getkeepalivesinterval ( Port port)

Definition at line 1778 of file pqcomm.c.

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

Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().

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

Definition at line 1888 of file pqcomm.c.

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

Referenced by assign_tcp_keepalives_count(), and StreamConnection().

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

Definition at line 1730 of file pqcomm.c.

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

Referenced by assign_tcp_keepalives_idle(), and StreamConnection().

1731 {
1732  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1733  return STATUS_OK;
1734 
1735 /* check SIO_KEEPALIVE_VALS here, not just WIN32, as some toolchains lack it */
1736 #if defined(PG_TCP_KEEPALIVE_IDLE) || defined(SIO_KEEPALIVE_VALS)
1737  if (idle == port->keepalives_idle)
1738  return STATUS_OK;
1739 
1740 #ifndef WIN32
1741  if (port->default_keepalives_idle <= 0)
1742  {
1743  if (pq_getkeepalivesidle(port) < 0)
1744  {
1745  if (idle == 0)
1746  return STATUS_OK; /* default is set but unknown */
1747  else
1748  return STATUS_ERROR;
1749  }
1750  }
1751 
1752  if (idle == 0)
1753  idle = port->default_keepalives_idle;
1754 
1755  if (setsockopt(port->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
1756  (char *) &idle, sizeof(idle)) < 0)
1757  {
1758  elog(LOG, "setsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_IDLE_STR);
1759  return STATUS_ERROR;
1760  }
1761 
1762  port->keepalives_idle = idle;
1763 #else /* WIN32 */
1764  return pq_setkeepaliveswin32(port, idle, port->keepalives_interval);
1765 #endif
1766 #else
1767  if (idle != 0)
1768  {
1769  elog(LOG, "setting the keepalive idle time is not supported");
1770  return STATUS_ERROR;
1771  }
1772 #endif
1773 
1774  return STATUS_OK;
1775 }
int keepalives_idle
Definition: libpq-be.h:163
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:982
#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:981
SockAddr laddr
Definition: libpq-be.h:121
int default_keepalives_idle
Definition: libpq-be.h:160
int pq_getkeepalivesidle(Port *port)
Definition: pqcomm.c:1696
#define elog
Definition: elog.h:219
int keepalives_interval
Definition: libpq-be.h:164
int pq_setkeepalivesinterval ( int  interval,
Port port 
)

Definition at line 1812 of file pqcomm.c.

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

Referenced by assign_tcp_keepalives_interval(), and StreamConnection().

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

Variable Documentation