From 3dcf39eb77dc324b6838a87fa82fb6d10a208cf7 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Thu, 31 Aug 2000 22:47:24 +0000 Subject: [PATCH] glib.h glib.def New function, to make a GPollFD from a GIOChannel. Creates 2000-08-31 Tor Lillqvist * glib.h * glib.def * giowin32.c (g_io_channel_win32_make_pollfd): New function, to make a GPollFD from a GIOChannel. Creates the events and starts the reader thread if necessary. --- ChangeLog | 6 ++++++ ChangeLog.pre-2-0 | 6 ++++++ ChangeLog.pre-2-10 | 6 ++++++ ChangeLog.pre-2-12 | 6 ++++++ ChangeLog.pre-2-2 | 6 ++++++ ChangeLog.pre-2-4 | 6 ++++++ ChangeLog.pre-2-6 | 6 ++++++ ChangeLog.pre-2-8 | 6 ++++++ giowin32.c | 29 ++++++++++++++++++++++++----- glib.def | 1 + glib.h | 23 ++++++++++++++++++----- glib/giowin32.c | 29 ++++++++++++++++++++++++----- glib/glib.def | 1 + glib/glib.h | 23 ++++++++++++++++++----- 14 files changed, 134 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index b11a965..1abba36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ 2000-08-31 Tor Lillqvist * glib.h + * glib.def + * giowin32.c (g_io_channel_win32_make_pollfd): New function, to + make a GPollFD from a GIOChannel. Creates the events and starts + the reader thread if necessary. + + * glib.h * giowin32.c (g_io_channel_win32_poll): No use for separate condition parameter. diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index b11a965..1abba36 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,6 +1,12 @@ 2000-08-31 Tor Lillqvist * glib.h + * glib.def + * giowin32.c (g_io_channel_win32_make_pollfd): New function, to + make a GPollFD from a GIOChannel. Creates the events and starts + the reader thread if necessary. + + * glib.h * giowin32.c (g_io_channel_win32_poll): No use for separate condition parameter. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index b11a965..1abba36 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,6 +1,12 @@ 2000-08-31 Tor Lillqvist * glib.h + * glib.def + * giowin32.c (g_io_channel_win32_make_pollfd): New function, to + make a GPollFD from a GIOChannel. Creates the events and starts + the reader thread if necessary. + + * glib.h * giowin32.c (g_io_channel_win32_poll): No use for separate condition parameter. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index b11a965..1abba36 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,6 +1,12 @@ 2000-08-31 Tor Lillqvist * glib.h + * glib.def + * giowin32.c (g_io_channel_win32_make_pollfd): New function, to + make a GPollFD from a GIOChannel. Creates the events and starts + the reader thread if necessary. + + * glib.h * giowin32.c (g_io_channel_win32_poll): No use for separate condition parameter. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index b11a965..1abba36 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,6 +1,12 @@ 2000-08-31 Tor Lillqvist * glib.h + * glib.def + * giowin32.c (g_io_channel_win32_make_pollfd): New function, to + make a GPollFD from a GIOChannel. Creates the events and starts + the reader thread if necessary. + + * glib.h * giowin32.c (g_io_channel_win32_poll): No use for separate condition parameter. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index b11a965..1abba36 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,6 +1,12 @@ 2000-08-31 Tor Lillqvist * glib.h + * glib.def + * giowin32.c (g_io_channel_win32_make_pollfd): New function, to + make a GPollFD from a GIOChannel. Creates the events and starts + the reader thread if necessary. + + * glib.h * giowin32.c (g_io_channel_win32_poll): No use for separate condition parameter. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index b11a965..1abba36 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,6 +1,12 @@ 2000-08-31 Tor Lillqvist * glib.h + * glib.def + * giowin32.c (g_io_channel_win32_make_pollfd): New function, to + make a GPollFD from a GIOChannel. Creates the events and starts + the reader thread if necessary. + + * glib.h * giowin32.c (g_io_channel_win32_poll): No use for separate condition parameter. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index b11a965..1abba36 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,6 +1,12 @@ 2000-08-31 Tor Lillqvist * glib.h + * glib.def + * giowin32.c (g_io_channel_win32_make_pollfd): New function, to + make a GPollFD from a GIOChannel. Creates the events and starts + the reader thread if necessary. + + * glib.h * giowin32.c (g_io_channel_win32_poll): No use for separate condition parameter. diff --git a/giowin32.c b/giowin32.c index 9db86d3..4acdb16 100644 --- a/giowin32.c +++ b/giowin32.c @@ -872,9 +872,9 @@ g_io_channel_win32_set_debug (GIOChannel *channel, } gint -g_io_channel_win32_poll (GPollFD *fds, - gint n_fds, - gint timeout) +g_io_channel_win32_poll (GPollFD *fds, + gint n_fds, + gint timeout) { int i; int result; @@ -887,6 +887,26 @@ g_io_channel_win32_poll (GPollFD *fds, return result; } +void +g_io_channel_win32_make_pollfd (GIOChannel *channel, + GIOCondition condition, + GPollFD *fd) +{ + GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel; + + if (win32_channel->data_avail_event == NULL) + create_events (win32_channel); + + fd->fd = win32_channel->data_avail_event; + fd->events = condition; + + if (win32_channel->thread_id == 0) + if (win32_channel->type == G_IO_FILE_DESC) + create_reader_thread (win32_channel, fd_reader); + else if (win32_channel->type == G_IO_STREAM_SOCKET) + create_reader_thread (win32_channel, sock_reader); +} + gint g_io_channel_win32_wait_for_condition (GIOChannel *channel, GIOCondition condition, @@ -895,8 +915,7 @@ g_io_channel_win32_wait_for_condition (GIOChannel *channel, GPollFD pollfd; GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel; - pollfd.fd = (gint) win32_channel->data_avail_event; - pollfd.events = condition; + g_io_channel_win32_make_pollfd (channel, condition, &pollfd); return g_io_channel_win32_poll (&pollfd, 1, timeout); } diff --git a/glib.def b/glib.def index 0843575..d70288f 100644 --- a/glib.def +++ b/glib.def @@ -164,6 +164,7 @@ EXPORTS g_io_channel_win32_new_pipe g_io_channel_win32_new_pipe_with_wakeups g_io_channel_win32_new_stream_socket + g_io_channel_win32_make_pollfd g_io_channel_win32_pipe_readable g_io_channel_win32_pipe_request_wakeups g_io_channel_win32_poll diff --git a/glib.h b/glib.h index ded2c20..46aa390 100644 --- a/glib.h +++ b/glib.h @@ -2921,13 +2921,22 @@ gint g_io_channel_unix_get_fd (GIOChannel *channel); #define G_WIN32_MSG_HANDLE 19981206 +/* Use this to get a GPollFD from a GIOChannel, so that you can call + * g_io_channel_win32_poll(). After calling this you should only use + * g_io_channel_read() to read from the GIOChannel, i.e. never read() + * or recv() from the underlying file descriptor or SOCKET. + */ +void g_io_channel_win32_make_pollfd (GIOChannel *channel, + GIOCondition condition, + GPollFD *fd); + /* 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_poll (GPollFD *fds, - gint n_fds, - gint timeout); +gint g_io_channel_win32_poll (GPollFD *fds, + gint n_fds, + gint timeout); /* This is used to add polling for Windows messages. GDK (GTk+) programs * should *not* use this. @@ -2941,14 +2950,18 @@ GIOChannel *g_io_channel_win32_new_messages (guint hwnd); /* An IO channel for C runtime (emulated Unix-like) file * descriptors. Identical to g_io_channel_unix_new above. + * After calling g_io_add_watch() on a IO channel returned + * by this function, you shouldn't call read() on the file + * descriptor. */ GIOChannel* g_io_channel_win32_new_fd (int fd); /* Get the C runtime file descriptor of a channel. */ gint g_io_channel_win32_get_fd (GIOChannel *channel); -/* An IO channel for a SOCK_STREAM winsock socket. The parameter should - * be a SOCKET. +/* An IO channel for a SOCK_STREAM winsock socket. The parameter + * should be a SOCKET. After calling g_io_add_watch() on a IO channel + * returned by this function, you shouldn't call recv() on the SOCKET. */ GIOChannel *g_io_channel_win32_new_stream_socket (int socket); diff --git a/glib/giowin32.c b/glib/giowin32.c index 9db86d3..4acdb16 100644 --- a/glib/giowin32.c +++ b/glib/giowin32.c @@ -872,9 +872,9 @@ g_io_channel_win32_set_debug (GIOChannel *channel, } gint -g_io_channel_win32_poll (GPollFD *fds, - gint n_fds, - gint timeout) +g_io_channel_win32_poll (GPollFD *fds, + gint n_fds, + gint timeout) { int i; int result; @@ -887,6 +887,26 @@ g_io_channel_win32_poll (GPollFD *fds, return result; } +void +g_io_channel_win32_make_pollfd (GIOChannel *channel, + GIOCondition condition, + GPollFD *fd) +{ + GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel; + + if (win32_channel->data_avail_event == NULL) + create_events (win32_channel); + + fd->fd = win32_channel->data_avail_event; + fd->events = condition; + + if (win32_channel->thread_id == 0) + if (win32_channel->type == G_IO_FILE_DESC) + create_reader_thread (win32_channel, fd_reader); + else if (win32_channel->type == G_IO_STREAM_SOCKET) + create_reader_thread (win32_channel, sock_reader); +} + gint g_io_channel_win32_wait_for_condition (GIOChannel *channel, GIOCondition condition, @@ -895,8 +915,7 @@ g_io_channel_win32_wait_for_condition (GIOChannel *channel, GPollFD pollfd; GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel; - pollfd.fd = (gint) win32_channel->data_avail_event; - pollfd.events = condition; + g_io_channel_win32_make_pollfd (channel, condition, &pollfd); return g_io_channel_win32_poll (&pollfd, 1, timeout); } diff --git a/glib/glib.def b/glib/glib.def index 0843575..d70288f 100644 --- a/glib/glib.def +++ b/glib/glib.def @@ -164,6 +164,7 @@ EXPORTS g_io_channel_win32_new_pipe g_io_channel_win32_new_pipe_with_wakeups g_io_channel_win32_new_stream_socket + g_io_channel_win32_make_pollfd g_io_channel_win32_pipe_readable g_io_channel_win32_pipe_request_wakeups g_io_channel_win32_poll diff --git a/glib/glib.h b/glib/glib.h index ded2c20..46aa390 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -2921,13 +2921,22 @@ gint g_io_channel_unix_get_fd (GIOChannel *channel); #define G_WIN32_MSG_HANDLE 19981206 +/* Use this to get a GPollFD from a GIOChannel, so that you can call + * g_io_channel_win32_poll(). After calling this you should only use + * g_io_channel_read() to read from the GIOChannel, i.e. never read() + * or recv() from the underlying file descriptor or SOCKET. + */ +void g_io_channel_win32_make_pollfd (GIOChannel *channel, + GIOCondition condition, + GPollFD *fd); + /* 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_poll (GPollFD *fds, - gint n_fds, - gint timeout); +gint g_io_channel_win32_poll (GPollFD *fds, + gint n_fds, + gint timeout); /* This is used to add polling for Windows messages. GDK (GTk+) programs * should *not* use this. @@ -2941,14 +2950,18 @@ GIOChannel *g_io_channel_win32_new_messages (guint hwnd); /* An IO channel for C runtime (emulated Unix-like) file * descriptors. Identical to g_io_channel_unix_new above. + * After calling g_io_add_watch() on a IO channel returned + * by this function, you shouldn't call read() on the file + * descriptor. */ GIOChannel* g_io_channel_win32_new_fd (int fd); /* Get the C runtime file descriptor of a channel. */ gint g_io_channel_win32_get_fd (GIOChannel *channel); -/* An IO channel for a SOCK_STREAM winsock socket. The parameter should - * be a SOCKET. +/* An IO channel for a SOCK_STREAM winsock socket. The parameter + * should be a SOCKET. After calling g_io_add_watch() on a IO channel + * returned by this function, you shouldn't call recv() on the SOCKET. */ GIOChannel *g_io_channel_win32_new_stream_socket (int socket); -- 2.7.4