Commit 8a0df0a7 authored by Tor Lillqvist's avatar Tor Lillqvist Committed by Tor Lillqvist

Socket support rewritten. It was utterly broken, and untested in fact. We

2001-01-25  Tor Lillqvist  <tml@iki.fi>

	* giowin32.c: Socket support rewritten. It was utterly broken, and
	untested in fact. We still do use a thread for each socket being
	watched, but instead of blocking in recv() (which of course was
	plain stupid for sockets being liste()ed on), we block in
	select(). The read method for sockets calls recv(). It is now
	possible for the application to call accept(), recv() or send() in
	the callback, just like on Unix. Tested with code kindly provided
	by Andrew Lanoix.

	Rename g_io_channel_win32_new_stream_socket() to
	g_io_channel_win32_new_socket() as it isn't restricted to stream
	sockets.

	* gmain.c (g_poll): Related changes in the Win32 version of
	g_poll(). When polling for messages, always do a PeekMessage()
	first. We used to miss messages if several were posted between
	calls to g_poll().

	* giochannel.h: Improve Win32-related comments.

	* gutf8.c: (Win32) Include <stdio.h> for sprintf.

	* tests/gio-test.c: (Win32) Add tests for polling for Windows
	messages.

	* tests/makefile.mingw.in: Remove superfluous compilation command
	line.
