PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
libpq-be.h File Reference
#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 73 of file libpq-be.h.

Function Documentation

int pq_getkeepalivescount ( Port port)

Definition at line 1823 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().

1824 {
1825 #ifdef TCP_KEEPCNT
1826  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1827  return 0;
1828 
1829  if (port->keepalives_count != 0)
1830  return port->keepalives_count;
1831 
1832  if (port->default_keepalives_count == 0)
1833  {
1834  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_count);
1835 
1836  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1837  (char *) &port->default_keepalives_count,
1838  &size) < 0)
1839  {
1840  elog(LOG, "getsockopt(TCP_KEEPCNT) failed: %m");
1841  port->default_keepalives_count = -1; /* don't know */
1842  }
1843  }
1844 
1845  return port->default_keepalives_count;
1846 #else
1847  return 0;
1848 #endif
1849 }
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define LOG
Definition: elog.h:26
int default_keepalives_count
Definition: libpq-be.h:164
pgsocket sock
Definition: libpq-be.h:120
int keepalives_count
Definition: libpq-be.h:167
#define IS_AF_UNIX(fam)
Definition: ip.h:24
SockAddr laddr
Definition: libpq-be.h:123
#define NULL
Definition: c.h:226
#define elog
Definition: elog.h:219
int pq_getkeepalivesidle ( Port port)

Definition at line 1643 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().

1644 {
1645 #if defined(TCP_KEEPIDLE) || defined(TCP_KEEPALIVE) || defined(WIN32)
1646  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1647  return 0;
1648 
1649  if (port->keepalives_idle != 0)
1650  return port->keepalives_idle;
1651 
1652  if (port->default_keepalives_idle == 0)
1653  {
1654 #ifndef WIN32
1655  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_idle);
1656 
1657 #ifdef TCP_KEEPIDLE
1658  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPIDLE,
1659  (char *) &port->default_keepalives_idle,
1660  &size) < 0)
1661  {
1662  elog(LOG, "getsockopt(TCP_KEEPIDLE) failed: %m");
1663  port->default_keepalives_idle = -1; /* don't know */
1664  }
1665 #else
1666  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPALIVE,
1667  (char *) &port->default_keepalives_idle,
1668  &size) < 0)
1669  {
1670  elog(LOG, "getsockopt(TCP_KEEPALIVE) failed: %m");
1671  port->default_keepalives_idle = -1; /* don't know */
1672  }
1673 #endif /* TCP_KEEPIDLE */
1674 #else /* WIN32 */
1675  /* We can't get the defaults on Windows, so return "don't know" */
1676  port->default_keepalives_idle = -1;
1677 #endif /* WIN32 */
1678  }
1679 
1680  return port->default_keepalives_idle;
1681 #else
1682  return 0;
1683 #endif
1684 }
int keepalives_idle
Definition: libpq-be.h:165
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define LOG
Definition: elog.h:26
pgsocket sock
Definition: libpq-be.h:120
#define IS_AF_UNIX(fam)
Definition: ip.h:24
SockAddr laddr
Definition: libpq-be.h:123
int default_keepalives_idle
Definition: libpq-be.h:162
#define NULL
Definition: c.h:226
#define elog
Definition: elog.h:219
int pq_getkeepalivesinterval ( Port port)

Definition at line 1742 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().

1743 {
1744 #if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
1745  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1746  return 0;
1747 
1748  if (port->keepalives_interval != 0)
1749  return port->keepalives_interval;
1750 
1751  if (port->default_keepalives_interval == 0)
1752  {
1753 #ifndef WIN32
1754  ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_interval);
1755 
1756  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1757  (char *) &port->default_keepalives_interval,
1758  &size) < 0)
1759  {
1760  elog(LOG, "getsockopt(TCP_KEEPINTVL) failed: %m");
1761  port->default_keepalives_interval = -1; /* don't know */
1762  }
1763 #else
1764  /* We can't get the defaults on Windows, so return "don't know" */
1765  port->default_keepalives_interval = -1;
1766 #endif /* WIN32 */
1767  }
1768 
1769  return port->default_keepalives_interval;
1770 #else
1771  return 0;
1772 #endif
1773 }
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define LOG
Definition: elog.h:26
int default_keepalives_interval
Definition: libpq-be.h:163
pgsocket sock
Definition: libpq-be.h:120
#define IS_AF_UNIX(fam)
Definition: ip.h:24
SockAddr laddr
Definition: libpq-be.h:123
#define NULL
Definition: c.h:226
#define elog
Definition: elog.h:219
int keepalives_interval
Definition: libpq-be.h:166
int pq_setkeepalivescount ( int  count,
Port port 
)

Definition at line 1852 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().

