From 759c0e935d0d189aebbb7ff8186c397e88477c7f Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Sat, 3 Sep 2011 09:03:17 -0400 Subject: [PATCH] gio: more implementations of GFileDescriptorBased Implement GFileDescriptorBased in GSocket{Input,Output}Stream and GUnix{Input,Output}Stream. https://bugzilla.gnome.org/show_bug.cgi?id=616852 --- gio/gsocketinputstream.c | 27 ++++++++++++++++++++++++++- gio/gsocketoutputstream.c | 29 +++++++++++++++++++++++++++-- gio/gunixinputstream.c | 12 +++++++++++- gio/gunixoutputstream.c | 12 +++++++++++- 4 files changed, 75 insertions(+), 5 deletions(-) diff --git a/gio/gsocketinputstream.c b/gio/gsocketinputstream.c index fb9da1bf1..e8d89fed4 100644 --- a/gio/gsocketinputstream.c +++ b/gio/gsocketinputstream.c @@ -31,13 +31,20 @@ #include "gcancellable.h" #include "gpollableinputstream.h" #include "gioerror.h" - +#include "gfiledescriptorbased.h" static void g_socket_input_stream_pollable_iface_init (GPollableInputStreamInterface *iface); +#ifdef G_OS_UNIX +static void g_socket_input_stream_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface); +#endif #define g_socket_input_stream_get_type _g_socket_input_stream_get_type G_DEFINE_TYPE_WITH_CODE (GSocketInputStream, g_socket_input_stream, G_TYPE_INPUT_STREAM, G_IMPLEMENT_INTERFACE (G_TYPE_POLLABLE_INPUT_STREAM, g_socket_input_stream_pollable_iface_init) +#ifdef G_OS_UNIX + + G_IMPLEMENT_INTERFACE (G_TYPE_FILE_DESCRIPTOR_BASED, g_socket_input_stream_file_descriptor_based_iface_init) +#endif ) enum @@ -248,6 +255,16 @@ g_socket_input_stream_pollable_read_nonblocking (GPollableInputStream *pollable NULL, error); } +#ifdef G_OS_UNIX +static int +g_socket_input_stream_get_fd (GFileDescriptorBased *fd_based) +{ + GSocketInputStream *input_stream = G_SOCKET_INPUT_STREAM (fd_based); + + return g_socket_get_fd (input_stream->priv->socket); +} +#endif + static void g_socket_input_stream_class_init (GSocketInputStreamClass *klass) { @@ -272,6 +289,14 @@ g_socket_input_stream_class_init (GSocketInputStreamClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } +#ifdef G_OS_UNIX +static void +g_socket_input_stream_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface) +{ + iface->get_fd = g_socket_input_stream_get_fd; +} +#endif + static void g_socket_input_stream_pollable_iface_init (GPollableInputStreamInterface *iface) { diff --git a/gio/gsocketoutputstream.c b/gio/gsocketoutputstream.c index 0ef336016..1335c4dcb 100644 --- a/gio/gsocketoutputstream.c +++ b/gio/gsocketoutputstream.c @@ -27,6 +27,7 @@ #include "goutputstream.h" #include "gsocketoutputstream.h" #include "gsocket.h" +#include "glibintl.h" #include "gsimpleasyncresult.h" #include "gcancellable.h" @@ -34,14 +35,20 @@ #include "gpollableoutputstream.h" #include "gioerror.h" #include "glibintl.h" - +#include "gfiledescriptorbased.h" static void g_socket_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface); +#ifdef G_OS_UNIX +static void g_socket_output_stream_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface); +#endif #define g_socket_output_stream_get_type _g_socket_output_stream_get_type G_DEFINE_TYPE_WITH_CODE (GSocketOutputStream, g_socket_output_stream, G_TYPE_OUTPUT_STREAM, G_IMPLEMENT_INTERFACE (G_TYPE_POLLABLE_OUTPUT_STREAM, g_socket_output_stream_pollable_iface_init) - ) +#ifdef G_OS_UNIX + G_IMPLEMENT_INTERFACE (G_TYPE_FILE_DESCRIPTOR_BASED, g_socket_output_stream_file_descriptor_based_iface_init) +#endif +); enum { @@ -251,6 +258,16 @@ g_socket_output_stream_pollable_write_nonblocking (GPollableOutputStream *polla NULL, error); } +#ifdef G_OS_UNIX +static int +g_socket_output_stream_get_fd (GFileDescriptorBased *fd_based) +{ + GSocketOutputStream *output_stream = G_SOCKET_OUTPUT_STREAM (fd_based); + + return g_socket_get_fd (output_stream->priv->socket); +} +#endif + static void g_socket_output_stream_class_init (GSocketOutputStreamClass *klass) { @@ -275,6 +292,14 @@ g_socket_output_stream_class_init (GSocketOutputStreamClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } +#ifdef G_OS_UNIX +static void +g_socket_output_stream_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface) +{ + iface->get_fd = g_socket_output_stream_get_fd; +} +#endif + static void g_socket_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface) { diff --git a/gio/gunixinputstream.c b/gio/gunixinputstream.c index 43a924729..708a90170 100644 --- a/gio/gunixinputstream.c +++ b/gio/gunixinputstream.c @@ -36,6 +36,7 @@ #include "gunixinputstream.h" #include "gcancellable.h" #include "gasynchelper.h" +#include "gfiledescriptorbased.h" #include "glibintl.h" @@ -61,11 +62,14 @@ enum { }; static void g_unix_input_stream_pollable_iface_init (GPollableInputStreamInterface *iface); +static void g_unix_input_stream_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface); G_DEFINE_TYPE_WITH_CODE (GUnixInputStream, g_unix_input_stream, G_TYPE_INPUT_STREAM, G_IMPLEMENT_INTERFACE (G_TYPE_POLLABLE_INPUT_STREAM, g_unix_input_stream_pollable_iface_init) - ); + G_IMPLEMENT_INTERFACE (G_TYPE_FILE_DESCRIPTOR_BASED, + g_unix_input_stream_file_descriptor_based_iface_init) + ) struct _GUnixInputStreamPrivate { int fd; @@ -189,6 +193,12 @@ g_unix_input_stream_pollable_iface_init (GPollableInputStreamInterface *iface) iface->create_source = g_unix_input_stream_pollable_create_source; } +static void +g_unix_input_stream_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface) +{ + iface->get_fd = (int (*) (GFileDescriptorBased *))g_unix_input_stream_get_fd; +} + static void g_unix_input_stream_set_property (GObject *object, guint prop_id, diff --git a/gio/gunixoutputstream.c b/gio/gunixoutputstream.c index 81021be8e..e99a13f90 100644 --- a/gio/gunixoutputstream.c +++ b/gio/gunixoutputstream.c @@ -36,6 +36,7 @@ #include "gcancellable.h" #include "gsimpleasyncresult.h" #include "gasynchelper.h" +#include "gfiledescriptorbased.h" #include "glibintl.h" @@ -61,11 +62,14 @@ enum { }; static void g_unix_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface); +static void g_unix_output_stream_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface); G_DEFINE_TYPE_WITH_CODE (GUnixOutputStream, g_unix_output_stream, G_TYPE_OUTPUT_STREAM, G_IMPLEMENT_INTERFACE (G_TYPE_POLLABLE_OUTPUT_STREAM, g_unix_output_stream_pollable_iface_init) - ); + G_IMPLEMENT_INTERFACE (G_TYPE_FILE_DESCRIPTOR_BASED, + g_unix_output_stream_file_descriptor_based_iface_init) + ) struct _GUnixOutputStreamPrivate { int fd; @@ -174,6 +178,12 @@ g_unix_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface) iface->create_source = g_unix_output_stream_pollable_create_source; } +static void +g_unix_output_stream_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface) +{ + iface->get_fd = (int (*) (GFileDescriptorBased *))g_unix_output_stream_get_fd; +} + static void g_unix_output_stream_set_property (GObject *object, guint prop_id,