|
PostgreSQL Source Code git master
|
#include "postgres.h"#include <poll.h>#include <signal.h>#include <fcntl.h>#include <grp.h>#include <unistd.h>#include <sys/file.h>#include <sys/socket.h>#include <sys/stat.h>#include <sys/time.h>#include <netdb.h>#include <netinet/in.h>#include <netinet/tcp.h>#include <utime.h>#include "common/ip.h"#include "libpq/libpq.h"#include "miscadmin.h"#include "port/pg_bswap.h"#include "postmaster/postmaster.h"#include "storage/ipc.h"#include "utils/guc_hooks.h"#include "utils/memutils.h"
Go to the source code of this file.
Macros | |
| #define | PQ_SEND_BUFFER_SIZE 8192 |
| #define | PQ_RECV_BUFFER_SIZE 8192 |
Functions | |
| static void | socket_comm_reset (void) |
| static void | socket_close (int code, Datum arg) |
| static void | socket_set_nonblocking (bool nonblocking) |
| static int | socket_flush (void) |
| static int | socket_flush_if_writable (void) |
| static bool | socket_is_send_pending (void) |
| static int | socket_putmessage (char msgtype, const char *s, size_t len) |
| static void | socket_putmessage_noblock (char msgtype, const char *s, size_t len) |
| static int | internal_putbytes (const void *b, size_t len) |
| static int | internal_flush (void) |
| static pg_noinline int | internal_flush_buffer (const char *buf, size_t *start, size_t *end) |
| static int | Lock_AF_UNIX (const char *unixSocketDir, const char *unixSocketPath) |
| static int | Setup_AF_UNIX (const char *sock_path) |
| Port * | pq_init (ClientSocket *client_sock) |
| int | ListenServerPort (int family, const char *hostName, unsigned short portNumber, const char *unixSocketDir, pgsocket ListenSockets[], int *NumListenSockets, int MaxListen) |
| int | AcceptConnection (pgsocket server_fd, ClientSocket *client_sock) |
| void | TouchSocketFiles (void) |
| void | RemoveSocketFiles (void) |
| static int | pq_recvbuf (void) |
| int | pq_getbyte (void) |
| int | pq_peekbyte (void) |
| int | pq_getbyte_if_available (unsigned char *c) |
| int | pq_getbytes (void *b, size_t len) |
| static int | pq_discardbytes (size_t len) |
| ssize_t | pq_buffer_remaining_data (void) |
| void | pq_startmsgread (void) |
| void | pq_endmsgread (void) |
| bool | pq_is_reading_msg (void) |
| int | pq_getmessage (StringInfo s, int maxlen) |
| int | pq_putmessage_v2 (char msgtype, const char *s, size_t len) |
| int | pq_getkeepalivesidle (Port *port) |
| int | pq_setkeepalivesidle (int idle, Port *port) |
| int | pq_getkeepalivesinterval (Port *port) |
| int | pq_setkeepalivesinterval (int interval, Port *port) |
| int | pq_getkeepalivescount (Port *port) |
| int | pq_setkeepalivescount (int count, Port *port) |
| int | pq_gettcpusertimeout (Port *port) |
| int | pq_settcpusertimeout (int timeout, Port *port) |
| void | assign_tcp_keepalives_idle (int newval, void *extra) |
| const char * | show_tcp_keepalives_idle (void) |
| void | assign_tcp_keepalives_interval (int newval, void *extra) |
| const char * | show_tcp_keepalives_interval (void) |
| void | assign_tcp_keepalives_count (int newval, void *extra) |
| const char * | show_tcp_keepalives_count (void) |
| void | assign_tcp_user_timeout (int newval, void *extra) |
| const char * | show_tcp_user_timeout (void) |
| bool | pq_check_connection (void) |
Variables | |
| int | Unix_socket_permissions |
| char * | Unix_socket_group |
| static List * | sock_paths = NIL |
| static char * | PqSendBuffer |
| static int | PqSendBufferSize |
| static size_t | PqSendPointer |
| static size_t | PqSendStart |
| static char | PqRecvBuffer [PQ_RECV_BUFFER_SIZE] |
| static int | PqRecvPointer |
| static int | PqRecvLength |
| static bool | PqCommBusy |
| static bool | PqCommReadingMsg |
| static const PQcommMethods | PqCommSocketMethods |
| const PQcommMethods * | PqCommMethods = &PqCommSocketMethods |
| WaitEventSet * | FeBeWaitSet |
| int AcceptConnection | ( | pgsocket | server_fd, |
| ClientSocket * | client_sock | ||
| ) |
Definition at line 794 of file pqcomm.c.
References accept, SockAddr::addr, ereport, errcode_for_socket_access(), errmsg(), LOG, pg_usleep(), PGINVALID_SOCKET, ClientSocket::raddr, SockAddr::salen, ClientSocket::sock, STATUS_ERROR, and STATUS_OK.
Referenced by ServerLoop().
| void assign_tcp_keepalives_count | ( | int | newval, |
| void * | extra | ||
| ) |
Definition at line 2010 of file pqcomm.c.
References MyProcPort, newval, and pq_setkeepalivescount().
| void assign_tcp_keepalives_idle | ( | int | newval, |
| void * | extra | ||
| ) |
Definition at line 1954 of file pqcomm.c.
References MyProcPort, newval, and pq_setkeepalivesidle().
| void assign_tcp_keepalives_interval | ( | int | newval, |
| void * | extra | ||
| ) |
Definition at line 1987 of file pqcomm.c.
References MyProcPort, newval, and pq_setkeepalivesinterval().
| void assign_tcp_user_timeout | ( | int | newval, |
| void * | extra | ||
| ) |
Definition at line 2033 of file pqcomm.c.
References MyProcPort, newval, and pq_settcpusertimeout().
|
inlinestatic |
Definition at line 1349 of file pqcomm.c.
References internal_flush_buffer(), PqSendBuffer, PqSendPointer, and PqSendStart.
Referenced by internal_putbytes(), socket_flush(), and socket_flush_if_writable().
|
static |
Definition at line 1362 of file pqcomm.c.
References buf, ClientConnectionLost, COMMERROR, EAGAIN, EINTR, ereport, errcode_for_socket_access(), errmsg(), EWOULDBLOCK, InterruptPending, MyProcPort, secure_write(), and start.
Referenced by internal_flush(), and internal_putbytes().
|
inlinestatic |
Definition at line 1277 of file pqcomm.c.
References b, internal_flush(), internal_flush_buffer(), len, PqSendBuffer, PqSendBufferSize, PqSendPointer, PqSendStart, socket_set_nonblocking(), and start.
Referenced by pq_putmessage_v2(), and socket_putmessage().
| int ListenServerPort | ( | int | family, |
| const char * | hostName, | ||
| unsigned short | portNumber, | ||
| const char * | unixSocketDir, | ||
| pgsocket | ListenSockets[], | ||
| int * | NumListenSockets, | ||
| int | MaxListen | ||
| ) |
Definition at line 418 of file pqcomm.c.
References _, bind, closesocket, EADDRINUSE, elog, ereport, err(), errcode_for_socket_access(), errhint(), errmsg(), FATAL, fd(), gai_strerror(), listen, ListenSockets, Lock_AF_UNIX(), LOG, MaxConnections, MAXPGPATH, MemSet, NumListenSockets, pg_freeaddrinfo_all(), pg_getaddrinfo_all(), pg_getnameinfo_all(), PGINVALID_SOCKET, Setup_AF_UNIX(), snprintf, socket, STATUS_ERROR, STATUS_OK, UNIXSOCK_PATH, and UNIXSOCK_PATH_BUFLEN.
Referenced by PostmasterMain().
|
static |
Definition at line 685 of file pqcomm.c.
References CreateSocketLockFile(), lappend(), pstrdup(), sock_paths, and STATUS_OK.
Referenced by ListenServerPort().
| ssize_t pq_buffer_remaining_data | ( | void | ) |
Definition at line 1127 of file pqcomm.c.
References Assert(), PqRecvLength, and PqRecvPointer.
Referenced by ProcessStartupPacket(), and secure_open_server().
| bool pq_check_connection | ( | void | ) |
Definition at line 2056 of file pqcomm.c.
References FeBeWaitSet, FeBeWaitSetNEvents, FeBeWaitSetSocketPos, i, lengthof, ModifyWaitEvent(), MyLatch, ResetLatch(), WaitEventSetWait(), WL_LATCH_SET, and WL_SOCKET_CLOSED.
Referenced by ProcessInterrupts().
|
static |
Definition at line 1097 of file pqcomm.c.
References Assert(), len, pq_recvbuf(), PqCommReadingMsg, PqRecvLength, and PqRecvPointer.
Referenced by pq_getmessage().
| void pq_endmsgread | ( | void | ) |
Definition at line 1165 of file pqcomm.c.
References Assert(), and PqCommReadingMsg.
Referenced by ProcessRepliesIfAny(), ProcessSSLStartup(), ProcessStartupPacket(), and secure_open_server().
| int pq_getbyte | ( | void | ) |
Definition at line 963 of file pqcomm.c.
References Assert(), pq_recvbuf(), PqCommReadingMsg, PqRecvBuffer, PqRecvLength, and PqRecvPointer.
Referenced by CheckSASLAuth(), CopyGetData(), HandleUploadManifestPacket(), recv_password_packet(), and SocketBackend().
| int pq_getbyte_if_available | ( | unsigned char * | c | ) |
Definition at line 1003 of file pqcomm.c.
References Assert(), COMMERROR, EAGAIN, EINTR, ereport, errcode_for_socket_access(), errmsg(), EWOULDBLOCK, MyProcPort, PqCommReadingMsg, PqRecvBuffer, PqRecvLength, PqRecvPointer, secure_read(), and socket_set_nonblocking().
Referenced by ProcessRepliesIfAny().
| int pq_getbytes | ( | void * | b, |
| size_t | len | ||
| ) |
Definition at line 1062 of file pqcomm.c.
References Assert(), b, len, pq_recvbuf(), PqCommReadingMsg, PqRecvBuffer, PqRecvLength, and PqRecvPointer.
Referenced by pq_getmessage(), ProcessStartupPacket(), and secure_open_server().
| int pq_getkeepalivescount | ( | Port * | port | ) |
Definition at line 1801 of file pqcomm.c.
References ereport, errmsg(), LOG, and port.
Referenced by pq_setkeepalivescount(), and show_tcp_keepalives_count().
| int pq_getkeepalivesidle | ( | Port * | port | ) |
Definition at line 1632 of file pqcomm.c.
References ereport, errmsg(), LOG, and port.
Referenced by pq_setkeepalivesidle(), and show_tcp_keepalives_idle().
| int pq_getkeepalivesinterval | ( | Port * | port | ) |
Definition at line 1717 of file pqcomm.c.
References ereport, errmsg(), LOG, and port.
Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().
| int pq_getmessage | ( | StringInfo | s, |
| int | maxlen | ||
| ) |
Definition at line 1203 of file pqcomm.c.
References Assert(), COMMERROR, StringInfoData::data, enlargeStringInfo(), ereport, errcode(), errmsg(), StringInfoData::len, len, PG_CATCH, PG_END_TRY, pg_ntoh32, PG_RE_THROW, PG_TRY, pq_discardbytes(), pq_getbytes(), PqCommReadingMsg, and resetStringInfo().
Referenced by CheckSASLAuth(), CopyGetData(), HandleUploadManifestPacket(), ProcessRepliesIfAny(), recv_password_packet(), and SocketBackend().
| int pq_gettcpusertimeout | ( | Port * | port | ) |
Definition at line 1876 of file pqcomm.c.
References ereport, errmsg(), LOG, and port.
Referenced by pq_settcpusertimeout(), and show_tcp_user_timeout().
| Port * pq_init | ( | ClientSocket * | client_sock | ) |
Definition at line 174 of file pqcomm.c.
References SockAddr::addr, AddWaitEventToSet(), Assert(), CreateWaitEventSet(), elog, ereport, errmsg(), FATAL, FeBeWaitSet, FeBeWaitSetLatchPos, FeBeWaitSetNEvents, FeBeWaitSetSocketPos, MemoryContextAlloc(), MyLatch, on_proc_exit(), palloc0(), pg_set_noblock(), PG_USED_FOR_ASSERTS_ONLY, PGINVALID_SOCKET, port, PQ_SEND_BUFFER_SIZE, pq_setkeepalivescount(), pq_setkeepalivesidle(), pq_setkeepalivesinterval(), pq_settcpusertimeout(), PqCommBusy, PqCommReadingMsg, PqRecvLength, PqRecvPointer, PqSendBuffer, PqSendBufferSize, PqSendPointer, PqSendStart, ClientSocket::raddr, SockAddr::salen, ClientSocket::sock, socket_close(), tcp_keepalives_count, tcp_keepalives_idle, tcp_keepalives_interval, tcp_user_timeout, TopMemoryContext, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_SOCKET_WRITEABLE.
Referenced by BackendInitialize().
| bool pq_is_reading_msg | ( | void | ) |
Definition at line 1181 of file pqcomm.c.
References PqCommReadingMsg.
Referenced by PostgresMain().
| int pq_peekbyte | ( | void | ) |
Definition at line 982 of file pqcomm.c.
References Assert(), pq_recvbuf(), PqCommReadingMsg, PqRecvBuffer, PqRecvLength, and PqRecvPointer.
Referenced by ProcessSSLStartup().
| int pq_putmessage_v2 | ( | char | msgtype, |
| const char * | s, | ||
| size_t | len | ||
| ) |
Definition at line 1561 of file pqcomm.c.
References Assert(), internal_putbytes(), len, and PqCommBusy.
Referenced by send_message_to_frontend().
|
static |
Definition at line 897 of file pqcomm.c.
References COMMERROR, EINTR, ereport, errcode_for_socket_access(), errmsg(), MyProcPort, PQ_RECV_BUFFER_SIZE, PqRecvBuffer, PqRecvLength, PqRecvPointer, secure_read(), and socket_set_nonblocking().
Referenced by pq_discardbytes(), pq_getbyte(), pq_getbytes(), and pq_peekbyte().
| int pq_setkeepalivescount | ( | int | count, |
| Port * | port | ||
| ) |
Definition at line 1831 of file pqcomm.c.
References ereport, errmsg(), LOG, port, pq_getkeepalivescount(), STATUS_ERROR, and STATUS_OK.
Referenced by assign_tcp_keepalives_count(), and pq_init().
| int pq_setkeepalivesidle | ( | int | idle, |
| Port * | port | ||
| ) |
Definition at line 1667 of file pqcomm.c.
References ereport, errmsg(), LOG, port, pq_getkeepalivesidle(), STATUS_ERROR, and STATUS_OK.
Referenced by assign_tcp_keepalives_idle(), and pq_init().
| int pq_setkeepalivesinterval | ( | int | interval, |
| Port * | port | ||
| ) |
Definition at line 1752 of file pqcomm.c.
References ereport, errmsg(), LOG, port, pq_getkeepalivesinterval(), STATUS_ERROR, and STATUS_OK.
Referenced by assign_tcp_keepalives_interval(), and pq_init().
| int pq_settcpusertimeout | ( | int | timeout, |
| Port * | port | ||
| ) |
Definition at line 1906 of file pqcomm.c.
References ereport, errmsg(), LOG, port, pq_gettcpusertimeout(), STATUS_ERROR, and STATUS_OK.
Referenced by assign_tcp_user_timeout(), and pq_init().
| void pq_startmsgread | ( | void | ) |
Definition at line 1141 of file pqcomm.c.
References ereport, errcode(), errmsg(), FATAL, and PqCommReadingMsg.
Referenced by CheckSASLAuth(), CopyGetData(), HandleUploadManifestPacket(), ProcessRepliesIfAny(), ProcessSSLStartup(), ProcessStartupPacket(), recv_password_packet(), secure_open_server(), and SocketBackend().
| void RemoveSocketFiles | ( | void | ) |
Definition at line 848 of file pqcomm.c.
References lfirst, and sock_paths.
Referenced by CloseServerPorts().
|
static |
Definition at line 720 of file pqcomm.c.
References Assert(), elog, ereport, errcode_for_file_access(), errmsg(), LOG, STATUS_ERROR, STATUS_OK, Unix_socket_group, Unix_socket_permissions, val, and WARNING.
Referenced by ListenServerPort().
| const char * show_tcp_keepalives_count | ( | void | ) |
Definition at line 2020 of file pqcomm.c.
References MyProcPort, pq_getkeepalivescount(), and snprintf.
| const char * show_tcp_keepalives_idle | ( | void | ) |
Definition at line 1974 of file pqcomm.c.
References MyProcPort, pq_getkeepalivesidle(), and snprintf.
| const char * show_tcp_keepalives_interval | ( | void | ) |
Definition at line 1997 of file pqcomm.c.
References MyProcPort, pq_getkeepalivesinterval(), and snprintf.
| const char * show_tcp_user_timeout | ( | void | ) |
Definition at line 2043 of file pqcomm.c.
References MyProcPort, pq_gettcpusertimeout(), and snprintf.
|
static |
Definition at line 349 of file pqcomm.c.
References Port::gss, MyProcPort, PGINVALID_SOCKET, secure_close(), and Port::sock.
Referenced by pq_init().
|
static |
Definition at line 334 of file pqcomm.c.
References PqCommBusy.
|
static |
Definition at line 1327 of file pqcomm.c.
References internal_flush(), PqCommBusy, and socket_set_nonblocking().
|
static |
Definition at line 1435 of file pqcomm.c.
References internal_flush(), PqCommBusy, PqSendPointer, PqSendStart, and socket_set_nonblocking().
|
static |
Definition at line 1461 of file pqcomm.c.
References PqSendPointer, and PqSendStart.
|
static |
Definition at line 1491 of file pqcomm.c.
References Assert(), internal_putbytes(), len, pg_hton32, and PqCommBusy.
|
static |
Definition at line 1524 of file pqcomm.c.
References Assert(), len, PG_USED_FOR_ASSERTS_ONLY, pq_putmessage, PqSendBuffer, PqSendBufferSize, PqSendPointer, repalloc(), and generate_unaccent_rules::required.
|
static |
Definition at line 880 of file pqcomm.c.
References ereport, errcode(), errmsg(), ERROR, MyProcPort, and Port::noblock.
Referenced by internal_putbytes(), pq_getbyte_if_available(), pq_recvbuf(), socket_flush(), and socket_flush_if_writable().
| void TouchSocketFiles | ( | void | ) |
Definition at line 830 of file pqcomm.c.
References lfirst, and sock_paths.
Referenced by ServerLoop().
| WaitEventSet* FeBeWaitSet |
Definition at line 166 of file pqcomm.c.
Referenced by pq_check_connection(), pq_init(), secure_read(), secure_write(), SwitchBackToLocalLatch(), SwitchToSharedLatch(), and WalSndWait().
|
static |
Definition at line 134 of file pqcomm.c.
Referenced by pq_init(), pq_putmessage_v2(), socket_comm_reset(), socket_flush(), socket_flush_if_writable(), and socket_putmessage().
| const PQcommMethods* PqCommMethods = &PqCommSocketMethods |
Definition at line 164 of file pqcomm.c.
Referenced by pq_redirect_to_shm_mq(), and pq_set_parallel_leader().
|
static |
Definition at line 135 of file pqcomm.c.
Referenced by pq_discardbytes(), pq_endmsgread(), pq_getbyte(), pq_getbyte_if_available(), pq_getbytes(), pq_getmessage(), pq_init(), pq_is_reading_msg(), pq_peekbyte(), and pq_startmsgread().
|
static |
|
static |
Definition at line 127 of file pqcomm.c.
Referenced by pq_getbyte(), pq_getbyte_if_available(), pq_getbytes(), pq_peekbyte(), and pq_recvbuf().
|
static |
Definition at line 129 of file pqcomm.c.
Referenced by pq_buffer_remaining_data(), pq_discardbytes(), pq_getbyte(), pq_getbyte_if_available(), pq_getbytes(), pq_init(), pq_peekbyte(), and pq_recvbuf().
|
static |
Definition at line 128 of file pqcomm.c.
Referenced by pq_buffer_remaining_data(), pq_discardbytes(), pq_getbyte(), pq_getbyte_if_available(), pq_getbytes(), pq_init(), pq_peekbyte(), and pq_recvbuf().
|
static |
Definition at line 122 of file pqcomm.c.
Referenced by internal_flush(), internal_putbytes(), pq_init(), and socket_putmessage_noblock().
|
static |
Definition at line 123 of file pqcomm.c.
Referenced by internal_putbytes(), pq_init(), and socket_putmessage_noblock().
|
static |
Definition at line 124 of file pqcomm.c.
Referenced by internal_flush(), internal_putbytes(), pq_init(), socket_flush_if_writable(), socket_is_send_pending(), and socket_putmessage_noblock().
|
static |
Definition at line 125 of file pqcomm.c.
Referenced by internal_flush(), internal_putbytes(), pq_init(), socket_flush_if_writable(), and socket_is_send_pending().
Definition at line 110 of file pqcomm.c.
Referenced by Lock_AF_UNIX(), RemoveSocketFiles(), and TouchSocketFiles().
| char* Unix_socket_group |
Definition at line 107 of file pqcomm.c.
Referenced by Setup_AF_UNIX().
| int Unix_socket_permissions |
Definition at line 106 of file pqcomm.c.
Referenced by Setup_AF_UNIX(), and show_unix_socket_permissions().