Bug 505361 - gunixinputstream.c assumes poll() available

Bug 509446 - portable blocking gio cancellation

	* gcancellable.c (g_cancellable_make_pollfd): New method to make a
	GPollFD for a cancellable (which is slightly more complicated on
	Windows than Unix).

	* gunixinputstream.c (g_unix_input_stream_read):
	* gunixoutputstream.c (g_unix_output_stream_write): Use
	g_cancellable_make_pollfd() and g_poll() rather than using poll()
	directly.

	* tests/unix-streams.c: test of GUnixInputStream,
	GUnixOutputStream, and GCancellable.

svn path=/trunk/; revision=7553
This commit is contained in:
Dan Winship
2008-09-26 16:19:35 +00:00
parent ea0970e9ca
commit 7f4864e58d
10 changed files with 356 additions and 29 deletions

View File

@@ -28,7 +28,6 @@
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <poll.h>
#include <glib.h>
#include <glib/gstdio.h>
@@ -161,23 +160,18 @@ g_unix_output_stream_write (GOutputStream *stream,
{
GUnixOutputStream *unix_stream;
gssize res;
struct pollfd poll_fds[2];
GPollFD poll_fds[2];
int poll_ret;
int cancel_fd;
unix_stream = G_UNIX_OUTPUT_STREAM (stream);
cancel_fd = g_cancellable_get_fd (cancellable);
if (cancel_fd != -1)
if (cancellable)
{
poll_fds[0].fd = unix_stream->priv->fd;
poll_fds[0].events = G_IO_OUT;
g_cancellable_make_pollfd (cancellable, &poll_fds[1]);
do
{
poll_fds[0].events = POLLOUT;
poll_fds[0].fd = unix_stream->priv->fd;
poll_fds[1].events = POLLIN;
poll_fds[1].fd = cancel_fd;
poll_ret = poll (poll_fds, 2, -1);
}
poll_ret = g_poll (poll_fds, 2, -1);
while (poll_ret == -1 && errno == EINTR);
if (poll_ret == -1)
@@ -335,7 +329,7 @@ g_unix_output_stream_write_async (GOutputStream *stream,
data->stream = unix_stream;
source = _g_fd_source_new (unix_stream->priv->fd,
POLLOUT,
G_IO_OUT,
cancellable);
g_source_set_callback (source, (GSourceFunc)write_async_cb, data, g_free);