[gnio] On i/o errors in setters, don't change the value



commit e6eebd6bd920fa689bafe1ee4774292571d68dfa
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Apr 28 11:28:45 2009 +0200

    On i/o errors in setters, don't change the value
---
 gio/gsocket.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/gio/gsocket.c b/gio/gsocket.c
index 1be66f4..8942ac7 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -514,17 +514,23 @@ g_socket_set_blocking (GSocket  *socket,
 
 #ifndef G_OS_WIN32
   if ((arg = fcntl (socket->priv->fd, F_GETFL, NULL)) < 0)
-    g_warning ("Error getting socket status flags: %s", g_strerror (errno));
+    {
+      g_warning ("Error getting socket status flags: %s", g_strerror (errno));
+      return; /* Don't change blocking */
+    }
 
   arg = blocking ? arg & ~O_NONBLOCK : arg | O_NONBLOCK;
 
   if (fcntl (socket->priv->fd, F_SETFL, arg) < 0)
-    g_warning ("Error setting socket status flags: %s", g_strerror (errno));
 #else
   arg = !blocking;
 
-  ioctlsocket (socket->priv->fd, FIONBIO, &arg);
+  if (ioctlsocket (socket->priv->fd, FIONBIO, &arg) == SOCKET_ERROR)
 #endif
+    {
+      g_warning ("Error setting socket status flags: %s", g_strerror (errno));
+      return; /* Don't change blocking */
+    }
 
   socket->priv->blocking = blocking;
   g_object_notify (G_OBJECT (socket), "blocking");
@@ -552,7 +558,10 @@ g_socket_set_reuse_address (GSocket  *socket,
 
   if (setsockopt (socket->priv->fd, SOL_SOCKET, SO_REUSEADDR,
 		  (gpointer) &value, sizeof (value)) < 0)
-    g_warning ("error setting reuse address: %s", g_strerror (errno));
+    {
+      g_warning ("error setting reuse address: %s", g_strerror (errno));
+      return;
+    }
 
   socket->priv->reuse_address = reuse;
   g_object_notify (G_OBJECT (socket), "reuse_address");



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