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

Alin Popa alin.popa@REDACTED
Tue May 26 21:33:34 CEST 2009


Maybe there is a BIF that is returning the remaining no of connections with
respect to that backlog atom...

On Tue, May 26, 2009 at 10:11 PM, Jarrod Roberson <jarrod@REDACTED>wrote:

> 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.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
Regards,

Alin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090526/0977fa86/attachment.htm>


More information about the erlang-questions mailing list