PostgreSQL Source Code git master
Data Structures | Typedefs | Functions | Variables
libpq-be.h File Reference
#include "common/scram-common.h"
#include <sys/time.h>
#include <netinet/tcp.h>
#include "libpq/pg-gssapi.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
 
struct   ClientSocket
 

Typedefs

 
typedef struct Port  Port
 
typedef struct ClientSocket  ClientSocket
 

Functions

 
 
 
 
int  pq_setkeepalivesidle (int idle, Port *port)
 
 
int  pq_setkeepalivescount (int count, Port *port)
 
int  pq_settcpusertimeout (int timeout, Port *port)
 

Variables

 
 

Typedef Documentation

ClientConnectionInfo

ClientSocket

typedef struct ClientSocket ClientSocket

Port

typedef struct Port Port

Function Documentation

pq_getkeepalivescount()

int pq_getkeepalivescount ( Portport )

Definition at line 1801 of file pqcomm.c.

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

Definition at line 1632 of file pqcomm.c.

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

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

Referenced by pq_setkeepalivesidle(), and show_tcp_keepalives_idle().

pq_getkeepalivesinterval()

int pq_getkeepalivesinterval ( Portport )

Definition at line 1717 of file pqcomm.c.

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

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

Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().

pq_gettcpusertimeout()

int pq_gettcpusertimeout ( Portport )

Definition at line 1876 of file pqcomm.c.

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

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

Referenced by pq_settcpusertimeout(), and show_tcp_user_timeout().

pq_setkeepalivescount()

int pq_setkeepalivescount ( int  count,
Portport 
)

Definition at line 1831 of file pqcomm.c.

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

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,
Portport 
)

Definition at line 1667 of file pqcomm.c.

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

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,
Portport 
)

Definition at line 1752 of file pqcomm.c.

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

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,
Portport 
)

Definition at line 1906 of file pqcomm.c.

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

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

Referenced by assign_tcp_user_timeout(), and pq_init().

Variable Documentation

FrontendProtocol

PGDLLIMPORT ProtocolVersion FrontendProtocol
extern

Definition at line 30 of file globals.c.

Referenced by BackendInitialize(), pq_redirect_to_shm_mq(), process_postgres_switches(), ProcessStartupPacket(), send_message_to_frontend(), and SendNegotiateProtocolVersion().

MyClientConnectionInfo

PGDLLIMPORT ClientConnectionInfo MyClientConnectionInfo
extern

Definition at line 1018 of file miscinit.c.

Referenced by auth_peer(), ClientAuthentication(), EstimateClientConnectionInfoSpace(), InitPostgres(), ParallelWorkerMain(), RestoreClientConnectionInfo(), SerializeClientConnectionInfo(), set_authn_id(), and validate().

AltStyle によって変換されたページ (->オリジナル) /