[erlang-questions] how to limit number of connections to gen_tcp?

Jarrod Roberson jarrod@REDACTED
Tue May 26 21:11:57 CEST 2009

On Tue, May 26, 2009 at 1:20 PM, Alin Popa <alin.popa@REDACTED> wrote:
> Hi Jarrod,
> Something like this might help you:
> -define(MAX_TCP_CONNECTIONS, 1000).
> -define(TCP_OPTIONS, [binary, {packet, 0}, {active, false}, {reuseaddr,
> true}, {backlog, ?MAX_TCP_CONNECTIONS}]).
> listen(Port, F) ->
>      {ok, LSocket} = gen_tcp:listen(Port, ?TCP_OPTIONS),
>      accept(LSocket, F).
> .............
> Hope this is what you are looking for ...

This will do what I asked about but it doesn't do what I was
"thinking' about :-)

What I really want to be able to do is accept the connection and if
max connections is exceeded send a message to the client that the
server is overloaded and the close the connection. What I really can't
figure out is how to pass around  a "current connection count" to I
can increment it and decrement it during accepts and disconnects.

More information about the erlang-questions mailing list