Finally, a new and improved IO Channel and condition watch implementation

2000-07-30  Tor Lillqvist  <tml@iki.fi>

	Finally, a new and improved IO Channel and condition watch
	implementation for Win32. Based on code provided by Craig Setera.

	When watching file descriptors, for which there is no select()
	like functionality on Win32 that would work on all Win32 platforms
	for all types of file descriptors (including anonymous pipes), we
	start a new thread that blocks while trying to read from the file
	descriptor. When the read returns, a Win32 Event is signalled that
	the polling routine eventually notices. Meanwhile, the data being
	read is stored in a circular buffer, from where the IO channel's
	read() method picks it up.

	If the buffer fills up the reading thread has to wait for space
	becoming available. For this another Win32 Event is used. The IO
	Channel's read() method signals this when it has read some data
	out of the buffer.

	The separate reader thread(s), and the circular buffer(s) with
	associated events mean lots of possibilities for fun parallellism
	errors. But it seems to work OK, i.e. GIMP runs.

	* gmain.c: Small changes to the Win32 polling function.
	(g_main_win32_get_poll_func): New function. Perhaps it would be a
	good idea to provide this on all platforms.

	* giowin32.c: The bulk of the new implementation.
	(g_io_channel_win32_wait_for_condition): New function. To be used
	where on Unix one does a select() on the channel's fd, like
	libgimp's gimp_extension_process(). Could be provided on all
	platforms.

	* glib.h: Update documentation for IO Channels on Win32. Remove
	the declarations for the as of now obsolete old functions related
	to IO Channels for pipes with "wakeup" messages.

	* glib.def: Some new functions.

	* tests/gio-test.c: New file, to test GIOChannel and main loop.

	* tests/Makefile.am
	* tests/makefile.mingw.in: Add it.
This commit is contained in:
Tor Lillqvist 2000-07-29 20:59:07 +00:00 committed by Tor Lillqvist
parent d33887428e
commit b965bb5db1
19 changed files with 1880 additions and 1420 deletions

View File

@ -1,3 +1,47 @@
2000-07-30 Tor Lillqvist <tml@iki.fi>
Finally, a new and improved IO Channel and condition watch
implementation for Win32. Based on code provided by Craig Setera.
When watching file descriptors, for which there is no select()
like functionality on Win32 that would work on all Win32 platforms
for all types of file descriptors (including anonymous pipes), we
start a new thread that blocks while trying to read from the file
descriptor. When the read returns, a Win32 Event is signalled that
the polling routine eventually notices. Meanwhile, the data being
read is stored in a circular buffer, from where the IO channel's
read() method picks it up.
If the buffer fills up the reading thread has to wait for space
becoming available. For this another Win32 Event is used. The IO
Channel's read() method signals this when it has read some data
out of the buffer.
The separate reader thread(s), and the circular buffer(s) with
associated events mean lots of possibilities for fun parallellism
errors. But it seems to work OK, i.e. GIMP runs.
* gmain.c: Small changes to the Win32 polling function.
(g_main_win32_get_poll_func): New function. Perhaps it would be a
good idea to provide this on all platforms.
* giowin32.c: The bulk of the new implementation.
(g_io_channel_win32_wait_for_condition): New function. To be used
where on Unix one does a select() on the channel's fd, like
libgimp's gimp_extension_process(). Could be provided on all
platforms.
* glib.h: Update documentation for IO Channels on Win32. Remove
the declarations for the as of now obsolete old functions related
to IO Channels for pipes with "wakeup" messages.
* glib.def: Some new functions.
* tests/gio-test.c: New file, to test GIOChannel and main loop.
* tests/Makefile.am
* tests/makefile.mingw.in: Add it.
Thu Jul 27 05:15:11 2000 Tim Janik <timj@gtk.org>
* gstrfuncs.c (g_strlcpy, g_strlcat): completed tor's fix

View File

@ -1,3 +1,47 @@
2000-07-30 Tor Lillqvist <tml@iki.fi>
Finally, a new and improved IO Channel and condition watch
implementation for Win32. Based on code provided by Craig Setera.
When watching file descriptors, for which there is no select()
like functionality on Win32 that would work on all Win32 platforms
for all types of file descriptors (including anonymous pipes), we
start a new thread that blocks while trying to read from the file
descriptor. When the read returns, a Win32 Event is signalled that
the polling routine eventually notices. Meanwhile, the data being
read is stored in a circular buffer, from where the IO channel's
read() method picks it up.
If the buffer fills up the reading thread has to wait for space
becoming available. For this another Win32 Event is used. The IO
Channel's read() method signals this when it has read some data
out of the buffer.
The separate reader thread(s), and the circular buffer(s) with
associated events mean lots of possibilities for fun parallellism
errors. But it seems to work OK, i.e. GIMP runs.
* gmain.c: Small changes to the Win32 polling function.
(g_main_win32_get_poll_func): New function. Perhaps it would be a
good idea to provide this on all platforms.
* giowin32.c: The bulk of the new implementation.
(g_io_channel_win32_wait_for_condition): New function. To be used
where on Unix one does a select() on the channel's fd, like
libgimp's gimp_extension_process(). Could be provided on all
platforms.
* glib.h: Update documentation for IO Channels on Win32. Remove
the declarations for the as of now obsolete old functions related
to IO Channels for pipes with "wakeup" messages.
* glib.def: Some new functions.
* tests/gio-test.c: New file, to test GIOChannel and main loop.
* tests/Makefile.am
* tests/makefile.mingw.in: Add it.
Thu Jul 27 05:15:11 2000 Tim Janik <timj@gtk.org>
* gstrfuncs.c (g_strlcpy, g_strlcat): completed tor's fix

View File

