From 3e27f4722e8afe083c41c899b227b8cb6c8db01e Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 4 Jun 2008 13:25:57 +0000 Subject: [PATCH] The SO_RCVTIMEO and SO_SNDTIMEO options to setsockopt() take int values, 2008-06-04 Tor Lillqvist * libsoup/soup-socket.c (set_fdflags): The SO_RCVTIMEO and SO_SNDTIMEO options to setsockopt() take int values, in milliseconds, on Windows. Not struct timeval. Eek. So passing a struct timeval meant that the tv_sec value (which is first in the struct) is interpreted as milliseconds. setsockopt apparently doesn't even get upset by the fact that the option size doesn't match the sizeof(int) it should expect. svn path=/trunk/; revision=1142 --- ChangeLog | 10 ++++++++++ libsoup/soup-socket.c | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index de1d8ab..0b44799 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-06-04 Tor Lillqvist + + * libsoup/soup-socket.c (set_fdflags): The SO_RCVTIMEO and + SO_SNDTIMEO options to setsockopt() take int values, in + milliseconds, on Windows. Not struct timeval. Eek. So passing a + struct timeval meant that the tv_sec value (which is first in the + struct) is interpreted as milliseconds. setsockopt apparently + doesn't even get upset by the fact that the option size doesn't + match the sizeof(int) it should expect. + 2008-05-02 Dan Winship * libsoup/soup-cookie.c (soup_cookie_applies_to_uri): fix the path diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c index e502086..4bc2d28 100644 --- a/libsoup/soup-socket.c +++ b/libsoup/soup-socket.c @@ -333,8 +333,8 @@ static void set_fdflags (SoupSocketPrivate *priv) { int opt; - struct timeval timeout; #ifndef G_OS_WIN32 + struct timeval timeout; int flags; #endif @@ -357,6 +357,7 @@ set_fdflags (SoupSocketPrivate *priv) setsockopt (priv->sockfd, SOL_SOCKET, SO_REUSEADDR, (void *) &opt, sizeof (opt)); +#ifndef G_OS_WIN32 timeout.tv_sec = priv->timeout; timeout.tv_usec = 0; setsockopt (priv->sockfd, SOL_SOCKET, @@ -366,6 +367,18 @@ set_fdflags (SoupSocketPrivate *priv) timeout.tv_usec = 0; setsockopt (priv->sockfd, SOL_SOCKET, SO_SNDTIMEO, (void *) &timeout, sizeof (timeout)); +#else + if (priv->timeout < G_MAXINT / 1000) + opt = priv->timeout * 1000; + else + opt = 0; + + setsockopt (priv->sockfd, SOL_SOCKET, + SO_RCVTIMEO, (void *) &opt, sizeof (opt)); + + setsockopt (priv->sockfd, SOL_SOCKET, + SO_SNDTIMEO, (void *) &opt, sizeof (opt)); +#endif #ifndef G_OS_WIN32 priv->iochannel = -- 2.7.4