On Tue, Feb 7, 2017 at 7:48 AM, Darren Smith <[email protected]> wrote:
> Hi
>
> I am using libuv for a server application.  When the server needs to close a
> client connection that has not hand-shaked correctly, I would like to reset
> the TCP connection rather than calling close() - this is to prevent having
> many sockets in the TIME_WAIT on the server side.
>
> I've looked at the libuv headers; there doesnt' seem any utility methods for
> reseting a uv_tcp_t object (e.g., naively I was hoping for a reset(...)
> call); nor is there any helper method for setting LINGER, although some
> socket options do have utility methods, eg uv_tcp_nodelay &
> uv_tcp_keepalive.
>
> I'm curious as to why some socket options have an API but others don't.
> For my requirement to reset a tcp connection, am I correct in there not
> being direct libuv support, or have I missed something?  In which case I
> suppose I can just call setsockopt directly on the fd.
>
> Thanks,
>
> Darren

Hi Darren,

Libuv indeed has no direct support for configuring SO_LINGER.  What is
it you ultimately want to accomplish?

1. Sending a TCP RST instead of a FIN to the remote peer?  I don't
think there is a portable (or even a non-portable but reliable) way of
doing that.  A zero SO_LINGER is not guaranteed to always result in a
RST.

2. Control how in-flight data is handled by close()?  See [0] for a
comprehensive overview of SO_LINGER's many intricacies, in particular
the section about non-blocking sockets.  To summarize: SO_LINGER is
likely not the answer, you probably want uv_shutdown().

3. Stop sockets from ending up in TIME_WAIT state?  You cannot in
general ([1] is the shortest explanation I was able to find, [2] the
most comprehensive one) but if there was a portable and reliable way
of controlling its duration, it would make sense to add that to libuv.
I'm not aware of any that meet both the 'portable' and 'reliable'
criteria, though.

Hope that helps,

Ben

[0] 
https://blog.netherlabs.nl/articles/2009/01/18/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable
[1] 
http://superuser.com/questions/173535/what-are-close-wait-and-time-wait-states/173542#173542
[2] 
http://www.serverframework.com/asynchronousevents/2011/01/time-wait-and-its-design-implications-for-protocols-and-scalable-servers.html

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to