@ -1,3 +1,47 @@
2000-07-30 Tor Lillqvist <tml@iki.fi>
Finally, a new and improved IO Channel and condition watch
implementation for Win32. Based on code provided by Craig Setera.
When watching file descriptors, for which there is no select()
like functionality on Win32 that would work on all Win32 platforms
for all types of file descriptors (including anonymous pipes), we
start a new thread that blocks while trying to read from the file
descriptor. When the read returns, a Win32 Event is signalled that
the polling routine eventually notices. Meanwhile, the data being
read is stored in a circular buffer, from where the IO channel's
read() method picks it up.
If the buffer fills up the reading thread has to wait for space
becoming available. For this another Win32 Event is used. The IO
Channel's read() method signals this when it has read some data
out of the buffer.
The separate reader thread(s), and the circular buffer(s) with
associated events mean lots of possibilities for fun parallellism
errors. But it seems to work OK, i.e. GIMP runs.
* gmain.c: Small changes to the Win32 polling function.
(g_main_win32_get_poll_func): New function. Perhaps it would be a
good idea to provide this on all platforms.
* giowin32.c: The bulk of the new implementation.
(g_io_channel_win32_wait_for_condition): New function. To be used
where on Unix one does a select() on the channel's fd, like
libgimp's gimp_extension_process(). Could be provided on all
platforms.
* glib.h: Update documentation for IO Channels on Win32. Remove
the declarations for the as of now obsolete old functions related
to IO Channels for pipes with "wakeup" messages.
* glib.def: Some new functions.
* tests/gio-test.c: New file, to test GIOChannel and main loop.
* tests/Makefile.am
* tests/makefile.mingw.in: Add it.
Thu Jul 27 05:15:11 2000 Tim Janik <timj@gtk.org>
* gstrfuncs.c (g_strlcpy, g_strlcat): completed tor's fix

View File

@ -1,3 +1,47 @@
2000-07-30 Tor Lillqvist <tml@iki.fi>
Finally, a new and improved IO Channel and condition watch
implementation for Win32. Based on code provided by Craig Setera.
When watching file descriptors, for which there is no select()
like functionality on Win32 that would work on all Win32 platforms
for all types of file descriptors (including anonymous pipes), we
start a new thread that blocks while trying to read from the file
descriptor. When the read returns, a Win32 Event is signalled that
the polling routine eventually notices. Meanwhile, the data being
read is stored in a circular buffer, from where the IO channel's
read() method picks it up.
If the buffer fills up the reading thread has to wait for space
becoming available. For this another Win32 Event is used. The IO
Channel's read() method signals this when it has read some data
out of the buffer.
The separate reader thread(s), and the circular buffer(s) with
associated events mean lots of possibilities for fun parallellism
errors. But it seems to work OK, i.e. GIMP runs.
* gmain.c: Small changes to the Win32 polling function.
(g_main_win32_get_poll_func): New function. Perhaps it would be a
good idea to provide this on all platforms.
* giowin32.c: The bulk of the new implementation.
(g_io_channel_win32_wait_for_condition): New function. To be used
where on Unix one does a select() on the channel's fd, like
libgimp's gimp_extension_process(). Could be provided on all
platforms.
* glib.h: Update documentation for IO Channels on Win32. Remove
the declarations for the as of now obsolete old functions related
to IO Channels for pipes with "wakeup" messages.
* glib.def: Some new functions.
* tests/gio-test.c: New file, to test GIOChannel and main loop.
* tests/Makefile.am
* tests/makefile.mingw.in: Add it.
Thu Jul 27 05:15:11 2000 Tim Janik <timj@gtk.org>
* gstrfuncs.c (g_strlcpy, g_strlcat): completed tor's fix

View File

@ -1,3 +1,47 @@
2000-07-30 Tor Lillqvist <tml@iki.fi>
Finally, a new and improved IO Channel and condition watch
implementation for Win32. Based on code provided by Craig Setera.
When watching file descriptors, for which there is no select()
like functionality on Win32 that would work on all Win32 platforms
for all types of file descriptors (including anonymous pipes), we
start a new thread that blocks while trying to read from the file
descriptor. When the read returns, a Win32 Event is signalled that
the polling routine eventually notices. Meanwhile, the data being
read is stored in a circular buffer, from where the IO channel's
read() method picks it up.
If the buffer fills up the reading thread has to wait for space
becoming available. For this another Win32 Event is used. The IO
Channel's read() method signals this when it has read some data
out of the buffer.
The separate reader thread(s), and the circular buffer(s) with
associated events mean lots of possibilities for fun parallellism
errors. But it seems to work OK, i.e. GIMP runs.
* gmain.c: Small changes to the Win32 polling function.
(g_main_win32_get_poll_func): New function. Perhaps it would be a
good idea to provide this on all platforms.
* giowin32.c: The bulk of the new implementation.
(g_io_channel_win32_wait_for_condition): New function. To be used
where on Unix one does a select() on the channel's fd, like
libgimp's gimp_extension_process(). Could be provided on all
platforms.
* glib.h: Update documentation for IO Channels on Win32. Remove
the declarations for the as of now obsolete old functions related
to IO Channels for pipes with "wakeup" messages.
* glib.def: Some new functions.
* tests/gio-test.c: New file, to test GIOChannel and main loop.
* tests/Makefile.am
* tests/makefile.mingw.in: Add it.
Thu Jul 27 05:15:11 2000 Tim Janik <timj@gtk.org>
* gstrfuncs.c (g_strlcpy, g_strlcat): completed tor's fix

View File

