PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
libpq-be.h File Reference
#include "common/scram-common.h"
#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 1802 of file pqcomm.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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