mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
Socket functions: _poll becomes _prepoll, which never waits
A layer over the sockets, TLS or a plugin's, no longer waits itself. Its _prepoll only tells what it knows without asking the system: the fds it knows to be ready, data TLS has already decrypted, or, returning 0, that the sockets have to be polled, for events it may rewrite: a TLS read waiting for its socket to be writable. The wait is sockpoll()'s, which calls _prepoll first and then polls, so that a wait can be made other than with poll() in one place: a client of an event loop is to wait in the loop. Whatever a rewritten wait gets is given to the caller as what it asked for, its chance to try again, and the events it asked for are given back. With no fds sockpoll() sleeps, which WSAPoll() would refuse. TLS remembers what a read or a write it could not do waits for. A read needing to write, or a write to read, was an error which ended the connection, as when TLS 1.3 answers a key update while the socket cannot take more; it now waits for what TLS needs, as one needing what it was asked for always did. Incompatible for plugins, which have to be built again with the same version of 3proxy, the structures they share not kept compatible: - struct sockfuncs has _prepoll(state, fds, nfds) in place of _poll(state, fds, nfds, timeout). A plugin replacing _poll replaces _prepoll: it must not wait, returns the number of fds it set revents of (events then left as they are), 0 for the fds to be polled (with events as it leaves them, revents left to the poll) or -1, and calls the _prepoll it replaced when it has nothing to say itself. - Waiting for sockets is sockpoll(sf, state, fds, nfds, timeout), not so._poll() of the socket functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
718798c7fc
commit
b4bbcb9e9a
16 files changed
+109
-53
No files matched your search
+10
-2
@@ -573,6 +573,14 @@ struct sockoptset {
|
||||
};
|
||||
|
||||
|
||||
/* _prepoll never waits: it tells what a layer over the socket knows to be
|
||||
ready without asking the system, data a TLS connection has already
|
||||
decrypted, and what the system is to be asked instead of what the caller
|
||||
asked, events rewritten: a TLS read waiting for its socket to be
|
||||
writable. It returns the number of fds it has set revents of, the rest
|
||||
to be ignored and events left as they are; 0 when the sockets have to be
|
||||
polled, for their events as it leaves them, revents left to the poll;
|
||||
or -1. The wait itself is sockpoll()'s, which calls it first. */
|
||||
struct sockfuncs {
|
||||
void * state;
|
||||
void (*freefunc)(void* state);
|
||||
@@ -586,7 +594,7 @@ struct sockfuncs {
|
||||
int (WINAPI *_getsockname)(void* state, SOCKET s, struct sockaddr * name, int * namelen);
|
||||
int (WINAPI *_getsockopt)(void* state, SOCKET s, int level, int optname, char * optval, int * optlen);
|
||||
int (WINAPI *_setsockopt)(void* state, SOCKET s, int level, int optname, const char *optval, int optlen);
|
||||
int (WINAPI *_poll)(void* state, struct pollfd *fds, unsigned int nfds, int timeout);
|
||||
int (WINAPI *_prepoll)(void* state, struct pollfd *fds, unsigned int nfds);
|
||||
int (WINAPI *_send)(void* state, SOCKET s, const char *msg, int len, int flags);
|
||||
int (WINAPI *_sendto)(void* state, SOCKET s, const char *msg, int len, int flags, const struct sockaddr *to, int tolen);
|
||||
int (WINAPI *_recv)(void* state, SOCKET s, char *buf, int len, int flags);
|
||||
@@ -603,7 +611,7 @@ struct sockfuncs {
|
||||
int (*_getsockname)(void* state, SOCKET s, struct sockaddr * name, socklen_t * namelen);
|
||||
int (*_getsockopt)(void* state, SOCKET s, int level, int optname, void * optval, socklen_t * optlen);
|
||||
int (*_setsockopt)(void* state, int s, int level, int optname, const void *optval, socklen_t optlen);
|
||||
int (*_poll)(void* state, struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
int (*_prepoll)(void* state, struct pollfd *fds, nfds_t nfds);
|
||||
ssize_t (*_send)(void* state, SOCKET s, const void *msg, size_t len, int flags);
|
||||
ssize_t (*_sendto)(void* state, SOCKET s, const void *msg, size_t len, int flags, const struct sockaddr *to, SASIZETYPE tolen);
|
||||
ssize_t (*_recv)(void* state, SOCKET s, void *buf, size_t len, int flags);
|
||||
|
||||
Reference in new issue
Block a user