@ -1,3 +1,47 @@
2000-07-30 Tor Lillqvist <tml@iki.fi>
Finally, a new and improved IO Channel and condition watch
implementation for Win32. Based on code provided by Craig Setera.
When watching file descriptors, for which there is no select()
like functionality on Win32 that would work on all Win32 platforms
for all types of file descriptors (including anonymous pipes), we
start a new thread that blocks while trying to read from the file
descriptor. When the read returns, a Win32 Event is signalled that
the polling routine eventually notices. Meanwhile, the data being
read is stored in a circular buffer, from where the IO channel's
read() method picks it up.
If the buffer fills up the reading thread has to wait for space
becoming available. For this another Win32 Event is used. The IO
Channel's read() method signals this when it has read some data
out of the buffer.
The separate reader thread(s), and the circular buffer(s) with
associated events mean lots of possibilities for fun parallellism
errors. But it seems to work OK, i.e. GIMP runs.
* gmain.c: Small changes to the Win32 polling function.
(g_main_win32_get_poll_func): New function. Perhaps it would be a
good idea to provide this on all platforms.
* giowin32.c: The bulk of the new implementation.
(g_io_channel_win32_wait_for_condition): New function. To be used
where on Unix one does a select() on the channel's fd, like
libgimp's gimp_extension_process(). Could be provided on all
platforms.
* glib.h: Update documentation for IO Channels on Win32. Remove
the declarations for the as of now obsolete old functions related
to IO Channels for pipes with "wakeup" messages.
* glib.def: Some new functions.
* tests/gio-test.c: New file, to test GIOChannel and main loop.
* tests/Makefile.am
* tests/makefile.mingw.in: Add it.
Thu Jul 27 05:15:11 2000 Tim Janik <timj@gtk.org>
* gstrfuncs.c (g_strlcpy, g_strlcat): completed tor's fix

View File

@ -1,3 +1,47 @@
2000-07-30 Tor Lillqvist <tml@iki.fi>
Finally, a new and improved IO Channel and condition watch
implementation for Win32. Based on code provided by Craig Setera.
When watching file descriptors, for which there is no select()
like functionality on Win32 that would work on all Win32 platforms
for all types of file descriptors (including anonymous pipes), we
start a new thread that blocks while trying to read from the file
descriptor. When the read returns, a Win32 Event is signalled that
the polling routine eventually notices. Meanwhile, the data being
read is stored in a circular buffer, from where the IO channel's
read() method picks it up.
If the buffer fills up the reading thread has to wait for space
becoming available. For this another Win32 Event is used. The IO
Channel's read() method signals this when it has read some data
out of the buffer.
The separate reader thread(s), and the circular buffer(s) with
associated events mean lots of possibilities for fun parallellism
errors. But it seems to work OK, i.e. GIMP runs.
* gmain.c: Small changes to the Win32 polling function.
(g_main_win32_get_poll_func): New function. Perhaps it would be a
good idea to provide this on all platforms.
* giowin32.c: The bulk of the new implementation.
(g_io_channel_win32_wait_for_condition): New function. To be used
where on Unix one does a select() on the channel's fd, like
libgimp's gimp_extension_process(). Could be provided on all
platforms.
* glib.h: Update documentation for IO Channels on Win32. Remove
the declarations for the as of now obsolete old functions related
to IO Channels for pipes with "wakeup" messages.
* glib.def: Some new functions.
* tests/gio-test.c: New file, to test GIOChannel and main loop.
* tests/Makefile.am
* tests/makefile.mingw.in: Add it.
Thu Jul 27 05:15:11 2000 Tim Janik <timj@gtk.org>
* gstrfuncs.c (g_strlcpy, g_strlcat): completed tor's fix

View File

@ -1,3 +1,47 @@
2000-07-30 Tor Lillqvist <tml@iki.fi>
Finally, a new and improved IO Channel and condition watch
implementation for Win32. Based on code provided by Craig Setera.
When watching file descriptors, for which there is no select()
like functionality on Win32 that would work on all Win32 platforms
for all types of file descriptors (including anonymous pipes), we
start a new thread that blocks while trying to read from the file
descriptor. When the read returns, a Win32 Event is signalled that
the polling routine eventually notices. Meanwhile, the data being
read is stored in a circular buffer, from where the IO channel's
read() method picks it up.
If the buffer fills up the reading thread has to wait for space
becoming available. For this another Win32 Event is used. The IO
Channel's read() method signals this when it has read some data
out of the buffer.
The separate reader thread(s), and the circular buffer(s) with
associated events mean lots of possibilities for fun parallellism
errors. But it seems to work OK, i.e. GIMP runs.
* gmain.c: Small changes to the Win32 polling function.
(g_main_win32_get_poll_func): New function. Perhaps it would be a
good idea to provide this on all platforms.
* giowin32.c: The bulk of the new implementation.
(g_io_channel_win32_wait_for_condition): New function. To be used
where on Unix one does a select() on the channel's fd, like
libgimp's gimp_extension_process(). Could be provided on all
platforms.
* glib.h: Update documentation for IO Channels on Win32. Remove
the declarations for the as of now obsolete old functions related
to IO Channels for pipes with "wakeup" messages.
* glib.def: Some new functions.
* tests/gio-test.c: New file, to test GIOChannel and main loop.
* tests/Makefile.am
* tests/makefile.mingw.in: Add it.
Thu Jul 27 05:15:11 2000 Tim Janik <timj@gtk.org>
* gstrfuncs.c (g_strlcpy, g_strlcat): completed tor's fix

1157
giowin32.c

File diff suppressed because it is too large Load Diff

View File

@ -160,11 +160,13 @@ EXPORTS
g_io_channel_unref
g_io_channel_win32_get_fd
g_io_channel_win32_new_messages
g_io_channel_win32_new_fd
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_pipe_readable
g_io_channel_win32_pipe_request_wakeups
g_io_channel_win32_wait_for_condition
g_io_channel_write
g_list_alloc
g_list_append
@ -207,6 +209,7 @@ EXPORTS
g_main_remove_poll
g_main_run
g_main_set_poll_func
g_main_win32_get_poll_func
g_malloc
g_malloc0
g_mem_check

66
glib.h
View File

