For anyone else interested in the solution, I can now limit the number
of connections on a port, and refuse connections in excess of the limit.
1) Put #define SO_REUSE 1 in lwiopts.h
2) Whenever the listening socket is being opened call tcp_new(), then
use ip_set_option(newpcb,SOF_REUSEADDR) to allow re-use of the port
number before calling tcp_bind();
3) When the last connection is accepted (hitting the max allowed
connections), in the accept callback call tcp_close() to close the
LISTENING pcb.
4) Whenever a connection is closed (making another socket available),
re-open the listening pcb again (as in step 2 above) if it is not
already open.
This exactly what I wanted. Up to "N" connections accepted
simultaneously, with excess connection attempts refused. Works great.
Keith Rubow
On 5/14/2018 11:56 AM, goldsi...@gmx.de wrote:
On 14.05.2018 18:27, Keith Rubow wrote:
[..] I would like to have additional connection
attempts to be refused. I can achieve this behavior only by closing the
listening pcb once I reach the max number of connections, but then I
can't re-open the listening pcb until ALL open connections are closed.
But some connections might stay open indefinitely, in which case I can
never open the listening pcb again.
You don't seem to read the responses to your mails. There were two
suggestsions:
a) do it the standard socket way (even if you are using lwIP callback
API) and use REUSEADDR to be able to open the listening socket
although connection sockets are active (or in time-wait; this *is*
standard behaviour, not an lwIP thing!)
b) play with backlog.
The default usage of backlog is to decrease it when connections are
actually accepted, but you can just use it to only accept new
connections after previous connections are closed. To do that, call
'tcp_backlog_delayed()' in your accept callback and call
'tcp_backlog_accepted()' when the pcb is closed (when the 'err'
callback is called, the latter is done internally by the stack).
Simon
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users