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

Christophe Fergeau cfergeau at redhat.com
Fri Mar 10 16:38:24 UTC 2017


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 at redhat.com>
> > ---
> >  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."

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.


Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170310/8b0845e0/attachment-0001.sig>


More information about the Spice-devel mailing list