New function, otherwise like g_io_channel_win32_wait_for_condition(), but
authorTor Lillqvist <tml@iki.fi>
Sun, 27 Aug 2000 10:53:36 +0000 (10:53 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Sun, 27 Aug 2000 10:53:36 +0000 (10:53 +0000)
2000-08-27  Tor Lillqvist  <tml@iki.fi>

* giowin32.c (g_io_channel_win32_poll): New function, otherwise
like g_io_channel_win32_wait_for_condition(), but accept several
GIOChannels.
(g_io_channel_win32_wait_for_condition): Call
g_io_channel_win32_poll().

* glib.h: Declare g_io_channel_win32_poll().

* gwin32.c (g_win32_error_message): Don't believe return value
from FormatMessage.

16 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
giowin32.c
glib.def
glib.h
glib/giowin32.c
glib/glib.def
glib/glib.h
glib/gwin32.c
gwin32.c

index d10e1d8b2e2960f4e1be096df359fc0f9024b7ea..dd894914d056c938afdc83f41ff411e911cbfbff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2000-08-27  Tor Lillqvist  <tml@iki.fi>
+
+       * giowin32.c (g_io_channel_win32_poll): New function, otherwise
+       like g_io_channel_win32_wait_for_condition(), but accept several
+       GIOChannels.
+       (g_io_channel_win32_wait_for_condition): Call
+       g_io_channel_win32_poll().
+
+       * glib.h: Declare g_io_channel_win32_poll().
+
+       * gwin32.c (g_win32_error_message): Don't believe return value
+       from FormatMessage.
+
 2000-08-25 Elliot Lee <sopwith@redhat.com>
        * glib.h, gunicode.h, gmodule/gmodule.h:
        : Mark the following functions G_GNUC_CONST (to allow
index d10e1d8b2e2960f4e1be096df359fc0f9024b7ea..dd894914d056c938afdc83f41ff411e911cbfbff 100644 (file)
@@ -1,3 +1,16 @@
+2000-08-27  Tor Lillqvist  <tml@iki.fi>
+
+       * giowin32.c (g_io_channel_win32_poll): New function, otherwise
+       like g_io_channel_win32_wait_for_condition(), but accept several
+       GIOChannels.
+       (g_io_channel_win32_wait_for_condition): Call
+       g_io_channel_win32_poll().
+
+       * glib.h: Declare g_io_channel_win32_poll().
+
+       * gwin32.c (g_win32_error_message): Don't believe return value
+       from FormatMessage.
+
 2000-08-25 Elliot Lee <sopwith@redhat.com>
        * glib.h, gunicode.h, gmodule/gmodule.h:
        : Mark the following functions G_GNUC_CONST (to allow
index d10e1d8b2e2960f4e1be096df359fc0f9024b7ea..dd894914d056c938afdc83f41ff411e911cbfbff 100644 (file)
@@ -1,3 +1,16 @@
+2000-08-27  Tor Lillqvist  <tml@iki.fi>
+
+       * giowin32.c (g_io_channel_win32_poll): New function, otherwise
+       like g_io_channel_win32_wait_for_condition(), but accept several
+       GIOChannels.
+       (g_io_channel_win32_wait_for_condition): Call
+       g_io_channel_win32_poll().
+
+       * glib.h: Declare g_io_channel_win32_poll().
+
+       * gwin32.c (g_win32_error_message): Don't believe return value
+       from FormatMessage.
+
 2000-08-25 Elliot Lee <sopwith@redhat.com>
        * glib.h, gunicode.h, gmodule/gmodule.h:
        : Mark the following functions G_GNUC_CONST (to allow
index d10e1d8b2e2960f4e1be096df359fc0f9024b7ea..dd894914d056c938afdc83f41ff411e911cbfbff 100644 (file)
@@ -1,3 +1,16 @@
+2000-08-27  Tor Lillqvist  <tml@iki.fi>
+
+       * giowin32.c (g_io_channel_win32_poll): New function, otherwise
+       like g_io_channel_win32_wait_for_condition(), but accept several
+       GIOChannels.
+       (g_io_channel_win32_wait_for_condition): Call
+       g_io_channel_win32_poll().
+
+       * glib.h: Declare g_io_channel_win32_poll().
+
+       * gwin32.c (g_win32_error_message): Don't believe return value
+       from FormatMessage.
+
 2000-08-25 Elliot Lee <sopwith@redhat.com>
        * glib.h, gunicode.h, gmodule/gmodule.h:
        : Mark the following functions G_GNUC_CONST (to allow
index d10e1d8b2e2960f4e1be096df359fc0f9024b7ea..dd894914d056c938afdc83f41ff411e911cbfbff 100644 (file)
@@ -1,3 +1,16 @@
+2000-08-27  Tor Lillqvist  <tml@iki.fi>
+
+       * giowin32.c (g_io_channel_win32_poll): New function, otherwise
+       like g_io_channel_win32_wait_for_condition(), but accept several
+       GIOChannels.
+       (g_io_channel_win32_wait_for_condition): Call
+       g_io_channel_win32_poll().
+
+       * glib.h: Declare g_io_channel_win32_poll().
+
+       * gwin32.c (g_win32_error_message): Don't believe return value
+       from FormatMessage.
+
 2000-08-25 Elliot Lee <sopwith@redhat.com>
        * glib.h, gunicode.h, gmodule/gmodule.h:
        : Mark the following functions G_GNUC_CONST (to allow
index d10e1d8b2e2960f4e1be096df359fc0f9024b7ea..dd894914d056c938afdc83f41ff411e911cbfbff 100644 (file)
@@ -1,3 +1,16 @@
+2000-08-27  Tor Lillqvist  <tml@iki.fi>
+
+       * giowin32.c (g_io_channel_win32_poll): New function, otherwise
+       like g_io_channel_win32_wait_for_condition(), but accept several
+       GIOChannels.
+       (g_io_channel_win32_wait_for_condition): Call
+       g_io_channel_win32_poll().
+
+       * glib.h: Declare g_io_channel_win32_poll().
+
+       * gwin32.c (g_win32_error_message): Don't believe return value
+       from FormatMessage.
+
 2000-08-25 Elliot Lee <sopwith@redhat.com>
        * glib.h, gunicode.h, gmodule/gmodule.h:
        : Mark the following functions G_GNUC_CONST (to allow
index d10e1d8b2e2960f4e1be096df359fc0f9024b7ea..dd894914d056c938afdc83f41ff411e911cbfbff 100644 (file)
@@ -1,3 +1,16 @@
+2000-08-27  Tor Lillqvist  <tml@iki.fi>
+
+       * giowin32.c (g_io_channel_win32_poll): New function, otherwise
+       like g_io_channel_win32_wait_for_condition(), but accept several
+       GIOChannels.
+       (g_io_channel_win32_wait_for_condition): Call
+       g_io_channel_win32_poll().
+
+       * glib.h: Declare g_io_channel_win32_poll().
+
+       * gwin32.c (g_win32_error_message): Don't believe return value
+       from FormatMessage.
+
 2000-08-25 Elliot Lee <sopwith@redhat.com>
        * glib.h, gunicode.h, gmodule/gmodule.h:
        : Mark the following functions G_GNUC_CONST (to allow
index d10e1d8b2e2960f4e1be096df359fc0f9024b7ea..dd894914d056c938afdc83f41ff411e911cbfbff 100644 (file)
@@ -1,3 +1,16 @@
+2000-08-27  Tor Lillqvist  <tml@iki.fi>
+
+       * giowin32.c (g_io_channel_win32_poll): New function, otherwise
+       like g_io_channel_win32_wait_for_condition(), but accept several
+       GIOChannels.
+       (g_io_channel_win32_wait_for_condition): Call
+       g_io_channel_win32_poll().
+
+       * glib.h: Declare g_io_channel_win32_poll().
+
+       * gwin32.c (g_win32_error_message): Don't believe return value
+       from FormatMessage.
+
 2000-08-25 Elliot Lee <sopwith@redhat.com>
        * glib.h, gunicode.h, gmodule/gmodule.h:
        : Mark the following functions G_GNUC_CONST (to allow
index 68fee3b4ab56246cb679863b02bb7175827dcbd2..db5e9ca4d74c59c553475d9c93643c62943c4929 100644 (file)
@@ -872,29 +872,62 @@ g_io_channel_win32_set_debug (GIOChannel *channel,
 }
 
 gint
-g_io_channel_win32_wait_for_condition (GIOChannel  *channel,
-                                      GIOCondition condition,
-                                      gint         timeout)
+g_io_channel_win32_poll (GIOChannel **channels,
+                        gint         n_channels,
+                        GIOCondition condition,
+                        gint         timeout)
 {
-  GPollFD pollfd;
-  GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
+  GPollFD *pollfd;
+  GIOWin32Channel *win32_channel;
+  int i;
   int result;
+  gboolean debug = FALSE;
 
-  pollfd.fd = (gint) win32_channel->data_avail_event;
-  pollfd.events = condition;
+  g_return_val_if_fail (n_channels >= 0, 0);
 
-  if (win32_channel->debug)
-    g_print ("g_io_channel_win32_wait_for_condition: fd:%d event:%#x timeout:%d\n",
-            win32_channel->fd, pollfd.fd, timeout);
+  pollfd = g_new (GPollFD, n_channels);
 
-  result = (*g_main_win32_get_poll_func ()) (&pollfd, 1, timeout);
+  for (i = 0; i < n_channels; i++)
+    {
+      win32_channel = (GIOWin32Channel *) channels[i];
+      debug |= win32_channel->debug;
+      pollfd[i].fd = (gint) win32_channel->data_avail_event;
+      pollfd[i].events = condition;
+    }
 
-  if (win32_channel->debug)
-    g_print ("g_io_channel_win32_wait_for_condition: done:%d\n", result);
+  if (debug)
+    {
+      g_print ("g_io_channel_win32_poll: ");
+      for (i = 0; i < n_channels; i++)
+       {
+         win32_channel = (GIOWin32Channel *) channels[i];
+         g_print ("fd:%d event:%#x ", win32_channel->fd, pollfd[i].fd);
+       }
+      g_print ("condition:%s%s%s%s timeout:%d\n",
+              (condition & G_IO_ERR) ? " ERR" : "",
+              (condition & G_IO_HUP) ? " HUP" : "",
+              (condition & G_IO_IN)  ? " IN"  : "",
+              (condition & G_IO_PRI) ? " PRI" : "",
+              timeout);
+    }
+
+  result = (*g_main_win32_get_poll_func ()) (pollfd, n_channels, timeout);
+
+  if (debug)
+    g_print ("g_io_channel_win32_poll: done:%d\n", result);
+
+  g_free (pollfd);
 
   return result;
 }
 
+gint
+g_io_channel_win32_wait_for_condition (GIOChannel  *channel,
+                                      GIOCondition condition,
+                                      gint         timeout)
+{
+  return g_io_channel_win32_poll (&channel, 1, condition, timeout);
+}
 
 /* This variable and the functions below are present just to be 
  * binary compatible with old clients... But note that in GIMP, the
index 2781cb4874643898a0c3632f7cc8e3c4499e28b7..0843575bf93c53fcab42f6d87a01db6de781f995 100644 (file)
--- a/glib.def
+++ b/glib.def
@@ -166,6 +166,7 @@ EXPORTS
        g_io_channel_win32_new_stream_socket
        g_io_channel_win32_pipe_readable
        g_io_channel_win32_pipe_request_wakeups
+       g_io_channel_win32_poll
        g_io_channel_win32_set_debug
        g_io_channel_win32_wait_for_condition
        g_io_channel_write
diff --git a/glib.h b/glib.h
index 6b684088ab4cead3a0da60d685879d48c33339b8..31805ddead8e5242aefd745e48d144c51b314fb2 100644 (file)
--- a/glib.h
+++ b/glib.h
@@ -2921,20 +2921,21 @@ gint        g_io_channel_unix_get_fd (GIOChannel *channel);
 
 #define G_WIN32_MSG_HANDLE 19981206
 
-/* This can be used to wait until a channel is readable.  On Unix you
- * would do a select() on the fd of the channel. This should probably
- * be replaced by something for all platforms?
+/* This can be used to wait a until at least one of the channels is readable.
+ * On Unix you would do a select() on the file descriptors of the channels.
+ * This should probably be available for all platforms?
  */
-gint        g_io_channel_win32_wait_for_condition (GIOChannel  *channel,
-                                                  GIOCondition condition,
-                                                  gint         timeout);
+gint        g_io_channel_win32_poll (GIOChannel **channels,
+                                    gint         n_channels,
+                                    GIOCondition condition,
+                                    gint         timeout);
 
 /* This is used to add polling for Windows messages. GDK (GTk+) programs
  * should *not* use this.
  */
-void        g_main_poll_win32_msg_add(gint        priority,
-                                     GPollFD    *fd,
-                                     guint       hwnd);
+void        g_main_poll_win32_msg_add (gint        priority,
+                                      GPollFD    *fd,
+                                      guint       hwnd);
 
 /* An IO channel for Windows messages for window handle hwnd. */
 GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
index 68fee3b4ab56246cb679863b02bb7175827dcbd2..db5e9ca4d74c59c553475d9c93643c62943c4929 100644 (file)
@@ -872,29 +872,62 @@ g_io_channel_win32_set_debug (GIOChannel *channel,
 }
 
 gint
-g_io_channel_win32_wait_for_condition (GIOChannel  *channel,
-                                      GIOCondition condition,
-                                      gint         timeout)
+g_io_channel_win32_poll (GIOChannel **channels,
+                        gint         n_channels,
+                        GIOCondition condition,
+                        gint         timeout)
 {
-  GPollFD pollfd;
-  GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
+  GPollFD *pollfd;
+  GIOWin32Channel *win32_channel;
+  int i;
   int result;
+  gboolean debug = FALSE;
 
-  pollfd.fd = (gint) win32_channel->data_avail_event;
-  pollfd.events = condition;
+  g_return_val_if_fail (n_channels >= 0, 0);
 
-  if (win32_channel->debug)
-    g_print ("g_io_channel_win32_wait_for_condition: fd:%d event:%#x timeout:%d\n",
-            win32_channel->fd, pollfd.fd, timeout);
+  pollfd = g_new (GPollFD, n_channels);
 
-  result = (*g_main_win32_get_poll_func ()) (&pollfd, 1, timeout);
+  for (i = 0; i < n_channels; i++)
+    {
+      win32_channel = (GIOWin32Channel *) channels[i];
+      debug |= win32_channel->debug;
+      pollfd[i].fd = (gint) win32_channel->data_avail_event;
+      pollfd[i].events = condition;
+    }
 
-  if (win32_channel->debug)
-    g_print ("g_io_channel_win32_wait_for_condition: done:%d\n", result);
+  if (debug)
+    {
+      g_print ("g_io_channel_win32_poll: ");
+      for (i = 0; i < n_channels; i++)
+       {
+         win32_channel = (GIOWin32Channel *) channels[i];
+         g_print ("fd:%d event:%#x ", win32_channel->fd, pollfd[i].fd);
+       }
+      g_print ("condition:%s%s%s%s timeout:%d\n",
+              (condition & G_IO_ERR) ? " ERR" : "",
+              (condition & G_IO_HUP) ? " HUP" : "",
+              (condition & G_IO_IN)  ? " IN"  : "",
+              (condition & G_IO_PRI) ? " PRI" : "",
+              timeout);
+    }
+
+  result = (*g_main_win32_get_poll_func ()) (pollfd, n_channels, timeout);
+
+  if (debug)
+    g_print ("g_io_channel_win32_poll: done:%d\n", result);
+
+  g_free (pollfd);
 
   return result;
 }
 
+gint
+g_io_channel_win32_wait_for_condition (GIOChannel  *channel,
+                                      GIOCondition condition,
+                                      gint         timeout)
+{
+  return g_io_channel_win32_poll (&channel, 1, condition, timeout);
+}
 
 /* This variable and the functions below are present just to be 
  * binary compatible with old clients... But note that in GIMP, the
index 2781cb4874643898a0c3632f7cc8e3c4499e28b7..0843575bf93c53fcab42f6d87a01db6de781f995 100644 (file)
@@ -166,6 +166,7 @@ EXPORTS
        g_io_channel_win32_new_stream_socket
        g_io_channel_win32_pipe_readable
        g_io_channel_win32_pipe_request_wakeups
+       g_io_channel_win32_poll
        g_io_channel_win32_set_debug
        g_io_channel_win32_wait_for_condition
        g_io_channel_write
index 6b684088ab4cead3a0da60d685879d48c33339b8..31805ddead8e5242aefd745e48d144c51b314fb2 100644 (file)
@@ -2921,20 +2921,21 @@ gint        g_io_channel_unix_get_fd (GIOChannel *channel);
 
 #define G_WIN32_MSG_HANDLE 19981206
 
-/* This can be used to wait until a channel is readable.  On Unix you
- * would do a select() on the fd of the channel. This should probably
- * be replaced by something for all platforms?
+/* This can be used to wait a until at least one of the channels is readable.
+ * On Unix you would do a select() on the file descriptors of the channels.
+ * This should probably be available for all platforms?
  */
-gint        g_io_channel_win32_wait_for_condition (GIOChannel  *channel,
-                                                  GIOCondition condition,
-                                                  gint         timeout);
+gint        g_io_channel_win32_poll (GIOChannel **channels,
+                                    gint         n_channels,
+                                    GIOCondition condition,
+                                    gint         timeout);
 
 /* This is used to add polling for Windows messages. GDK (GTk+) programs
  * should *not* use this.
  */
-void        g_main_poll_win32_msg_add(gint        priority,
-                                     GPollFD    *fd,
-                                     guint       hwnd);
+void        g_main_poll_win32_msg_add (gint        priority,
+                                      GPollFD    *fd,
+                                      guint       hwnd);
 
 /* An IO channel for Windows messages for window handle hwnd. */
 GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
index adc8a2393cb70ca50195041f6ca1410409b5ecbc..256fe021a590269c2783c35628a988a3edc1f9ca 100644 (file)
@@ -806,11 +806,13 @@ g_win32_error_message (gint error)
   gchar *retval;
   int nbytes;
 
-  nbytes = FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
-                         |FORMAT_MESSAGE_IGNORE_INSERTS
-                         |FORMAT_MESSAGE_FROM_SYSTEM,
-                         NULL, error, 0,
-                         (LPTSTR) &msg, 0, NULL);
+  FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
+                |FORMAT_MESSAGE_IGNORE_INSERTS
+                |FORMAT_MESSAGE_FROM_SYSTEM,
+                NULL, error, 0,
+                (LPTSTR) &msg, 0, NULL);
+  nbytes = strlen (msg);
+
   if (nbytes > 2 && msg[nbytes-1] == '\n' && msg[nbytes-2] == '\r')
     msg[nbytes-2] = '\0';
   
index adc8a2393cb70ca50195041f6ca1410409b5ecbc..256fe021a590269c2783c35628a988a3edc1f9ca 100644 (file)
--- a/gwin32.c
+++ b/gwin32.c
@@ -806,11 +806,13 @@ g_win32_error_message (gint error)
   gchar *retval;
   int nbytes;
 
-  nbytes = FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
-                         |FORMAT_MESSAGE_IGNORE_INSERTS
-                         |FORMAT_MESSAGE_FROM_SYSTEM,
-                         NULL, error, 0,
-                         (LPTSTR) &msg, 0, NULL);
+  FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
+                |FORMAT_MESSAGE_IGNORE_INSERTS
+                |FORMAT_MESSAGE_FROM_SYSTEM,
+                NULL, error, 0,
+                (LPTSTR) &msg, 0, NULL);
+  nbytes = strlen (msg);
+
   if (nbytes > 2 && msg[nbytes-1] == '\n' && msg[nbytes-2] == '\r')
     msg[nbytes-2] = '\0';