@ -2881,29 +2881,43 @@ void g_main_add_poll (GPollFD *fd,
void g_main_remove_poll (GPollFD *fd);
void g_main_set_poll_func (GPollFunc func);
#ifdef G_OS_WIN32
/* Useful on other platforms, too? */
GPollFunc g_main_win32_get_poll_func (void);
#endif
/* On Unix, IO channels created with this function for any file
* descriptor or socket.
*
* On Win32, use this only for plain files opened with the MSVCRT (the
* Microsoft run-time C library) _open(), including file descriptors
* 0, 1 and 2 (corresponding to stdin, stdout and stderr).
* Actually, don't do even that, this code isn't done yet.
* On Win32, use this only for files opened with the MSVCRT (the
* Microsoft run-time C library) _open() or _pipe, including file
* descriptors 0, 1 and 2 (corresponding to stdin, stdout and stderr).
*
* The term file descriptor as used in the context of Win32 refers to
* the emulated Unix-like file descriptors MSVCRT provides.
* the emulated Unix-like file descriptors MSVCRT provides. The native
* corresponding concept is file HANDLE. There isn't as of yet a way to
* get GIOChannels for file HANDLEs.
*/
GIOChannel* g_io_channel_unix_new (int fd);
gint g_io_channel_unix_get_fd (GIOChannel *channel);
#ifdef G_OS_WIN32
GLIB_VAR guint g_pipe_readable_msg;
#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?
*/
gint g_io_channel_win32_wait_for_condition (GIOChannel *channel,
GIOCondition condition,
gint timeout);
/* This is used to add polling for Windows messages. GDK (GTk+) programs
* should *not* use this. (In fact, I can't think of any program that
* would want to use this, but it's here just for completeness's sake.
* should *not* use this.
*/
void g_main_poll_win32_msg_add(gint priority,
GPollFD *fd,
@ -2912,40 +2926,16 @@ void g_main_poll_win32_msg_add(gint priority,
/* An IO channel for Windows messages for window handle hwnd. */
GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
/* An IO channel for an anonymous pipe as returned from the MSVCRT
* _pipe(), with no mechanism for the writer to tell the reader when
* there is data in the pipe.
*
* This is not really implemented yet.
/* An IO channel for C runtime (emulated Unix-like) file
* descriptors. Identical to g_io_channel_unix_new above.
*/
GIOChannel *g_io_channel_win32_new_pipe (int fd);
/* An IO channel for a pipe as returned from the MSVCRT _pipe(), with
* Windows user messages used to signal data in the pipe for the
* reader.
*
* fd is the file descriptor. For the write end, peer is the thread id
* of the reader, and peer_fd is his file descriptor for the read end
* of the pipe.
*
* This is used by the GIMP, and works.
*/
GIOChannel *g_io_channel_win32_new_pipe_with_wakeups (int fd,
guint peer,
int peer_fd);
void g_io_channel_win32_pipe_request_wakeups (GIOChannel *channel,
guint peer,
int peer_fd);
void g_io_channel_win32_pipe_readable (int fd,
guint offset);
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 is
* actually a SOCKET.
/* An IO channel for a SOCK_STREAM winsock socket. The parameter should
* be a SOCKET.
*/
GIOChannel *g_io_channel_win32_new_stream_socket (int socket);

File diff suppressed because it is too large Load Diff

View File

@ -160,11 +160,13 @@ EXPORTS
g_io_channel_unref
g_io_channel_win32_get_fd
g_io_channel_win32_new_messages
g_io_channel_win32_new_fd
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_pipe_readable
g_io_channel_win32_pipe_request_wakeups
g_io_channel_win32_wait_for_condition
g_io_channel_write
g_list_alloc
g_list_append
@ -207,6 +209,7 @@ EXPORTS
g_main_remove_poll
g_main_run
g_main_set_poll_func
g_main_win32_get_poll_func
g_malloc
g_malloc0
g_mem_check

View File

@ -2881,29 +2881,43 @@ void g_main_add_poll (GPollFD *fd,
void g_main_remove_poll (GPollFD *fd);
void g_main_set_poll_func (GPollFunc func);
#ifdef G_OS_WIN32
/* Useful on other platforms, too? */
GPollFunc g_main_win32_get_poll_func (void);
#endif
/* On Unix, IO channels created with this function for any file
* descriptor or socket.
*
* On Win32, use this only for plain files opened with the MSVCRT (the
* Microsoft run-time C library) _open(), including file descriptors
* 0, 1 and 2 (corresponding to stdin, stdout and stderr).
* Actually, don't do even that, this code isn't done yet.
* On Win32, use this only for files opened with the MSVCRT (the
* Microsoft run-time C library) _open() or _pipe, including file
* descriptors 0, 1 and 2 (corresponding to stdin, stdout and stderr).
*
* The term file descriptor as used in the context of Win32 refers to
* the emulated Unix-like file descriptors MSVCRT provides.
* the emulated Unix-like file descriptors MSVCRT provides. The native
* corresponding concept is file HANDLE. There isn't as of yet a way to
* get GIOChannels for file HANDLEs.
*/
GIOChannel* g_io_channel_unix_new (int fd);
gint g_io_channel_unix_get_fd (GIOChannel *channel);
#ifdef G_OS_WIN32
GLIB_VAR guint g_pipe_readable_msg;
#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?
*/
gint g_io_channel_win32_wait_for_condition (GIOChannel *channel,
GIOCondition condition,
gint timeout);
/* This is used to add polling for Windows messages. GDK (GTk+) programs
* should *not* use this. (In fact, I can't think of any program that
* would want to use this, but it's here just for completeness's sake.
* should *not* use this.
*/
void g_main_poll_win32_msg_add(gint priority,
GPollFD *fd,
@ -2912,40 +2926,16 @@ void g_main_poll_win32_msg_add(gint priority,
/* An IO channel for Windows messages for window handle hwnd. */
GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
/* An IO channel for an anonymous pipe as returned from the MSVCRT
* _pipe(), with no mechanism for the writer to tell the reader when
* there is data in the pipe.
*
* This is not really implemented yet.
/* An IO channel for C runtime (emulated Unix-like) file
* descriptors. Identical to g_io_channel_unix_new above.
*/
GIOChannel *g_io_channel_win32_new_pipe (int fd);
/* An IO channel for a pipe as returned from the MSVCRT _pipe(), with
* Windows user messages used to signal data in the pipe for the
* reader.
*
* fd is the file descriptor. For the write end, peer is the thread id
* of the reader, and peer_fd is his file descriptor for the read end
* of the pipe.
*
* This is used by the GIMP, and works.
*/
GIOChannel *g_io_channel_win32_new_pipe_with_wakeups (int fd,
guint peer,
int peer_fd);
void g_io_channel_win32_pipe_request_wakeups (GIOChannel *channel,
guint peer,
int peer_fd);
void g_io_channel_win32_pipe_readable (int fd,
guint offset);
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 is
* actually a SOCKET.
/* An IO channel for a SOCK_STREAM winsock socket. The parameter should
* be a SOCKET.
*/
GIOChannel *g_io_channel_win32_new_stream_socket (int socket);

View File

@ -36,8 +36,6 @@
/* uncomment the next line to get poll() debugging info */
/* #define G_MAIN_POLL_DEBUG */
#include "glib.h"
#include <sys/types.h>
#include <time.h>
@ -192,34 +190,39 @@ static GPollFunc poll_func = (GPollFunc) poll;
#ifdef G_OS_WIN32
static gint
g_poll (GPollFD *fds, guint nfds, gint timeout)
g_poll (GPollFD *fds,
guint nfds,
gint timeout)
{
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
gboolean poll_msgs = FALSE;
GPollFD *f;
DWORD ready;
MSG msg;
UINT timer;
LONG prevcnt;
gint poll_msgs = -1;
gint nhandles = 0;
for (f = fds; f < &fds[nfds]; ++f)
if (f->fd >= 0)
{
if (f->events & G_IO_IN)
if (f->fd == G_WIN32_MSG_HANDLE)
poll_msgs = f - fds;
else
{
/* g_print ("g_poll: waiting for handle %#x\n", f->fd); */
handles[nhandles++] = (HANDLE) f->fd;
}
{
if (f->fd == G_WIN32_MSG_HANDLE)
poll_msgs = TRUE;
else
{
#ifdef G_MAIN_POLL_DEBUG
g_print ("g_poll: waiting for %#x\n", f->fd);
#endif
handles[nhandles++] = (HANDLE) f->fd;
}
}
}
if (timeout == -1)
timeout = INFINITE;
if (poll_msgs >= 0)
if (poll_msgs)
{
/* Waiting for messages, and maybe events */
if (nhandles == 0)
@ -229,7 +232,9 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
/* Waiting just for messages, infinite timeout
* -> Use PeekMessage, then WaitMessage
*/
/* g_print ("WaitMessage, PeekMessage\n"); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage, then WaitMessage\n");
#endif
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0;
else if (!WaitMessage ())
@ -241,7 +246,9 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
/* Waiting just for messages, zero timeout
* -> Use PeekMessage
*/
/* g_print ("PeekMessage\n"); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage\n");
#endif
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0;
else
@ -253,17 +260,22 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
* -> First try PeekMessage, then set a timer, wait for message,
* kill timer, use PeekMessage
*/
/* g_print ("PeekMessage\n"); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage\n");
#endif
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0;
else if ((timer = SetTimer (NULL, 0, timeout, NULL)) == 0)
g_warning ("g_poll: SetTimer failed");
else
{
/* g_print ("WaitMessage\n"); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("WaitMessage\n");
#endif
WaitMessage ();
KillTimer (NULL, timer);
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)
&& msg.message != WM_TIMER)
ready = WAIT_OBJECT_0;
else
ready = WAIT_TIMEOUT;
@ -275,10 +287,12 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
/* Wait for either message or event
* -> Use MsgWaitForMultipleObjects
*/
/* g_print ("MsgWaitForMultipleObjects(%d, %d)\n", nhandles, timeout); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("MsgWaitForMultipleObjects(%d, %d)\n", nhandles, timeout);
#endif
ready = MsgWaitForMultipleObjects (nhandles, handles, FALSE,
timeout, QS_ALLINPUT);
/* g_print("=%d\n", ready); */
if (ready == WAIT_FAILED)
g_warning ("g_poll: MsgWaitForMultipleObjects failed");
}
@ -293,9 +307,10 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
/* Wait for just events
* -> Use WaitForMultipleObjects
*/
/* g_print ("WaitForMultipleObjects(%d, %d)\n", nhandles, timeout); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("WaitForMultipleObjects(%d, %d)\n", nhandles, timeout);
#endif
ready = WaitForMultipleObjects (nhandles, handles, FALSE, timeout);
/* g_print("=%d\n", ready); */
if (ready == WAIT_FAILED)
g_warning ("g_poll: WaitForMultipleObjects failed");
}
@ -305,9 +320,17 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
if (ready == WAIT_FAILED)
return -1;
else if (poll_msgs >= 0 && ready == WAIT_OBJECT_0 + nhandles)
else if (ready == WAIT_TIMEOUT)
return 0;
else if (poll_msgs && ready == WAIT_OBJECT_0 + nhandles)
{
fds[poll_msgs].revents |= G_IO_IN;
for (f = fds; f < &fds[nfds]; ++f)
if (f->fd >= 0)
{
if (f->events & G_IO_IN)
if (f->fd == G_WIN32_MSG_HANDLE)
f->revents |= G_IO_IN;
}
}
else if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles)
for (f = fds; f < &fds[nfds]; ++f)
@ -316,15 +339,19 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
&& f->fd == (gint) handles[ready - WAIT_OBJECT_0])
{
f->revents |= G_IO_IN;
/* g_print ("event %#x\n", f->fd); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("g_poll: got event %#x\n", f->fd);
#endif
#if 0
ResetEvent ((HANDLE) f->fd);
#endif
}
}
if (ready == WAIT_TIMEOUT)
return 0;
if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles)
return ready - WAIT_OBJECT_0 + 1;
else
return 1;
return 0;
}
#else /* !G_OS_WIN32 */
@ -592,7 +619,6 @@ void
g_get_current_time (GTimeVal *result)
{
#ifndef G_OS_WIN32
struct timeval r;
g_return_if_fail (result != NULL);
/*this is required on alpha, there the timeval structs are int's
@ -608,7 +634,6 @@ g_get_current_time (GTimeVal *result)
static DWORD start_tick = 0;
static time_t start_time;
DWORD tick;
time_t t;
g_return_if_fail (result != NULL);
@ -992,9 +1017,12 @@ g_main_poll (gint timeout,
if (wake_up_semaphore == NULL)
{
if ((wake_up_semaphore = CreateSemaphore (NULL, 0, 100, NULL)) == NULL)
g_error ("Cannot create wake-up semaphore: %d", GetLastError ());
g_error ("Cannot create wake-up semaphore: %s", g_win32_error_message (GetLastError ()));
wake_up_rec.fd = (gint) wake_up_semaphore;
wake_up_rec.events = G_IO_IN;
#ifdef G_MAIN_POLL_DEBUG
g_print ("wake-up semaphore: %#x\n", (guint) wake_up_semaphore);
#endif
g_main_add_poll_unlocked (0, &wake_up_rec);
}
#endif
@ -1029,7 +1057,7 @@ g_main_poll (gint timeout,
if (npoll || timeout != 0)
{
#ifdef G_MAIN_POLL_DEBUG
g_print ("g_main_poll(%d) timeout: %d\r", npoll, timeout);
g_print ("g_main_poll(%d) timeout: %d\n", npoll, timeout);
poll_timer = g_timer_new ();
#endif
@ -1223,6 +1251,18 @@ g_main_set_poll_func (GPollFunc func)
#endif
}
#ifdef G_OS_WIN32
/* Useful on other platforms, too? */
GPollFunc
g_main_win32_get_poll_func (void)
{
return poll_func;
}
#endif
/* Wake the main loop up from a poll() */
static void
g_main_wakeup (void)

104
gmain.c
View File

@ -36,8 +36,6 @@
/* uncomment the next line to get poll() debugging info */
/* #define G_MAIN_POLL_DEBUG */
#include "glib.h"
#include <sys/types.h>
#include <time.h>
@ -192,34 +190,39 @@ static GPollFunc poll_func = (GPollFunc) poll;
#ifdef G_OS_WIN32
static gint
g_poll (GPollFD *fds, guint nfds, gint timeout)
g_poll (GPollFD *fds,
guint nfds,
gint timeout)
{
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
gboolean poll_msgs = FALSE;
GPollFD *f;
DWORD ready;
MSG msg;
UINT timer;
LONG prevcnt;
gint poll_msgs = -1;
gint nhandles = 0;
for (f = fds; f < &fds[nfds]; ++f)
if (f->fd >= 0)
{
if (f->events & G_IO_IN)
if (f->fd == G_WIN32_MSG_HANDLE)
poll_msgs = f - fds;
else
{
/* g_print ("g_poll: waiting for handle %#x\n", f->fd); */
handles[nhandles++] = (HANDLE) f->fd;
}
{
if (f->fd == G_WIN32_MSG_HANDLE)
poll_msgs = TRUE;
else
{
#ifdef G_MAIN_POLL_DEBUG
g_print ("g_poll: waiting for %#x\n", f->fd);
#endif
handles[nhandles++] = (HANDLE) f->fd;
}
}
}
if (timeout == -1)
timeout = INFINITE;
if (poll_msgs >= 0)
if (poll_msgs)
{
/* Waiting for messages, and maybe events */
if (nhandles == 0)
@ -229,7 +232,9 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
/* Waiting just for messages, infinite timeout
* -> Use PeekMessage, then WaitMessage
*/
/* g_print ("WaitMessage, PeekMessage\n"); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage, then WaitMessage\n");
#endif
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0;
else if (!WaitMessage ())
@ -241,7 +246,9 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
/* Waiting just for messages, zero timeout
* -> Use PeekMessage
*/
/* g_print ("PeekMessage\n"); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage\n");
#endif
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0;
else
@ -253,17 +260,22 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
* -> First try PeekMessage, then set a timer, wait for message,
* kill timer, use PeekMessage
*/
/* g_print ("PeekMessage\n"); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage\n");
#endif
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0;
else if ((timer = SetTimer (NULL, 0, timeout, NULL)) == 0)
g_warning ("g_poll: SetTimer failed");
else
{
/* g_print ("WaitMessage\n"); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("WaitMessage\n");
#endif
WaitMessage ();
KillTimer (NULL, timer);
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)
&& msg.message != WM_TIMER)
ready = WAIT_OBJECT_0;
else
ready = WAIT_TIMEOUT;
@ -275,10 +287,12 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
/* Wait for either message or event
* -> Use MsgWaitForMultipleObjects
*/
/* g_print ("MsgWaitForMultipleObjects(%d, %d)\n", nhandles, timeout); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("MsgWaitForMultipleObjects(%d, %d)\n", nhandles, timeout);
#endif
ready = MsgWaitForMultipleObjects (nhandles, handles, FALSE,
timeout, QS_ALLINPUT);
/* g_print("=%d\n", ready); */
if (ready == WAIT_FAILED)
g_warning ("g_poll: MsgWaitForMultipleObjects failed");
}
@ -293,9 +307,10 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
/* Wait for just events
* -> Use WaitForMultipleObjects
*/
/* g_print ("WaitForMultipleObjects(%d, %d)\n", nhandles, timeout); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("WaitForMultipleObjects(%d, %d)\n", nhandles, timeout);
#endif
ready = WaitForMultipleObjects (nhandles, handles, FALSE, timeout);
/* g_print("=%d\n", ready); */
if (ready == WAIT_FAILED)
g_warning ("g_poll: WaitForMultipleObjects failed");
}
@ -305,9 +320,17 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
if (ready == WAIT_FAILED)
return -1;
else if (poll_msgs >= 0 && ready == WAIT_OBJECT_0 + nhandles)
else if (ready == WAIT_TIMEOUT)
return 0;
else if (poll_msgs && ready == WAIT_OBJECT_0 + nhandles)
{
fds[poll_msgs].revents |= G_IO_IN;
for (f = fds; f < &fds[nfds]; ++f)
if (f->fd >= 0)
{
if (f->events & G_IO_IN)
if (f->fd == G_WIN32_MSG_HANDLE)
f->revents |= G_IO_IN;
}
}
else if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles)
for (f = fds; f < &fds[nfds]; ++f)
@ -316,15 +339,19 @@ g_poll (GPollFD *fds, guint nfds, gint timeout)
&& f->fd == (gint) handles[ready - WAIT_OBJECT_0])
{
f->revents |= G_IO_IN;
/* g_print ("event %#x\n", f->fd); */
#ifdef G_MAIN_POLL_DEBUG
g_print ("g_poll: got event %#x\n", f->fd);
#endif
#if 0
ResetEvent ((HANDLE) f->fd);
#endif
}
}
if (ready == WAIT_TIMEOUT)
return 0;
if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles)
return ready - WAIT_OBJECT_0 + 1;
else
return 1;
return 0;
}
#else /* !G_OS_WIN32 */
@ -592,7 +619,6 @@ void
g_get_current_time (GTimeVal *result)
{
#ifndef G_OS_WIN32
struct timeval r;
g_return_if_fail (result != NULL);
/*this is required on alpha, there the timeval structs are int's
@ -608,7 +634,6 @@ g_get_current_time (GTimeVal *result)
static DWORD start_tick = 0;
static time_t start_time;
DWORD tick;
time_t t;
g_return_if_fail (result != NULL);
@ -992,9 +1017,12 @@ g_main_poll (gint timeout,
if (wake_up_semaphore == NULL)
{
if ((wake_up_semaphore = CreateSemaphore (NULL, 0, 100, NULL)) == NULL)
g_error ("Cannot create wake-up semaphore: %d", GetLastError ());
g_error ("Cannot create wake-up semaphore: %s", g_win32_error_message (GetLastError ()));
wake_up_rec.fd = (gint) wake_up_semaphore;
wake_up_rec.events = G_IO_IN;
#ifdef G_MAIN_POLL_DEBUG
g_print ("wake-up semaphore: %#x\n", (guint) wake_up_semaphore);
#endif
g_main_add_poll_unlocked (0, &wake_up_rec);
}
#endif
@ -1029,7 +1057,7 @@ g_main_poll (gint timeout,
if (npoll || timeout != 0)
{
#ifdef G_MAIN_POLL_DEBUG
g_print ("g_main_poll(%d) timeout: %d\r", npoll, timeout);
g_print ("g_main_poll(%d) timeout: %d\n", npoll, timeout);
poll_timer = g_timer_new ();
#endif
@ -1223,6 +1251,18 @@ g_main_set_poll_func (GPollFunc func)
#endif
}
#ifdef G_OS_WIN32
/* Useful on other platforms, too? */
GPollFunc
g_main_win32_get_poll_func (void)
{
return poll_func;
}
#endif
/* Wake the main loop up from a poll() */
static void
g_main_wakeup (void)

View File

@ -11,6 +11,7 @@ TESTS = \
array-test \
date-test \
dirname-test \
gio-test \
hash-test \
list-test \
node-test \
@ -33,6 +34,7 @@ thread_LDADD = $(progs_LDADD) $(top_builddir)/gthread/libgthread-1.3.la @G_THREA
array_test_LDADD = $(progs_LDADD)
date_test_LDADD = $(progs_LDADD)
dirname_test_LDADD = $(progs_LDADD)
gio_test_LDADD = $(progs_LDADD)
hash_test_LDADD = $(progs_LDADD)
list_test_LDADD = $(progs_LDADD)
node_test_LDADD = $(progs_LDADD)

285
tests/gio-test.c Normal file
View File

@ -0,0 +1,285 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 2000 Tor Lillqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* A test program for the main loop and IO channel code.
* Just run it.
*/
#include "config.h"
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#ifdef G_OS_WIN32
#include <io.h>
#include <fcntl.h>
#include <process.h>
#else
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#endif
static int nrunning;
static GMainLoop *main_loop;
#define BUFSIZE 5000 /* Larger than the circular buffer in
* giowin32.c on purpose.
*/
static int nkiddies;
static struct {
int fd;
int seq;
} *seqtab;
static gboolean
recv_message (GIOChannel *channel,
GIOCondition cond,
gpointer data)
{
gint fd = g_io_channel_unix_get_fd (channel);
g_print ("testgio: ...from %d:%s%s%s%s\n", fd,
(cond & G_IO_ERR) ? " ERR" : "",
(cond & G_IO_HUP) ? " HUP" : "",
(cond & G_IO_IN) ? " IN" : "",
(cond & G_IO_PRI) ? " PRI" : "");
if (cond & (G_IO_ERR | G_IO_HUP))
{
g_source_remove (*(guint *) data);
nrunning--;
if (nrunning == 0)
g_main_quit (main_loop);
}
if (cond & G_IO_IN)
{
char buf[BUFSIZE];
guint nbytes;
guint nb;
int i, j, seq;
GIOError error;
error = g_io_channel_read (channel, (gchar *) &seq, sizeof (seq), &nb);
if (error == G_IO_ERROR_NONE)
{
if (nb == 0)
{
g_print ("testgio: ...from %d: EOF\n", fd);
return FALSE;
}
g_assert (nb == sizeof (nbytes));
for (i = 0; i < nkiddies; i++)
if (seqtab[i].fd == fd)
{
if (seq != seqtab[i].seq)
{
g_print ("testgio: ...from &d: invalid sequence number %d, expected %d\n",
seq, seqtab[i].seq);
g_assert_not_reached ();
}
seqtab[i].seq++;
break;
}
error = g_io_channel_read (channel, (gchar *) &nbytes, sizeof (nbytes), &nb);
}
if (error != G_IO_ERROR_NONE)
{
g_print ("testgio: ...from %d: G_IO_ERROR_%s\n", fd,
(error == G_IO_ERROR_AGAIN ? "AGAIN" :
(error == G_IO_ERROR_INVAL ? "INVAL" :
(error == G_IO_ERROR_UNKNOWN ? "UNKNOWN" : "???"))));
return FALSE;
}
if (nb == 0)
{
g_print ("testgio: ...from %d: EOF\n", fd);
return FALSE;
}
g_assert (nb == sizeof (nbytes));
if (nbytes >= BUFSIZE)
{
g_print ("testgio: ...from %d: nbytes = %d (%#x)!\n", fd, nbytes, nbytes);
g_assert_not_reached ();
}
g_assert (nbytes >= 0 && nbytes < BUFSIZE);
g_print ("testgio: ...from %d: %d bytes\n", fd, nbytes);
if (nbytes > 0)
{
error = g_io_channel_read (channel, buf, nbytes, &nb);
if (error != G_IO_ERROR_NONE)
{
g_print ("testgio: ...from %d: G_IO_ERROR_%s\n", fd,
(error == G_IO_ERROR_AGAIN ? "AGAIN" :
(error == G_IO_ERROR_INVAL ? "INVAL" :
(error == G_IO_ERROR_UNKNOWN ? "UNKNOWN" : "???"))));
return FALSE;
}
if (nb != nbytes)
{
g_print ("testgio: ...from %d: nb=%d != nbytes=%d\n",
fd, nb, nbytes);
g_assert_not_reached ();
}
for (j = 0; j < nbytes; j++)
if (buf[j] != ' ' + ((nbytes + j) % 95))
{
g_print ("testgio: ...from %d: buf[%d] == '%c', should be '%c'\n",
fd, j, buf[j], 'a' + ((nbytes + j) % 32));
g_assert_not_reached ();
}
g_print ("testgio: ...from %d: OK\n", fd);
}
}
return TRUE;
}
int
main (int argc,
char **argv)
{
if (argc < 3)
{
/* Parent */
GIOChannel *my_read_channel;
gchar *cmdline;
guint *id;
int i;
#ifdef G_OS_WIN32
GTimeVal start, end;
int pollresult;
#endif
nkiddies = (argc == 1 ? 1 : atoi(argv[1]));
seqtab = g_malloc (nkiddies * 2 * sizeof (int));
for (i = 0; i < nkiddies; i++)
{
int pipe_to_sub[2], pipe_from_sub[2];
if (pipe (pipe_to_sub) == -1 ||
pipe (pipe_from_sub) == -1)
perror ("pipe"), exit (1);
seqtab[i].fd = pipe_from_sub[0];
seqtab[i].seq = 0;
my_read_channel = g_io_channel_unix_new (pipe_from_sub[0]);
id = g_new (guint, 1);
*id =
g_io_add_watch (my_read_channel,
G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
recv_message,
id);
cmdline = g_strdup_printf ("%s %d %d &", argv[0],
pipe_to_sub[0], pipe_from_sub[1]);
nrunning++;
#ifdef G_OS_WIN32
{
gchar *readfd = g_strdup_printf ("%d", pipe_to_sub[0]);
gchar *writefd = g_strdup_printf ("%d", pipe_from_sub[1]);
_spawnl (_P_NOWAIT, argv[0], argv[0], readfd, writefd, NULL);
}
#else
system (cmdline);
#endif
close (pipe_to_sub[0]);
close (pipe_from_sub [1]);
#ifdef G_OS_WIN32
g_get_current_time (&start);
pollresult = g_io_channel_win32_wait_for_condition (my_read_channel, G_IO_IN, 100);
g_get_current_time (&end);
if (end.tv_usec < start.tv_usec)
end.tv_sec--, end.tv_usec += 1000000;
g_print ("testgio: had to wait %ld.%03ld s, result:%d\n",
end.tv_sec - start.tv_sec,
(end.tv_usec - start.tv_usec) / 1000,
pollresult);
#endif
}
main_loop = g_main_new (FALSE);
g_main_run (main_loop);
}
else if (argc == 3)
{
/* Child */
int readfd, writefd;
int i, j;
char buf[BUFSIZE];
int buflen;
GTimeVal tv;
g_get_current_time (&tv);
readfd = atoi (argv[1]);
writefd = atoi (argv[2]);
srand (tv.tv_sec ^ (tv.tv_usec / 1000) ^ readfd ^ (writefd << 4));
for (i = 0; i < 20 + rand() % 20; i++)
{
g_usleep (100 + (rand() % 10) * 5000);
buflen = rand() % BUFSIZE;
for (j = 0; j < buflen; j++)
buf[j] = ' ' + ((buflen + j) % 95);
g_print ("testgio: child writing %d bytes to %d\n", buflen, writefd);
write (writefd, &i, sizeof (i));
write (writefd, &buflen, sizeof (buflen));
write (writefd, buf, buflen);
}
g_print ("testgio: child exiting, closing %d\n", writefd);
close (writefd);
}
else
g_print ("Huh?\n");
return 0;
}

View File

@ -18,6 +18,7 @@ TESTS = \
array-test.exe \
date-test.exe \
dirname-test.exe\
gio-test.exe \
hash-test.exe \
list-test.exe \
node-test.exe \