1853 {
1854  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1855  return STATUS_OK;
1856 
1857 #ifdef TCP_KEEPCNT
1858  if (count == port->keepalives_count)
1859  return STATUS_OK;
1860 
1861  if (port->default_keepalives_count <= 0)
1862  {
1863  if (pq_getkeepalivescount(port) < 0)
1864  {
1865  if (count == 0)
1866  return STATUS_OK; /* default is set but unknown */
1867  else
1868  return STATUS_ERROR;
1869  }
1870  }
1871 
1872  if (count == 0)
1873  count = port->default_keepalives_count;
1874 
1875  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1876  (char *) &count, sizeof(count)) < 0)
1877  {
1878  elog(LOG, "setsockopt(TCP_KEEPCNT) failed: %m");
1879  return STATUS_ERROR;
1880  }
1881 
1882  port->keepalives_count = count;
1883 #else
1884  if (count != 0)
1885  {
1886  elog(LOG, "setsockopt(TCP_KEEPCNT) not supported");
1887  return STATUS_ERROR;
1888  }
1889 #endif
1890 
1891  return STATUS_OK;
1892 }
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:972
#define LOG
Definition: elog.h:26
int default_keepalives_count
Definition: libpq-be.h:164
pgsocket sock
Definition: libpq-be.h:120
int keepalives_count
Definition: libpq-be.h:167
#define IS_AF_UNIX(fam)
Definition: ip.h:24
#define STATUS_OK
Definition: c.h:971
SockAddr laddr
Definition: libpq-be.h:123
#define NULL
Definition: c.h:226
int pq_getkeepalivescount(Port *port)
Definition: pqcomm.c:1823
#define elog
Definition: elog.h:219
int pq_setkeepalivesidle ( int  idle,
Port port 
)

Definition at line 1687 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().

1688 {
1689  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1690  return STATUS_OK;
1691 
1692 #if defined(TCP_KEEPIDLE) || defined(TCP_KEEPALIVE) || defined(SIO_KEEPALIVE_VALS)
1693  if (idle == port->keepalives_idle)
1694  return STATUS_OK;
1695 
1696 #ifndef WIN32
1697  if (port->default_keepalives_idle <= 0)
1698  {
1699  if (pq_getkeepalivesidle(port) < 0)
1700  {
1701  if (idle == 0)
1702  return STATUS_OK; /* default is set but unknown */
1703  else
1704  return STATUS_ERROR;
1705  }
1706  }
1707 
1708  if (idle == 0)
1709  idle = port->default_keepalives_idle;
1710 
1711 #ifdef TCP_KEEPIDLE
1712  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPIDLE,
1713  (char *) &idle, sizeof(idle)) < 0)
1714  {
1715  elog(LOG, "setsockopt(TCP_KEEPIDLE) failed: %m");
1716  return STATUS_ERROR;
1717  }
1718 #else
1719  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPALIVE,
1720  (char *) &idle, sizeof(idle)) < 0)
1721  {
1722  elog(LOG, "setsockopt(TCP_KEEPALIVE) failed: %m");
1723  return STATUS_ERROR;
1724  }
1725 #endif
1726 
1727  port->keepalives_idle = idle;
1728 #else /* WIN32 */
1729  return pq_setkeepaliveswin32(port, idle, port->keepalives_interval);
1730 #endif
1731 #else /* TCP_KEEPIDLE || SIO_KEEPALIVE_VALS */
1732  if (idle != 0)
1733  {
1734  elog(LOG, "setting the keepalive idle time is not supported");
1735  return STATUS_ERROR;
1736  }
1737 #endif
1738  return STATUS_OK;
1739 }
int keepalives_idle
Definition: libpq-be.h:165
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:972
#define LOG
Definition: elog.h:26
pgsocket sock
Definition: libpq-be.h:120
#define IS_AF_UNIX(fam)
Definition: ip.h:24
#define STATUS_OK
Definition: c.h:971
SockAddr laddr
Definition: libpq-be.h:123
int default_keepalives_idle
Definition: libpq-be.h:162
#define NULL
Definition: c.h:226
int pq_getkeepalivesidle(Port *port)
Definition: pqcomm.c:1643
#define elog
Definition: elog.h:219
int keepalives_interval
Definition: libpq-be.h:166
int pq_setkeepalivesinterval ( int  interval,
Port port 
)

Definition at line 1776 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().

1777 {
1778  if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1779  return STATUS_OK;
1780 
1781 #if defined(TCP_KEEPINTVL) || defined (SIO_KEEPALIVE_VALS)
1782  if (interval == port->keepalives_interval)
1783  return STATUS_OK;
1784 
1785 #ifndef WIN32
1786  if (port->default_keepalives_interval <= 0)
1787  {
1788  if (pq_getkeepalivesinterval(port) < 0)
1789  {
1790  if (interval == 0)
1791  return STATUS_OK; /* default is set but unknown */
1792  else
1793  return STATUS_ERROR;
1794  }
1795  }
1796 
1797  if (interval == 0)
1799 
1800  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1801  (char *) &interval, sizeof(interval)) < 0)
1802  {
1803  elog(LOG, "setsockopt(TCP_KEEPINTVL) failed: %m");
1804  return STATUS_ERROR;
1805  }
1806 
1807  port->keepalives_interval = interval;
1808 #else /* WIN32 */
1809  return pq_setkeepaliveswin32(port, port->keepalives_idle, interval);
1810 #endif
1811 #else
1812  if (interval != 0)
1813  {
1814  elog(LOG, "setsockopt(TCP_KEEPINTVL) not supported");
1815  return STATUS_ERROR;
1816  }
1817 #endif
1818 
1819  return STATUS_OK;
1820 }
int keepalives_idle
Definition: libpq-be.h:165
int pq_getkeepalivesinterval(Port *port)
Definition: pqcomm.c:1742
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define STATUS_ERROR
Definition: c.h:972
#define LOG
Definition: elog.h:26
int default_keepalives_interval
Definition: libpq-be.h:163
pgsocket sock
Definition: libpq-be.h:120
#define IS_AF_UNIX(fam)
Definition: ip.h:24
#define STATUS_OK
Definition: c.h:971
SockAddr laddr
Definition: libpq-be.h:123
#define NULL
Definition: c.h:226
#define elog
Definition: elog.h:219
int keepalives_interval
Definition: libpq-be.h:166

Variable Documentation