parent 9f9ad360
2001-01-25 Tor Lillqvist <tml@iki.fi>
* giowin32.c: Socket support rewritten. It was utterly broken, and
untested in fact. We still do use a thread for each socket being
watched, but instead of blocking in recv() (which of course was
plain stupid for sockets being liste()ed on), we block in
select(). The read method for sockets calls recv(). It is now
possible for the application to call accept(), recv() or send() in
the callback, just like on Unix. Tested with code kindly provided
by Andrew Lanoix.
Rename g_io_channel_win32_new_stream_socket() to
g_io_channel_win32_new_socket() as it isn't restricted to stream
sockets.
* gmain.c (g_poll): Related changes in the Win32 version of
g_poll(). When polling for messages, always do a PeekMessage()
first. We used to miss messages if several were posted between
calls to g_poll().
* giochannel.h: Improve Win32-related comments.
* gutf8.c: (Win32) Include <stdio.h> for sprintf.
* tests/gio-test.c: (Win32) Add tests for polling for Windows
messages.
* tests/makefile.mingw.in: Remove superfluous compilation command
line.
2001-01-23 <alexl@redhat.com>
* gmain.c (g_source_callback_unref): Free the callback
......
2001-01-25 Tor Lillqvist <tml@iki.fi>
* giowin32.c: Socket support rewritten. It was utterly broken, and
untested in fact. We still do use a thread for each socket being
watched, but instead of blocking in recv() (which of course was
plain stupid for sockets being liste()ed on), we block in
select(). The read method for sockets calls recv(). It is now
possible for the application to call accept(), recv() or send() in
the callback, just like on Unix. Tested with code kindly provided
by Andrew Lanoix.
Rename g_io_channel_win32_new_stream_socket() to
g_io_channel_win32_new_socket() as it isn't restricted to stream
sockets.
* gmain.c (g_poll): Related changes in the Win32 version of
g_poll(). When polling for messages, always do a PeekMessage()
first. We used to miss messages if several were posted between
calls to g_poll().
* giochannel.h: Improve Win32-related comments.
* gutf8.c: (Win32) Include <stdio.h> for sprintf.
* tests/gio-test.c: (Win32) Add tests for polling for Windows
messages.
* tests/makefile.mingw.in: Remove superfluous compilation command
line.
2001-01-23 <alexl@redhat.com>
* gmain.c (g_source_callback_unref): Free the callback
......
2001-01-25 Tor Lillqvist <tml@iki.fi>
* giowin32.c: Socket support rewritten. It was utterly broken, and
untested in fact. We still do use a thread for each socket being
watched, but instead of blocking in recv() (which of course was
plain stupid for sockets being liste()ed on), we block in
select(). The read method for sockets calls recv(). It is now
possible for the application to call accept(), recv() or send() in
the callback, just like on Unix. Tested with code kindly provided
by Andrew Lanoix.
Rename g_io_channel_win32_new_stream_socket() to
g_io_channel_win32_new_socket() as it isn't restricted to stream
sockets.
* gmain.c (g_poll): Related changes in the Win32 version of
g_poll(). When polling for messages, always do a PeekMessage()
first. We used to miss messages if several were posted between
calls to g_poll().
* giochannel.h: Improve Win32-related comments.
* gutf8.c: (Win32) Include <stdio.h> for sprintf.
* tests/gio-test.c: (Win32) Add tests for polling for Windows
messages.
* tests/makefile.mingw.in: Remove superfluous compilation command
line.
2001-01-23 <alexl@redhat.com>
* gmain.c (g_source_callback_unref): Free the callback
......
2001-01-25 Tor Lillqvist <tml@iki.fi>
* giowin32.c: Socket support rewritten. It was utterly broken, and
untested in fact. We still do use a thread for each socket being
watched, but instead of blocking in recv() (which of course was
plain stupid for sockets being liste()ed on), we block in
select(). The read method for sockets calls recv(). It is now
possible for the application to call accept(), recv() or send() in
the callback, just like on Unix. Tested with code kindly provided
by Andrew Lanoix.
Rename g_io_channel_win32_new_stream_socket() to
g_io_channel_win32_new_socket() as it isn't restricted to stream
sockets.
* gmain.c (g_poll): Related changes in the Win32 version of
g_poll(). When polling for messages, always do a PeekMessage()
first. We used to miss messages if several were posted between
calls to g_poll().
* giochannel.h: Improve Win32-related comments.
* gutf8.c: (Win32) Include <stdio.h> for sprintf.
* tests/gio-test.c: (Win32) Add tests for polling for Windows
messages.
* tests/makefile.mingw.in: Remove superfluous compilation command
line.
2001-01-23 <alexl@redhat.com>
* gmain.c (g_source_callback_unref): Free the callback
......
2001-01-25 Tor Lillqvist <tml@iki.fi>
* giowin32.c: Socket support rewritten. It was utterly broken, and
untested in fact. We still do use a thread for each socket being
watched, but instead of blocking in recv() (which of course was
plain stupid for sockets being liste()ed on), we block in
select(). The read method for sockets calls recv(). It is now
possible for the application to call accept(), recv() or send() in
the callback, just like on Unix. Tested with code kindly provided
by Andrew Lanoix.
Rename g_io_channel_win32_new_stream_socket() to
g_io_channel_win32_new_socket() as it isn't restricted to stream
sockets.
* gmain.c (g_poll): Related changes in the Win32 version of
g_poll(). When polling for messages, always do a PeekMessage()
first. We used to miss messages if several were posted between
calls to g_poll().
* giochannel.h: Improve Win32-related comments.
* gutf8.c: (Win32) Include <stdio.h> for sprintf.
* tests/gio-test.c: (Win32) Add tests for polling for Windows
messages.
* tests/makefile.mingw.in: Remove superfluous compilation command
line.
2001-01-23 <alexl@redhat.com>
* gmain.c (g_source_callback_unref): Free the callback
......
2001-01-25 Tor Lillqvist <tml@iki.fi>
* giowin32.c: Socket support rewritten. It was utterly broken, and
untested in fact. We still do use a thread for each socket being
watched, but instead of blocking in recv() (which of course was
plain stupid for sockets being liste()ed on), we block in
select(). The read method for sockets calls recv(). It is now
possible for the application to call accept(), recv() or send() in
the callback, just like on Unix. Tested with code kindly provided
by Andrew Lanoix.
Rename g_io_channel_win32_new_stream_socket() to
g_io_channel_win32_new_socket() as it isn't restricted to stream
sockets.
* gmain.c (g_poll): Related changes in the Win32 version of
g_poll(). When polling for messages, always do a PeekMessage()
first. We used to miss messages if several were posted between
calls to g_poll().
* giochannel.h: Improve Win32-related comments.
* gutf8.c: (Win32) Include <stdio.h> for sprintf.
* tests/gio-test.c: (Win32) Add tests for polling for Windows
messages.
* tests/makefile.mingw.in: Remove superfluous compilation command
line.
2001-01-23 <alexl@redhat.com>
* gmain.c (g_source_callback_unref): Free the callback
......
2001-01-25 Tor Lillqvist <tml@iki.fi>
* giowin32.c: Socket support rewritten. It was utterly broken, and
untested in fact. We still do use a thread for each socket being
watched, but instead of blocking in recv() (which of course was
plain stupid for sockets being liste()ed on), we block in
select(). The read method for sockets calls recv(). It is now
possible for the application to call accept(), recv() or send() in
the callback, just like on Unix. Tested with code kindly provided
by Andrew Lanoix.
Rename g_io_channel_win32_new_stream_socket() to
g_io_channel_win32_new_socket() as it isn't restricted to stream
sockets.
* gmain.c (g_poll): Related changes in the Win32 version of
g_poll(). When polling for messages, always do a PeekMessage()
first. We used to miss messages if several were posted between
calls to g_poll().
* giochannel.h: Improve Win32-related comments.
* gutf8.c: (Win32) Include <stdio.h> for sprintf.
* tests/gio-test.c: (Win32) Add tests for polling for Windows
messages.
* tests/makefile.mingw.in: Remove superfluous compilation command
line.
2001-01-23 <alexl@redhat.com>
* gmain.c (g_source_callback_unref): Free the callback
......
2001-01-25 Tor Lillqvist <tml@iki.fi>
* giowin32.c: Socket support rewritten. It was utterly broken, and
untested in fact. We still do use a thread for each socket being
watched, but instead of blocking in recv() (which of course was
plain stupid for sockets being liste()ed on), we block in
select(). The read method for sockets calls recv(). It is now
possible for the application to call accept(), recv() or send() in
the callback, just like on Unix. Tested with code kindly provided
by Andrew Lanoix.
Rename g_io_channel_win32_new_stream_socket() to
g_io_channel_win32_new_socket() as it isn't restricted to stream
sockets.
* gmain.c (g_poll): Related changes in the Win32 version of
g_poll(). When polling for messages, always do a PeekMessage()
first. We used to miss messages if several were posted between
calls to g_poll().
* giochannel.h: Improve Win32-related comments.
* gutf8.c: (Win32) Include <stdio.h> for sprintf.
* tests/gio-test.c: (Win32) Add tests for polling for Windows
messages.
* tests/makefile.mingw.in: Remove superfluous compilation command
line.
2001-01-23 <alexl@redhat.com>
* gmain.c (g_source_callback_unref): Free the callback
......
......@@ -120,14 +120,20 @@ guint g_io_add_watch (GIOChannel *channel,
/* On Unix, IO channels created with this function for any file
* descriptor or socket.
*
* 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).
* On Win32, this can be used either 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),
* or for Winsock SOCKETs. If the parameter is a legal file
* descriptor, it is assumed to be such, otherwise it should be a
* SOCKET. This relies on SOCKETs and file descriptors not
* overlapping. If you want to be certain, call either
* g_io_channel_win32_new_fd() or g_io_channel_win32_new_socket()
* instead as appropriate.
*
* The term file descriptor as used in the context of Win32 refers to
* 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.
* get GIOChannels for Win32 file HANDLEs.
*/
GIOChannel* g_io_channel_unix_new (int fd);
gint g_io_channel_unix_get_fd (GIOChannel *channel);
......@@ -139,7 +145,8 @@ gint g_io_channel_unix_get_fd (GIOChannel *channel);
/* 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.
* from the underlying file descriptor. For SOCKETs, it is possible to call
* recv().
*/
void g_io_channel_win32_make_pollfd (GIOChannel *channel,
GIOCondition condition,
......@@ -147,7 +154,6 @@ void g_io_channel_win32_make_pollfd (GIOChannel *channel,
/* 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,
......@@ -160,25 +166,29 @@ void g_main_poll_win32_msg_add (gint priority,
GPollFD *fd,
guint hwnd);
/* An IO channel for Windows messages for window handle hwnd. */
/* Create an IO channel for Windows messages for window handle hwnd. */
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.
/* Create an IO channel for C runtime (emulated Unix-like) file
* descriptors. After calling g_io_add_watch() on a IO channel
* returned by this function, you shouldn't call read() on the file
* descriptor. This is because adding polling for a file descriptor is
* implemented on Win32 by starting a thread that sits blocked in a
* read() from the file descriptor most of the time. All reads from
* the file descriptor should be done by this internal GLib
* thread. Your code should call only g_io_channel_read().
*/
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. After calling g_io_add_watch() on a IO channel
* returned by this function, you shouldn't call recv() on the SOCKET.
/* Create an IO channel for a winsock socket. The parameter should be
* a SOCKET. Contrary to IO channels for file descriptors (on *Win32),
* you can use normal recv() or recvfrom() on sockets even if GLib
* is polling them.
*/
GIOChannel *g_io_channel_win32_new_stream_socket (int socket);
GIOChannel *g_io_channel_win32_new_socket (int socket);
#endif
......
This diff is collapsed.
......@@ -180,6 +180,7 @@ EXPORTS
g_io_channel_win32_make_pollfd
g_io_channel_win32_new_fd
g_io_channel_win32_new_messages
g_io_channel_win32_new_socket
g_io_channel_win32_new_stream_socket
g_io_channel_win32_poll
g_io_channel_win32_set_debug
......
......@@ -120,14 +120,20 @@ guint g_io_add_watch (GIOChannel *channel,
/* On Unix, IO channels created with this function for any file
* descriptor or socket.
*
* 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).
* On Win32, this can be used either 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),
* or for Winsock SOCKETs. If the parameter is a legal file
* descriptor, it is assumed to be such, otherwise it should be a
* SOCKET. This relies on SOCKETs and file descriptors not
* overlapping. If you want to be certain, call either
* g_io_channel_win32_new_fd() or g_io_channel_win32_new_socket()
* instead as appropriate.
*
* The term file descriptor as used in the context of Win32 refers to
* 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.
* get GIOChannels for Win32 file HANDLEs.
*/
GIOChannel* g_io_channel_unix_new (int fd);
gint g_io_channel_unix_get_fd (GIOChannel *channel);
......@@ -139,7 +145,8 @@ gint g_io_channel_unix_get_fd (GIOChannel *channel);
/* 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.
* from the underlying file descriptor. For SOCKETs, it is possible to call
* recv().
*/
void g_io_channel_win32_make_pollfd (GIOChannel *channel,
GIOCondition condition,
......@@ -147,7 +154,6 @@ void g_io_channel_win32_make_pollfd (GIOChannel *channel,
/* 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,
......@@ -160,25 +166,29 @@ void g_main_poll_win32_msg_add (gint priority,
GPollFD *fd,
guint hwnd);
/* An IO channel for Windows messages for window handle hwnd. */
/* Create an IO channel for Windows messages for window handle hwnd. */
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.
/* Create an IO channel for C runtime (emulated Unix-like) file
* descriptors. After calling g_io_add_watch() on a IO channel
* returned by this function, you shouldn't call read() on the file
* descriptor. This is because adding polling for a file descriptor is
* implemented on Win32 by starting a thread that sits blocked in a
* read() from the file descriptor most of the time. All reads from
* the file descriptor should be done by this internal GLib
* thread. Your code should call only g_io_channel_read().
*/
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. After calling g_io_add_watch() on a IO channel
* returned by this function, you shouldn't call recv() on the SOCKET.
/* Create an IO channel for a winsock socket. The parameter should be
* a SOCKET. Contrary to IO channels for file descriptors (on *Win32),
* you can use normal recv() or recvfrom() on sockets even if GLib
* is polling them.
*/
GIOChannel *g_io_channel_win32_new_stream_socket (int socket);
GIOChannel *g_io_channel_win32_new_socket (int socket);
#endif
......
This diff is collapsed.
......@@ -180,6 +180,7 @@ EXPORTS
g_io_channel_win32_make_pollfd
g_io_channel_win32_new_fd
g_io_channel_win32_new_messages
g_io_channel_win32_new_socket
g_io_channel_win32_new_stream_socket
g_io_channel_win32_poll
g_io_channel_win32_set_debug
......
......@@ -272,77 +272,78 @@ g_poll (GPollFD *fds,
if (poll_msgs)
{
/* Waiting for messages, and maybe events */
if (nhandles == 0)
{
if (timeout == INFINITE)
{
/* Waiting just for messages, infinite timeout
* -> Use PeekMessage, then WaitMessage
*/
/* Waiting for messages, and maybe events
* -> First PeekMessage
*/
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage, then WaitMessage\n");
g_print ("PeekMessage\n");
#endif
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0;
else if (!WaitMessage ())
g_warning ("g_poll: WaitMessage failed");
ready = WAIT_OBJECT_0;
}
else if (timeout == 0)
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0 + nhandles;
else
{
if (nhandles == 0)
{
/* Waiting just for messages, zero timeout
* -> Use PeekMessage
*/
/* Waiting just for messages */
if (timeout == INFINITE)
{
/* Infinite timeout
* -> WaitMessage
*/
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage\n");
g_print ("WaitMessage\n");
#endif
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0;
if (!WaitMessage ())
g_warning ("g_poll: WaitMessage failed");
ready = WAIT_OBJECT_0 + nhandles;
}
else if (timeout == 0)
{
/* Waiting just for messages, zero timeout.
* If we got here, there was no message
*/
ready = WAIT_TIMEOUT;
}
else
ready = WAIT_TIMEOUT;
}
else
{
/* Waiting just for messages, some timeout
* -> First try PeekMessage, then set a timer, wait for message,
* kill timer, use PeekMessage
*/
{
/* Waiting just for messages, some timeout
* -> Set a timer, wait for message,
* kill timer, use PeekMessage
*/
if ((timer = SetTimer (NULL, 0, timeout, NULL)) == 0)
g_warning ("g_poll: SetTimer failed");
else
{
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage\n");
g_print ("WaitMessage\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
{
WaitMessage ();
KillTimer (NULL, timer);
#ifdef G_MAIN_POLL_DEBUG
g_print ("WaitMessage\n");
g_print ("PeekMessage\n");
#endif
WaitMessage ();
KillTimer (NULL, timer);
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)
&& msg.message != WM_TIMER)
ready = WAIT_OBJECT_0;
else
ready = WAIT_TIMEOUT;
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)
&& msg.message != WM_TIMER)
ready = WAIT_OBJECT_0;
else
ready = WAIT_TIMEOUT;
}
}
}
}
else
{
/* Wait for either message or event
* -> Use MsgWaitForMultipleObjects
*/
else
{
/* Wait for either message or event
* -> Use MsgWaitForMultipleObjects
*/
#ifdef G_MAIN_POLL_DEBUG
g_print ("MsgWaitForMultipleObjects(%d, %d)\n", nhandles, timeout);
g_print ("MsgWaitForMultipleObjects(%d, %d)\n", nhandles, timeout);
#endif
ready = MsgWaitForMultipleObjects (nhandles, handles, FALSE,
timeout, QS_ALLINPUT);
ready = MsgWaitForMultipleObjects (nhandles, handles, FALSE,
timeout, QS_ALLINPUT);
if (ready == WAIT_FAILED)
g_warning ("g_poll: MsgWaitForMultipleObjects failed");
if (ready == WAIT_FAILED)
g_warning ("g_poll: MsgWaitForMultipleObjects failed");
}
}
}
else if (nhandles == 0)
......@@ -363,6 +364,13 @@ g_poll (GPollFD *fds,
g_warning ("g_poll: WaitForMultipleObjects failed");
}
#ifdef G_MAIN_POLL_DEBUG
g_print ("wait returns %d%s\n",
ready,
(ready == WAIT_FAILED ? " (WAIT_FAILED)" :
(ready == WAIT_TIMEOUT ? " (WAIT_TIMEOUT)" :
(poll_msgs && ready == WAIT_OBJECT_0 + nhandles ? " (msg)" : ""))));
#endif
for (f = fds; f < &fds[nfds]; ++f)
f->revents = 0;
......@@ -380,6 +388,7 @@ g_poll (GPollFD *fds,
f->revents |= G_IO_IN;
}
}
#if TEST_WITHOUT_THIS
else if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles)
for (f = fds; f < &fds[nfds]; ++f)
{
......@@ -395,11 +404,9 @@ g_poll (GPollFD *fds,
#endif
}
}
#endif
if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles)
return ready - WAIT_OBJECT_0 + 1;
else
return 0;
return 1;
}
#else /* !G_OS_WIN32 */
......
......@@ -30,6 +30,8 @@
#include "glib.h"
#ifdef G_OS_WIN32
#include <stdio.h>
#define STRICT
#include <windows.h>
#endif
......
......@@ -272,77 +272,78 @@ g_poll (GPollFD *fds,
if (poll_msgs)
{
/* Waiting for messages, and maybe events */
if (nhandles == 0)
{
if (timeout == INFINITE)
{
/* Waiting just for messages, infinite timeout
* -> Use PeekMessage, then WaitMessage
*/
/* Waiting for messages, and maybe events
* -> First PeekMessage
*/
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage, then WaitMessage\n");
g_print ("PeekMessage\n");
#endif
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0;
else if (!WaitMessage ())
g_warning ("g_poll: WaitMessage failed");
ready = WAIT_OBJECT_0;
}
else if (timeout == 0)
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0 + nhandles;
else
{
if (nhandles == 0)
{
/* Waiting just for messages, zero timeout
* -> Use PeekMessage
*/
/* Waiting just for messages */
if (timeout == INFINITE)
{
/* Infinite timeout
* -> WaitMessage
*/
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage\n");
g_print ("WaitMessage\n");
#endif
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
ready = WAIT_OBJECT_0;
if (!WaitMessage ())
g_warning ("g_poll: WaitMessage failed");
ready = WAIT_OBJECT_0 + nhandles;
}
else if (timeout == 0)
{
/* Waiting just for messages, zero timeout.
* If we got here, there was no message
*/
ready = WAIT_TIMEOUT;
}
else
ready = WAIT_TIMEOUT;
}
else
{
/* Waiting just for messages, some timeout
* -> First try PeekMessage, then set a timer, wait for message,
* kill timer, use PeekMessage
*/
{
/* Waiting just for messages, some timeout
* -> Set a timer, wait for message,
* kill timer, use PeekMessage
*/
if ((timer = SetTimer (NULL, 0, timeout, NULL)) == 0)
g_warning ("g_poll: SetTimer failed");
else
{
#ifdef G_MAIN_POLL_DEBUG
g_print ("PeekMessage\n");
g_print ("WaitMessage\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
{
WaitMessage ();
KillTimer (NULL, timer);
#ifdef G_MAIN_POLL_DEBUG
g_print ("WaitMessage\n");
g_print ("PeekMessage\n");
#endif
WaitMessage ();
KillTimer (NULL, timer);
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)
&& msg.message != WM_TIMER)
ready = WAIT_OBJECT_0;
else
ready = WAIT_TIMEOUT;
if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)
&& msg.message != WM_TIMER)
ready = WAIT_OBJECT_0;
else
ready = WAIT_TIMEOUT;
}
}
}
}
else
{
/* Wait for either message or event
* -> Use MsgWaitForMultipleObjects
*/
else
{
/* Wait for either message or event
* -> Use MsgWaitForMultipleObjects
*/
#ifdef G_MAIN_POLL_DEBUG
g_print ("MsgWaitForMultipleObjects(%d, %d)\n", nhandles, timeout);
g_print ("MsgWaitForMultipleObjects(%d, %d)\n", nhandles, timeout);
#endif
ready = MsgWaitForMultipleObjects (nhandles, handles, FALSE,
timeout, QS_ALLINPUT);
ready = MsgWaitForMultipleObjects (nhandles, handles, FALSE,
timeout, QS_ALLINPUT);
if (ready == WAIT_FAILED)
g_warning ("g_poll: MsgWaitForMultipleObjects failed");