mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-06 15:24:56 +08:00
Add WL_SOCKET_ACCEPT event to WaitEventSet API.
To be able to handle incoming connections on a server socket with the WaitEventSet API, we'll need a new kind of event to indicate that the the socket is ready to accept a connection. On Unix, it's just the same as WL_SOCKET_READABLE, but on Windows there is a different underlying kernel event that we need to map our abstraction to. No user yet, but a proposed patch would use this. Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CA%2BhUKG%2BZ-HpOj1JsO9eWUP%2Bar7npSVinsC_npxSy%2BjdOMsx%3DGg%40mail.gmail.com
This commit is contained in:
parent
f4f2f2b84a
commit
30829e52ff
@ -864,6 +864,9 @@ FreeWaitEventSet(WaitEventSet *set)
|
|||||||
* - WL_SOCKET_CONNECTED: Wait for socket connection to be established,
|
* - WL_SOCKET_CONNECTED: Wait for socket connection to be established,
|
||||||
* can be combined with other WL_SOCKET_* events (on non-Windows
|
* can be combined with other WL_SOCKET_* events (on non-Windows
|
||||||
* platforms, this is the same as WL_SOCKET_WRITEABLE)
|
* platforms, this is the same as WL_SOCKET_WRITEABLE)
|
||||||
|
* - WL_SOCKET_ACCEPT: Wait for new connection to a server socket,
|
||||||
|
* can be combined with other WL_SOCKET_* events (on non-Windows
|
||||||
|
* platforms, this is the same as WL_SOCKET_READABLE)
|
||||||
* - WL_SOCKET_CLOSED: Wait for socket to be closed by remote peer.
|
* - WL_SOCKET_CLOSED: Wait for socket to be closed by remote peer.
|
||||||
* - WL_EXIT_ON_PM_DEATH: Exit immediately if the postmaster dies
|
* - WL_EXIT_ON_PM_DEATH: Exit immediately if the postmaster dies
|
||||||
*
|
*
|
||||||
@ -874,7 +877,7 @@ FreeWaitEventSet(WaitEventSet *set)
|
|||||||
* i.e. it must be a process-local latch initialized with InitLatch, or a
|
* i.e. it must be a process-local latch initialized with InitLatch, or a
|
||||||
* shared latch associated with the current process by calling OwnLatch.
|
* shared latch associated with the current process by calling OwnLatch.
|
||||||
*
|
*
|
||||||
* In the WL_SOCKET_READABLE/WRITEABLE/CONNECTED cases, EOF and error
|
* In the WL_SOCKET_READABLE/WRITEABLE/CONNECTED/ACCEPT cases, EOF and error
|
||||||
* conditions cause the socket to be reported as readable/writable/connected,
|
* conditions cause the socket to be reported as readable/writable/connected,
|
||||||
* so that the caller can deal with the condition.
|
* so that the caller can deal with the condition.
|
||||||
*
|
*
|
||||||
@ -1312,6 +1315,8 @@ WaitEventAdjustWin32(WaitEventSet *set, WaitEvent *event)
|
|||||||
flags |= FD_WRITE;
|
flags |= FD_WRITE;
|
||||||
if (event->events & WL_SOCKET_CONNECTED)
|
if (event->events & WL_SOCKET_CONNECTED)
|
||||||
flags |= FD_CONNECT;
|
flags |= FD_CONNECT;
|
||||||
|
if (event->events & WL_SOCKET_ACCEPT)
|
||||||
|
flags |= FD_ACCEPT;
|
||||||
|
|
||||||
if (*handle == WSA_INVALID_EVENT)
|
if (*handle == WSA_INVALID_EVENT)
|
||||||
{
|
{
|
||||||
@ -2067,6 +2072,12 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
|
|||||||
/* connected */
|
/* connected */
|
||||||
occurred_events->events |= WL_SOCKET_CONNECTED;
|
occurred_events->events |= WL_SOCKET_CONNECTED;
|
||||||
}
|
}
|
||||||
|
if ((cur_event->events & WL_SOCKET_ACCEPT) &&
|
||||||
|
(resEvents.lNetworkEvents & FD_ACCEPT))
|
||||||
|
{
|
||||||
|
/* incoming connection could be accepted */
|
||||||
|
occurred_events->events |= WL_SOCKET_ACCEPT;
|
||||||
|
}
|
||||||
if (resEvents.lNetworkEvents & FD_CLOSE)
|
if (resEvents.lNetworkEvents & FD_CLOSE)
|
||||||
{
|
{
|
||||||
/* EOF/error, so signal all caller-requested socket flags */
|
/* EOF/error, so signal all caller-requested socket flags */
|
||||||
|
@ -135,9 +135,16 @@ typedef struct Latch
|
|||||||
#define WL_SOCKET_CONNECTED WL_SOCKET_WRITEABLE
|
#define WL_SOCKET_CONNECTED WL_SOCKET_WRITEABLE
|
||||||
#endif
|
#endif
|
||||||
#define WL_SOCKET_CLOSED (1 << 7)
|
#define WL_SOCKET_CLOSED (1 << 7)
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WL_SOCKET_ACCEPT (1 << 8)
|
||||||
|
#else
|
||||||
|
/* avoid having to deal with case on platforms not requiring it */
|
||||||
|
#define WL_SOCKET_ACCEPT WL_SOCKET_READABLE
|
||||||
|
#endif
|
||||||
#define WL_SOCKET_MASK (WL_SOCKET_READABLE | \
|
#define WL_SOCKET_MASK (WL_SOCKET_READABLE | \
|
||||||
WL_SOCKET_WRITEABLE | \
|
WL_SOCKET_WRITEABLE | \
|
||||||
WL_SOCKET_CONNECTED | \
|
WL_SOCKET_CONNECTED | \
|
||||||
|
WL_SOCKET_ACCEPT | \
|
||||||
WL_SOCKET_CLOSED)
|
WL_SOCKET_CLOSED)
|
||||||
|
|
||||||
typedef struct WaitEvent
|
typedef struct WaitEvent
|
||||||
|
Loading…
Reference in New Issue
Block a user