Re: [spice-server v2 3/6] net: Introduce red_socket_set_keepalive() helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> On Fri, Mar 10, 2017 at 08:46:09AM -0500, Frediano Ziglio wrote:
> > > 
> > > This allows to move some low-level code out of reds.c
> > > 
> > > Signed-off-by: Christophe Fergeau <cfergeau@xxxxxxxxxx>
> > > ---
> > >  server/net-utils.c | 25 +++++++++++++++++++++++++
> > >  server/net-utils.h |  1 +
> > >  server/reds.c      | 27 ++-------------------------
> > >  3 files changed, 28 insertions(+), 25 deletions(-)
> > > 
> > > diff --git a/server/net-utils.c b/server/net-utils.c
> > > index ce409be..995b0d4 100644
> > > --- a/server/net-utils.c
> > > +++ b/server/net-utils.c
> > > @@ -31,6 +31,31 @@
> > >  
> > >  #include "net-utils.h"
> > >  
> > > +bool red_socket_set_keepalive(int fd, bool enable, int timeout)
> > > +{
> > > +    int keepalive = !!enable;
> > > +
> > > +    if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keepalive,
> > > sizeof(keepalive)) == -1) {
> > > +        if (errno != ENOTSUP) {
> > > +            spice_printerr("setsockopt for keepalive failed, %s",
> > > strerror(errno));
> > > +            return false;
> > > +        }
> > > +    }
> > > +
> > > +    if (!enable) {
> > > +        return true;
> > > +    }
> > > +
> > > +    if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &timeout, sizeof(timeout))
> > > ==
> > > -1) {
> > 
> > About this value. NetBSD, Windows and Mac use milliseconds.
> 
> This is not true for NetBSD and Mac:
> http://www.unix.com/man-page/netbsd/4/tcp/
> "The TCP_KEEPIDLE option can be used to affect this value for a given
> socket, and specifies the number of seconds of idle time between
> keepalive probes."
> 

You are right, very similar for FreeBSD
https://www.freebsd.org/cgi/man.cgi?query=tcp&sektion=4&apropos=0&manpath=FreeBSD+11.0-RELEASE+and+Ports

> For Mac, I only found
> https://stackoverflow.com/questions/15860127/how-to-configure-tcp-keepalive-under-mac-os-x
> but this uses values in seconds.
> 

See https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man4/tcp.4.html#//apple_ref/doc/man/4/tcp
I must have been confused by the system setting which seems to use milliseconds.
Looks like Mac uses TCP_KEEPALIVE but is just changing name.
I searched a more recent page on apple developer website but I could not find it.

> 
> Christophe
> 

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]