diff options
| author | Heikki Linnakangas | 2024-03-12 11:42:38 +0000 |
|---|---|---|
| committer | Heikki Linnakangas | 2024-03-12 11:42:38 +0000 |
| commit | 4945e4ed4a72c3ff41560ccef722c3d70ae07dbb (patch) | |
| tree | f5e98b8bc2cc4734e02b0bca72e98bf7ddeec616 /src/include/libpq | |
| parent | d162c3a73bf14416ff4012de6f01c3d825610f70 (diff) | |
Move initialization of the Port struct to the child process
In postmaster, use a more lightweight ClientSocket struct that
encapsulates just the socket itself and the remote endpoint's address
that you get from accept() call. ClientSocket is passed to the child
process, which initializes the bigger Port struct. This makes it more
clear what information postmaster initializes, and what is left to the
child process.
Rename the StreamServerPort and StreamConnection functions to make it
more clear what they do. Remove StreamClose, replacing it with plain
closesocket() calls.
Reviewed-by: Tristan Partin, Andres Freund
Discussion: https://www.postgresql.org/message-id/7a59b073-5b5b-151e-7ed3-8b01ff7ce9ef@iki.fi
Diffstat (limited to 'src/include/libpq')
| -rw-r--r-- | src/include/libpq/libpq-be.h | 20 | ||||
| -rw-r--r-- | src/include/libpq/libpq.h | 7 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h index 59c2a1d874f..4dce7677510 100644 --- a/src/include/libpq/libpq-be.h +++ b/src/include/libpq/libpq-be.h @@ -110,12 +110,9 @@ typedef struct ClientConnectionInfo } ClientConnectionInfo; /* - * This is used by the postmaster in its communication with frontends. It - * contains all state information needed during this communication before the - * backend is run. The Port structure is kept in malloc'd memory and is - * still available when a backend is running (see MyProcPort). The data - * it points to must also be malloc'd, or else palloc'd in TopMemoryContext, - * so that it survives into PostgresMain execution! + * The Port structure holds state information about a client connection in a + * backend process. It is available in the global variable MyProcPort. The + * struct and all the data it points are kept in TopMemoryContext. * * remote_hostname is set if we did a successful reverse lookup of the * client's IP address during connection setup. @@ -217,6 +214,17 @@ typedef struct Port #endif } Port; +/* + * ClientSocket holds a socket for an accepted connection, along with the + * information about the remote endpoint. This is passed from postmaster to + * the backend process. + */ +typedef struct ClientSocket +{ + pgsocket sock; /* File descriptor */ + SockAddr raddr; /* remote addr (client) */ +} ClientSocket; + #ifdef USE_SSL /* * Hardcoded DH parameters, used in ephemeral DH keying. (See also diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h index 6171a0d17a5..be054b59dd1 100644 --- a/src/include/libpq/libpq.h +++ b/src/include/libpq/libpq.h @@ -64,14 +64,13 @@ extern PGDLLIMPORT WaitEventSet *FeBeWaitSet; #define FeBeWaitSetLatchPos 1 #define FeBeWaitSetNEvents 3 -extern int StreamServerPort(int family, const char *hostName, +extern int ListenServerPort(int family, const char *hostName, unsigned short portNumber, const char *unixSocketDir, pgsocket ListenSocket[], int *NumListenSockets, int MaxListen); -extern int StreamConnection(pgsocket server_fd, Port *port); -extern void StreamClose(pgsocket sock); +extern int AcceptConnection(pgsocket server_fd, ClientSocket *client_sock); extern void TouchSocketFiles(void); extern void RemoveSocketFiles(void); -extern void pq_init(void); +extern Port *pq_init(ClientSocket *client_sock); extern int pq_getbytes(char *s, size_t len); extern void pq_startmsgread(void); extern void pq_endmsgread(void); |
