Commit 6d328a0d authored by Dan Winship's avatar Dan Winship

gio: port unix streams to GUnixFDSource

The unix input/output streams were using a gio-only source type that
was mostly identical to GUnixFDSource. Get rid of that source type
and just use GUnixFDSource instead.

https://bugzilla.gnome.org/show_bug.cgi?id=701511
parent 8a899265
......@@ -35,115 +35,6 @@
*
**/
/*************************************************************************
* fd source *
************************************************************************/
typedef struct
{
GSource source;
GPollFD pollfd;
} FDSource;
static gboolean
fd_source_prepare (GSource *source,
gint *timeout)
{
*timeout = -1;
return FALSE;
}
static gboolean
fd_source_check (GSource *source)
{
FDSource *fd_source = (FDSource *)source;
return fd_source->pollfd.revents != 0;
}
static gboolean
fd_source_dispatch (GSource *source,
GSourceFunc callback,
gpointer user_data)
{
GFDSourceFunc func = (GFDSourceFunc)callback;
FDSource *fd_source = (FDSource *)source;
g_warn_if_fail (func != NULL);
return (*func) (fd_source->pollfd.fd, fd_source->pollfd.revents, user_data);
}
static void
fd_source_finalize (GSource *source)
{
}
static gboolean
fd_source_closure_callback (int fd,
GIOCondition condition,
gpointer data)
{
GClosure *closure = data;
GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
GValue result_value = G_VALUE_INIT;
gboolean result;
g_value_init (&result_value, G_TYPE_BOOLEAN);
g_value_init (&params[0], G_TYPE_INT);
g_value_set_int (&params[0], fd);
g_value_init (&params[1], G_TYPE_IO_CONDITION);
g_value_set_flags (&params[1], condition);
g_closure_invoke (closure, &result_value, 2, params, NULL);
result = g_value_get_boolean (&result_value);
g_value_unset (&result_value);
g_value_unset (&params[0]);
g_value_unset (&params[1]);
return result;
}
static GSourceFuncs fd_source_funcs = {
fd_source_prepare,
fd_source_check,
fd_source_dispatch,
fd_source_finalize,
(GSourceFunc)fd_source_closure_callback,
};
GSource *
_g_fd_source_new (int fd,
gushort events,
GCancellable *cancellable)
{
GSource *source;
FDSource *fd_source;
source = g_source_new (&fd_source_funcs, sizeof (FDSource));
fd_source = (FDSource *)source;
fd_source->pollfd.fd = fd;
fd_source->pollfd.events = events;
g_source_add_poll (source, &fd_source->pollfd);
if (cancellable)
{
GSource *cancellable_source = g_cancellable_source_new (cancellable);
g_source_set_dummy_callback (cancellable_source);
g_source_add_child_source (source, cancellable_source);
g_source_unref (cancellable_source);
}
return source;
}
#ifdef G_OS_WIN32
gboolean
_g_win32_overlap_wait_result (HANDLE hfile,
......
......@@ -31,14 +31,6 @@
G_BEGIN_DECLS
typedef gboolean (*GFDSourceFunc) (int fd,
GIOCondition condition,
gpointer user_data);
GSource *_g_fd_source_new (int fd,
gushort events,
GCancellable *cancellable);
#ifdef G_OS_WIN32
gboolean _g_win32_overlap_wait_result (HANDLE hfile,
OVERLAPPED *overlap,
......
......@@ -31,6 +31,7 @@
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/glib-unix.h>
#include "gioerror.h"
#include "gsimpleasyncresult.h"
#include "gunixinputstream.h"
......@@ -510,14 +511,22 @@ g_unix_input_stream_pollable_create_source (GPollableInputStream *stream,
GCancellable *cancellable)
{
GUnixInputStream *unix_stream = G_UNIX_INPUT_STREAM (stream);
GSource *inner_source, *pollable_source;
GSource *inner_source, *cancellable_source, *pollable_source;
pollable_source = g_pollable_source_new (G_OBJECT (stream));
inner_source = _g_fd_source_new (unix_stream->priv->fd, G_IO_IN, cancellable);
inner_source = g_unix_fd_source_new (unix_stream->priv->fd, G_IO_IN);
g_source_set_dummy_callback (inner_source);
g_source_add_child_source (pollable_source, inner_source);
g_source_unref (inner_source);
if (cancellable)
{
cancellable_source = g_cancellable_source_new (cancellable);
g_source_set_dummy_callback (cancellable_source);
g_source_add_child_source (pollable_source, cancellable_source);
g_source_unref (cancellable_source);
}
return pollable_source;
}
......@@ -31,6 +31,7 @@
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/glib-unix.h>
#include "gioerror.h"
#include "gunixoutputstream.h"
#include "gcancellable.h"
......@@ -474,14 +475,22 @@ g_unix_output_stream_pollable_create_source (GPollableOutputStream *stream,
GCancellable *cancellable)
{
GUnixOutputStream *unix_stream = G_UNIX_OUTPUT_STREAM (stream);
GSource *inner_source, *pollable_source;
GSource *inner_source, *cancellable_source, *pollable_source;
pollable_source = g_pollable_source_new (G_OBJECT (stream));
inner_source = _g_fd_source_new (unix_stream->priv->fd, G_IO_OUT, cancellable);
inner_source = g_unix_fd_source_new (unix_stream->priv->fd, G_IO_OUT);
g_source_set_dummy_callback (inner_source);
g_source_add_child_source (pollable_source, inner_source);
g_source_unref (inner_source);
if (cancellable)
{
cancellable_source = g_cancellable_source_new (cancellable);
g_source_set_dummy_callback (cancellable_source);
g_source_add_child_source (pollable_source, cancellable_source);
g_source_unref (cancellable_source);
}
return pollable_source;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment