mirror of
https://github.com/eledio-devices/thirdparty-AsyncTCPSock.git
synced 2025-10-30 16:15:40 +01:00
Stop accept()-ing connections if already at max connection limit
The constant CONFIG_LWIP_MAX_SOCKETS, if available, tells how many sockets can be opened at once. If already at this limit, and an attempt is made to accept() an additional incoming connection from a listening socket, the accept() call will fail. Fix this by checking the socket list and refusing to add the listening socket to the set of readable sockets to check in the select() call. This will cause connections to remain in the listening backlog until some other socket is closed.
This commit is contained in:
@@ -92,12 +92,19 @@ void _asynctcpsock_task(void *)
|
||||
FD_ZERO(&sockSet_r); FD_ZERO(&sockSet_w);
|
||||
for (it = _socketBaseList.begin(); it != _socketBaseList.end(); it++) {
|
||||
if ((*it)->_socket != -1) {
|
||||
FD_SET((*it)->_socket, &sockSet_r);
|
||||
#ifdef CONFIG_LWIP_MAX_SOCKETS
|
||||
if (!(*it)->_isServer() || _socketBaseList.size() < CONFIG_LWIP_MAX_SOCKETS) {
|
||||
#endif
|
||||
FD_SET((*it)->_socket, &sockSet_r);
|
||||
if (max_sock <= (*it)->_socket) max_sock = (*it)->_socket + 1;
|
||||
#ifdef CONFIG_LWIP_MAX_SOCKETS
|
||||
}
|
||||
#endif
|
||||
if ((*it)->_pendingWrite()) {
|
||||
FD_SET((*it)->_socket, &sockSet_w);
|
||||
if (max_sock <= (*it)->_socket) max_sock = (*it)->_socket + 1;
|
||||
}
|
||||
(*it)->_selected = true;
|
||||
if (max_sock <= (*it)->_socket) max_sock = (*it)->_socket + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ protected:
|
||||
virtual void _sockDelayedConnect(void) {} // Action to take on DNS-resolve finished
|
||||
|
||||
virtual bool _pendingWrite(void) { return false; } // Test if there is data pending to be written
|
||||
virtual bool _isServer(void) { return false; } // Will a read from this socket result in one more client?
|
||||
|
||||
public:
|
||||
AsyncSocketBase(void);
|
||||
@@ -239,6 +240,9 @@ class AsyncServer : public AsyncSocketBase
|
||||
|
||||
// Listening socket is readable on incoming connection
|
||||
void _sockIsReadable(void);
|
||||
|
||||
// Mark this class as a server
|
||||
bool _isServer(void) { return true; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user