Implement setting/clearing G_IO_FLAG_NONBLOCK for channels attached to
authorTor Lillqvist <tml@novell.com>
Fri, 12 May 2006 13:20:36 +0000 (13:20 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Fri, 12 May 2006 13:20:36 +0000 (13:20 +0000)
2006-05-12  Tor Lillqvist  <tml@novell.com>

* glib/giowin32.c (g_io_win32_sock_set_flags): Implement
setting/clearing G_IO_FLAG_NONBLOCK for channels attached to
sockets. (#341192)
(g_io_win32_unimpl_set_flags): set_flags method for the
unimplemented case.

ChangeLog
ChangeLog.pre-2-12
glib/giowin32.c

index 2666443..6864376 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-05-12  Tor Lillqvist  <tml@novell.com>
+
+       * glib/giowin32.c (g_io_win32_sock_set_flags): Implement
+       setting/clearing G_IO_FLAG_NONBLOCK for channels attached to
+       sockets. (#341192)
+       (g_io_win32_unimpl_set_flags): set_flags method for the
+       unimplemented case.
+       
 2006-05-11  Bastien Nocera  <hadess@hadess.net>
 
        * glib/goption.c: (parse_int64), (parse_arg), (free_changes_list):
index 2666443..6864376 100644 (file)
@@ -1,3 +1,11 @@
+2006-05-12  Tor Lillqvist  <tml@novell.com>
+
+       * glib/giowin32.c (g_io_win32_sock_set_flags): Implement
+       setting/clearing G_IO_FLAG_NONBLOCK for channels attached to
+       sockets. (#341192)
+       (g_io_win32_unimpl_set_flags): set_flags method for the
+       unimplemented case.
+       
 2006-05-11  Bastien Nocera  <hadess@hadess.net>
 
        * glib/goption.c: (parse_int64), (parse_arg), (free_changes_list):
index 7a9b6d7..5354968 100644 (file)
@@ -1646,15 +1646,15 @@ g_io_channel_new_file (const gchar  *filename,
 #endif
 
 static GIOStatus
-g_io_win32_set_flags (GIOChannel *channel,
-                      GIOFlags    flags,
-                      GError    **err)
+g_io_win32_unimpl_set_flags (GIOChannel *channel,
+                            GIOFlags    flags,
+                            GError    **err)
 {
   GIOWin32Channel *win32_channel = (GIOWin32Channel *)channel;
 
   if (win32_channel->debug)
     {
-      g_print ("g_io_win32_set_flags: ");
+      g_print ("g_io_win32_unimpl_set_flags: ");
       g_win32_print_gioflags (flags);
       g_print ("\n");
     }
@@ -1735,10 +1735,51 @@ g_io_win32_msg_get_flags (GIOChannel *channel)
   return 0;
 }
 
+static GIOStatus
+g_io_win32_sock_set_flags (GIOChannel *channel,
+                          GIOFlags    flags,
+                          GError    **err)
+{
+  GIOWin32Channel *win32_channel = (GIOWin32Channel *)channel;
+  u_long arg;
+
+  if (win32_channel->debug)
+    {
+      g_print ("g_io_win32_sock_set_flags: ");
+      g_win32_print_gioflags (flags);
+      g_print ("\n");
+    }
+
+  if (flags & G_IO_FLAG_NONBLOCK)
+    {
+      arg = 1;
+      if (ioctlsocket (win32_channel->fd, FIONBIO, &arg) == SOCKET_ERROR)
+       {
+         g_set_error (err, G_IO_CHANNEL_ERROR,
+                      G_IO_CHANNEL_ERROR_FAILED,
+                      winsock_error_message (WSAGetLastError ()));
+         return G_IO_STATUS_ERROR;
+       }
+    }
+  else
+    {
+      arg = 0;
+      if (ioctlsocket (win32_channel->fd, FIONBIO, &arg) == SOCKET_ERROR)
+       {
+         g_set_error (err, G_IO_CHANNEL_ERROR,
+                      G_IO_CHANNEL_ERROR_FAILED,
+                      winsock_error_message (WSAGetLastError ()));
+         return G_IO_STATUS_ERROR;
+       }
+    }
+
+  return G_IO_STATUS_NORMAL;
+}
+
 static GIOFlags
 g_io_win32_sock_get_flags (GIOChannel *channel)
 {
-  /* XXX Could do something here. */
+  /* Could we do something here? */
   return 0;
 }
 
@@ -1749,7 +1790,7 @@ static GIOFuncs win32_channel_msg_funcs = {
   g_io_win32_msg_close,
   g_io_win32_msg_create_watch,
   g_io_win32_free,
-  g_io_win32_set_flags,
+  g_io_win32_unimpl_set_flags,
   g_io_win32_msg_get_flags,
 };
 
@@ -1760,7 +1801,7 @@ static GIOFuncs win32_channel_fd_funcs = {
   g_io_win32_fd_close,
   g_io_win32_fd_create_watch,
   g_io_win32_free,
-  g_io_win32_set_flags,
+  g_io_win32_unimpl_set_flags,
   g_io_win32_fd_get_flags,
 };
 
@@ -1771,7 +1812,7 @@ static GIOFuncs win32_channel_sock_funcs = {
   g_io_win32_sock_close,
   g_io_win32_sock_create_watch,
   g_io_win32_free,
-  g_io_win32_set_flags,
+  g_io_win32_sock_set_flags,
   g_io_win32_sock_get_flags,
 };