diff --git a/gio/ChangeLog b/gio/ChangeLog index 0bd45400b..8a98837bd 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,3 +1,14 @@ +2007-11-27 Alexander Larsson + + * Makefile.am: + * gsocketinputstream.[ch]: Removed. + * gsocketoutputstream.[ch]: Removed. + * gunixinputstream.[ch]: Added. + * gunixoutputstream.[ch]: Added. + Renamed GSocket*Stream to GUnix*Stream and made + it unix-only, since its not really only for sockets + and it only works on unix (but is highly useful there). + 2007-11-27 Andrew Walton * gappinfo.c: * gappinfo.h: diff --git a/gio/Makefile.am b/gio/Makefile.am index b33750a25..f965501ff 100644 --- a/gio/Makefile.am +++ b/gio/Makefile.am @@ -73,19 +73,23 @@ if OS_UNIX appinfo_sources += gdesktopappinfo.c gdesktopappinfo.h platform_libadd += xdgmime/libxdgmime.la unix_sources = \ - gunixdrive.c \ - gunixdrive.h \ - gunixmounts.c \ - gunixmounts.h \ - gunixvolume.c \ - gunixvolume.h \ - gunixvolumemonitor.c \ - gunixvolumemonitor.h \ + gunixdrive.c \ + gunixdrive.h \ + gunixmounts.c \ + gunixmounts.h \ + gunixvolume.c \ + gunixvolume.h \ + gunixvolumemonitor.c \ + gunixvolumemonitor.h \ + gunixinputstream.c \ + gunixoutputstream.c \ $(NULL) giounixincludedir=$(includedir)/gio-unix-2.0/gio giounixinclude_HEADERS = \ gunixmounts.h \ + gunixinputstream.h \ + gunixoutputstream.h \ $(NULL) endif @@ -138,8 +142,6 @@ libgio_2_0_la_SOURCES = \ gpollfilemonitor.h \ gseekable.c \ gsimpleasyncresult.c \ - gsocketinputstream.c \ - gsocketoutputstream.c \ gthemedicon.c \ gunionvolumemonitor.c \ gunionvolumemonitor.h \ @@ -207,8 +209,6 @@ gioinclude_HEADERS = \ goutputstream.h \ gseekable.h \ gsimpleasyncresult.h \ - gsocketinputstream.h \ - gsocketoutputstream.h \ gthemedicon.h \ gvfs.h \ gvolume.h \ diff --git a/gio/gsocketinputstream.h b/gio/gsocketinputstream.h deleted file mode 100644 index ec98cdb85..000000000 --- a/gio/gsocketinputstream.h +++ /dev/null @@ -1,74 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * 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. - * - * Author: Alexander Larsson - */ - -#ifndef __G_SOCKET_INPUT_STREAM_H__ -#define __G_SOCKET_INPUT_STREAM_H__ - -#include - -G_BEGIN_DECLS - -#define G_TYPE_SOCKET_INPUT_STREAM (g_socket_input_stream_get_type ()) -#define G_SOCKET_INPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_SOCKET_INPUT_STREAM, GSocketInputStream)) -#define G_SOCKET_INPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_SOCKET_INPUT_STREAM, GSocketInputStreamClass)) -#define G_IS_SOCKET_INPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_SOCKET_INPUT_STREAM)) -#define G_IS_SOCKET_INPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_SOCKET_INPUT_STREAM)) -#define G_SOCKET_INPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_SOCKET_INPUT_STREAM, GSocketInputStreamClass)) - -/** - * GSocketInputStream: - * - * Implements #GInputStream for reading from sockets. - **/ -typedef struct _GSocketInputStream GSocketInputStream; -typedef struct _GSocketInputStreamClass GSocketInputStreamClass; -typedef struct _GSocketInputStreamPrivate GSocketInputStreamPrivate; - -struct _GSocketInputStream -{ - GInputStream parent; - - /*< private >*/ - GSocketInputStreamPrivate *priv; -}; - -struct _GSocketInputStreamClass -{ - GInputStreamClass parent_class; - - /*< private >*/ - /* Padding for future expansion */ - void (*_g_reserved1) (void); - void (*_g_reserved2) (void); - void (*_g_reserved3) (void); - void (*_g_reserved4) (void); - void (*_g_reserved5) (void); -}; - -GType g_socket_input_stream_get_type (void) G_GNUC_CONST; - -GInputStream *g_socket_input_stream_new (int fd, - gboolean close_fd_at_close); - -G_END_DECLS - -#endif /* __G_SOCKET_INPUT_STREAM_H__ */ diff --git a/gio/gsocketoutputstream.h b/gio/gsocketoutputstream.h deleted file mode 100644 index 09527def3..000000000 --- a/gio/gsocketoutputstream.h +++ /dev/null @@ -1,74 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * 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. - * - * Author: Alexander Larsson - */ - -#ifndef __G_SOCKET_OUTPUT_STREAM_H__ -#define __G_SOCKET_OUTPUT_STREAM_H__ - -#include - -G_BEGIN_DECLS - -#define G_TYPE_SOCKET_OUTPUT_STREAM (g_socket_output_stream_get_type ()) -#define G_SOCKET_OUTPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_SOCKET_OUTPUT_STREAM, GSocketOutputStream)) -#define G_SOCKET_OUTPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_SOCKET_OUTPUT_STREAM, GSocketOutputStreamClass)) -#define G_IS_SOCKET_OUTPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_SOCKET_OUTPUT_STREAM)) -#define G_IS_SOCKET_OUTPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_SOCKET_OUTPUT_STREAM)) -#define G_SOCKET_OUTPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_SOCKET_OUTPUT_STREAM, GSocketOutputStreamClass)) - -/** - * GSocketOutputStream: - * - * Implements #GOutputStream for outputting to sockets. - **/ -typedef struct _GSocketOutputStream GSocketOutputStream; -typedef struct _GSocketOutputStreamClass GSocketOutputStreamClass; -typedef struct _GSocketOutputStreamPrivate GSocketOutputStreamPrivate; - -struct _GSocketOutputStream -{ - GOutputStream parent; - - /*< private >*/ - GSocketOutputStreamPrivate *priv; -}; - -struct _GSocketOutputStreamClass -{ - GOutputStreamClass parent_class; - - /*< private >*/ - /* Padding for future expansion */ - void (*_g_reserved1) (void); - void (*_g_reserved2) (void); - void (*_g_reserved3) (void); - void (*_g_reserved4) (void); - void (*_g_reserved5) (void); -}; - -GType g_socket_output_stream_get_type (void) G_GNUC_CONST; - -GOutputStream *g_socket_output_stream_new (int fd, - gboolean close_fd_at_close); - -G_END_DECLS - -#endif /* __G_SOCKET_OUTPUT_STREAM_H__ */ diff --git a/gio/gsocketinputstream.c b/gio/gunixinputstream.c similarity index 50% rename from gio/gsocketinputstream.c rename to gio/gunixinputstream.c index 1b7b2b8a1..286d22813 100644 --- a/gio/gsocketinputstream.c +++ b/gio/gunixinputstream.c @@ -34,125 +34,127 @@ #include #include "gioerror.h" #include "gsimpleasyncresult.h" -#include "gsocketinputstream.h" +#include "gunixinputstream.h" #include "gcancellable.h" #include "gasynchelper.h" #include "glibintl.h" /** - * SECTION:gsocketinputstream - * @short_description: Socket Input Stream + * SECTION:gunixinputstream + * @short_description: Unix Input Stream * @see_also: #GInputStream. * - * #GSocketInputStream implements #GInputStream for reading from a socket, - * including asynchronous operations. + * #GUnixInputStream implements #GInputStream for reading from a + * unix file descriptor, including asynchronous operations. The file + * descriptor much be selectable, so it doesn't work with opened files. **/ -G_DEFINE_TYPE (GSocketInputStream, g_socket_input_stream, G_TYPE_INPUT_STREAM); +G_DEFINE_TYPE (GUnixInputStream, g_unix_input_stream, G_TYPE_INPUT_STREAM); -struct _GSocketInputStreamPrivate { +struct _GUnixInputStreamPrivate { int fd; gboolean close_fd_at_close; }; -static gssize g_socket_input_stream_read (GInputStream *stream, - void *buffer, - gsize count, - GCancellable *cancellable, - GError **error); -static gboolean g_socket_input_stream_close (GInputStream *stream, - GCancellable *cancellable, - GError **error); -static void g_socket_input_stream_read_async (GInputStream *stream, - void *buffer, - gsize count, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer data); -static gssize g_socket_input_stream_read_finish (GInputStream *stream, - GAsyncResult *result, - GError **error); -static void g_socket_input_stream_skip_async (GInputStream *stream, - gsize count, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer data); -static gssize g_socket_input_stream_skip_finish (GInputStream *stream, - GAsyncResult *result, - GError **error); -static void g_socket_input_stream_close_async (GInputStream *stream, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer data); -static gboolean g_socket_input_stream_close_finish (GInputStream *stream, - GAsyncResult *result, - GError **error); +static gssize g_unix_input_stream_read (GInputStream *stream, + void *buffer, + gsize count, + GCancellable *cancellable, + GError **error); +static gboolean g_unix_input_stream_close (GInputStream *stream, + GCancellable *cancellable, + GError **error); +static void g_unix_input_stream_read_async (GInputStream *stream, + void *buffer, + gsize count, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer data); +static gssize g_unix_input_stream_read_finish (GInputStream *stream, + GAsyncResult *result, + GError **error); +static void g_unix_input_stream_skip_async (GInputStream *stream, + gsize count, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer data); +static gssize g_unix_input_stream_skip_finish (GInputStream *stream, + GAsyncResult *result, + GError **error); +static void g_unix_input_stream_close_async (GInputStream *stream, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer data); +static gboolean g_unix_input_stream_close_finish (GInputStream *stream, + GAsyncResult *result, + GError **error); + static void -g_socket_input_stream_finalize (GObject *object) +g_unix_input_stream_finalize (GObject *object) { - GSocketInputStream *stream; + GUnixInputStream *stream; - stream = G_SOCKET_INPUT_STREAM (object); + stream = G_UNIX_INPUT_STREAM (object); - if (G_OBJECT_CLASS (g_socket_input_stream_parent_class)->finalize) - (*G_OBJECT_CLASS (g_socket_input_stream_parent_class)->finalize) (object); + if (G_OBJECT_CLASS (g_unix_input_stream_parent_class)->finalize) + (*G_OBJECT_CLASS (g_unix_input_stream_parent_class)->finalize) (object); } static void -g_socket_input_stream_class_init (GSocketInputStreamClass *klass) +g_unix_input_stream_class_init (GUnixInputStreamClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GInputStreamClass *stream_class = G_INPUT_STREAM_CLASS (klass); - g_type_class_add_private (klass, sizeof (GSocketInputStreamPrivate)); + g_type_class_add_private (klass, sizeof (GUnixInputStreamPrivate)); - gobject_class->finalize = g_socket_input_stream_finalize; + gobject_class->finalize = g_unix_input_stream_finalize; - stream_class->read = g_socket_input_stream_read; - stream_class->close = g_socket_input_stream_close; - stream_class->read_async = g_socket_input_stream_read_async; - stream_class->read_finish = g_socket_input_stream_read_finish; + stream_class->read = g_unix_input_stream_read; + stream_class->close = g_unix_input_stream_close; + stream_class->read_async = g_unix_input_stream_read_async; + stream_class->read_finish = g_unix_input_stream_read_finish; if (0) { /* TODO: Implement instead of using fallbacks */ - stream_class->skip_async = g_socket_input_stream_skip_async; - stream_class->skip_finish = g_socket_input_stream_skip_finish; + stream_class->skip_async = g_unix_input_stream_skip_async; + stream_class->skip_finish = g_unix_input_stream_skip_finish; } - stream_class->close_async = g_socket_input_stream_close_async; - stream_class->close_finish = g_socket_input_stream_close_finish; + stream_class->close_async = g_unix_input_stream_close_async; + stream_class->close_finish = g_unix_input_stream_close_finish; } static void -g_socket_input_stream_init (GSocketInputStream *socket) +g_unix_input_stream_init (GUnixInputStream *unix_stream) { - socket->priv = G_TYPE_INSTANCE_GET_PRIVATE (socket, - G_TYPE_SOCKET_INPUT_STREAM, - GSocketInputStreamPrivate); + unix_stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (unix_stream, + G_TYPE_UNIX_INPUT_STREAM, + GUnixInputStreamPrivate); } /** - * g_socket_input_stream_new: - * @fd: socket file descriptor. + * g_unix_input_stream_new: + * @fd: unix file descriptor. * @close_fd_at_close: a #gboolean. * - * Creates a new #GSocketInputStream for the given @fd. If @close_fd_at_close - * is %TRUE, the socket will be closed when the stream is closed. + * Creates a new #GUnixInputStream for the given @fd. If @close_fd_at_close + * is %TRUE, the file descriptor will be closed when the stream is closed. * - * Returns: a #GSocketInputStream. + * Returns: a #GUnixInputStream. **/ GInputStream * -g_socket_input_stream_new (int fd, - gboolean close_fd_at_close) +g_unix_input_stream_new (int fd, + gboolean close_fd_at_close) { - GSocketInputStream *stream; + GUnixInputStream *stream; g_return_val_if_fail (fd != -1, NULL); - stream = g_object_new (G_TYPE_SOCKET_INPUT_STREAM, NULL); + stream = g_object_new (G_TYPE_UNIX_INPUT_STREAM, NULL); stream->priv->fd = fd; stream->priv->close_fd_at_close = close_fd_at_close; @@ -161,19 +163,19 @@ g_socket_input_stream_new (int fd, } static gssize -g_socket_input_stream_read (GInputStream *stream, - void *buffer, - gsize count, - GCancellable *cancellable, - GError **error) +g_unix_input_stream_read (GInputStream *stream, + void *buffer, + gsize count, + GCancellable *cancellable, + GError **error) { - GSocketInputStream *socket_stream; + GUnixInputStream *unix_stream; gssize res; struct pollfd poll_fds[2]; int poll_ret; int cancel_fd; - socket_stream = G_SOCKET_INPUT_STREAM (stream); + unix_stream = G_UNIX_INPUT_STREAM (stream); cancel_fd = g_cancellable_get_fd (cancellable); if (cancel_fd != -1) @@ -181,7 +183,7 @@ g_socket_input_stream_read (GInputStream *stream, do { poll_fds[0].events = POLLIN; - poll_fds[0].fd = socket_stream->priv->fd; + 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); @@ -192,7 +194,7 @@ g_socket_input_stream_read (GInputStream *stream, { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - _("Error reading from socket: %s"), + _("Error reading from unix: %s"), g_strerror (errno)); return -1; } @@ -202,7 +204,7 @@ g_socket_input_stream_read (GInputStream *stream, { if (g_cancellable_set_error_if_cancelled (cancellable, error)) break; - res = read (socket_stream->priv->fd, buffer, count); + res = read (unix_stream->priv->fd, buffer, count); if (res == -1) { if (errno == EINTR) @@ -210,7 +212,7 @@ g_socket_input_stream_read (GInputStream *stream, g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - _("Error reading from socket: %s"), + _("Error reading from unix: %s"), g_strerror (errno)); } @@ -221,27 +223,27 @@ g_socket_input_stream_read (GInputStream *stream, } static gboolean -g_socket_input_stream_close (GInputStream *stream, - GCancellable *cancellable, - GError **error) +g_unix_input_stream_close (GInputStream *stream, + GCancellable *cancellable, + GError **error) { - GSocketInputStream *socket_stream; + GUnixInputStream *unix_stream; int res; - socket_stream = G_SOCKET_INPUT_STREAM (stream); + unix_stream = G_UNIX_INPUT_STREAM (stream); - if (!socket_stream->priv->close_fd_at_close) + if (!unix_stream->priv->close_fd_at_close) return TRUE; while (1) { /* This might block during the close. Doesn't seem to be a way to avoid it though. */ - res = close (socket_stream->priv->fd); + res = close (unix_stream->priv->fd); if (res == -1) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - _("Error closing socket: %s"), + _("Error closing unix: %s"), g_strerror (errno)); } break; @@ -256,7 +258,7 @@ typedef struct { GAsyncReadyCallback callback; gpointer user_data; GCancellable *cancellable; - GSocketInputStream *stream; + GUnixInputStream *stream; } ReadAsyncData; static gboolean @@ -284,7 +286,7 @@ read_async_cb (ReadAsyncData *data, g_set_error (&error, G_IO_ERROR, g_io_error_from_errno (errno), - _("Error reading from socket: %s"), + _("Error reading from unix: %s"), g_strerror (errno)); } break; @@ -293,7 +295,7 @@ read_async_cb (ReadAsyncData *data, simple = g_simple_async_result_new (G_OBJECT (data->stream), data->callback, data->user_data, - g_socket_input_stream_read_async); + g_unix_input_stream_read_async); g_simple_async_result_set_op_res_gssize (simple, count_read); @@ -311,19 +313,19 @@ read_async_cb (ReadAsyncData *data, } static void -g_socket_input_stream_read_async (GInputStream *stream, - void *buffer, - gsize count, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +g_unix_input_stream_read_async (GInputStream *stream, + void *buffer, + gsize count, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { GSource *source; - GSocketInputStream *socket_stream; + GUnixInputStream *unix_stream; ReadAsyncData *data; - socket_stream = G_SOCKET_INPUT_STREAM (stream); + unix_stream = G_UNIX_INPUT_STREAM (stream); data = g_new0 (ReadAsyncData, 1); data->count = count; @@ -331,9 +333,9 @@ g_socket_input_stream_read_async (GInputStream *stream, data->callback = callback; data->user_data = user_data; data->cancellable = cancellable; - data->stream = socket_stream; + data->stream = unix_stream; - source = _g_fd_source_new (socket_stream->priv->fd, + source = _g_fd_source_new (unix_stream->priv->fd, POLLIN, cancellable); @@ -344,36 +346,36 @@ g_socket_input_stream_read_async (GInputStream *stream, } static gssize -g_socket_input_stream_read_finish (GInputStream *stream, - GAsyncResult *result, - GError **error) +g_unix_input_stream_read_finish (GInputStream *stream, + GAsyncResult *result, + GError **error) { GSimpleAsyncResult *simple; gssize nread; simple = G_SIMPLE_ASYNC_RESULT (result); - g_assert (g_simple_async_result_get_source_tag (simple) == g_socket_input_stream_read_async); + g_assert (g_simple_async_result_get_source_tag (simple) == g_unix_input_stream_read_async); nread = g_simple_async_result_get_op_res_gssize (simple); return nread; } static void -g_socket_input_stream_skip_async (GInputStream *stream, - gsize count, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer data) +g_unix_input_stream_skip_async (GInputStream *stream, + gsize count, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer data) { g_assert_not_reached (); /* TODO: Not implemented */ } static gssize -g_socket_input_stream_skip_finish (GInputStream *stream, - GAsyncResult *result, - GError **error) +g_unix_input_stream_skip_finish (GInputStream *stream, + GAsyncResult *result, + GError **error) { g_assert_not_reached (); /* TODO: Not implemented */ @@ -397,15 +399,15 @@ close_async_data_free (gpointer _data) static gboolean close_async_cb (CloseAsyncData *data) { - GSocketInputStream *socket_stream; + GUnixInputStream *unix_stream; GSimpleAsyncResult *simple; GError *error = NULL; gboolean result; int res; - socket_stream = G_SOCKET_INPUT_STREAM (data->stream); + unix_stream = G_UNIX_INPUT_STREAM (data->stream); - if (!socket_stream->priv->close_fd_at_close) + if (!unix_stream->priv->close_fd_at_close) { result = TRUE; goto out; @@ -413,12 +415,12 @@ close_async_cb (CloseAsyncData *data) while (1) { - res = close (socket_stream->priv->fd); + res = close (unix_stream->priv->fd); if (res == -1) { g_set_error (&error, G_IO_ERROR, g_io_error_from_errno (errno), - _("Error closing socket: %s"), + _("Error closing unix: %s"), g_strerror (errno)); } break; @@ -430,7 +432,7 @@ close_async_cb (CloseAsyncData *data) simple = g_simple_async_result_new (G_OBJECT (data->stream), data->callback, data->user_data, - g_socket_input_stream_close_async); + g_unix_input_stream_close_async); if (!result) { @@ -446,11 +448,11 @@ close_async_cb (CloseAsyncData *data) } static void -g_socket_input_stream_close_async (GInputStream *stream, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +g_unix_input_stream_close_async (GInputStream *stream, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { GSource *idle; CloseAsyncData *data; @@ -468,9 +470,9 @@ g_socket_input_stream_close_async (GInputStream *stream, } static gboolean -g_socket_input_stream_close_finish (GInputStream *stream, - GAsyncResult *result, - GError **error) +g_unix_input_stream_close_finish (GInputStream *stream, + GAsyncResult *result, + GError **error) { /* Failures handled in generic close_finish code */ return TRUE; diff --git a/gio/gunixinputstream.h b/gio/gunixinputstream.h new file mode 100644 index 000000000..0a632271e --- /dev/null +++ b/gio/gunixinputstream.h @@ -0,0 +1,74 @@ +/* GIO - GLib Input, Output and Streaming Library + * + * Copyright (C) 2006-2007 Red Hat, Inc. + * + * 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. + * + * Author: Alexander Larsson + */ + +#ifndef __G_UNIX_INPUT_STREAM_H__ +#define __G_UNIX_INPUT_STREAM_H__ + +#include + +G_BEGIN_DECLS + +#define G_TYPE_UNIX_INPUT_STREAM (g_unix_input_stream_get_type ()) +#define G_UNIX_INPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_UNIX_INPUT_STREAM, GUnixInputStream)) +#define G_UNIX_INPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_UNIX_INPUT_STREAM, GUnixInputStreamClass)) +#define G_IS_UNIX_INPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_UNIX_INPUT_STREAM)) +#define G_IS_UNIX_INPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_UNIX_INPUT_STREAM)) +#define G_UNIX_INPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_UNIX_INPUT_STREAM, GUnixInputStreamClass)) + +/** + * GUnixInputStream: + * + * Implements #GInputStream for reading from selectable unix file descriptors + **/ +typedef struct _GUnixInputStream GUnixInputStream; +typedef struct _GUnixInputStreamClass GUnixInputStreamClass; +typedef struct _GUnixInputStreamPrivate GUnixInputStreamPrivate; + +struct _GUnixInputStream +{ + GInputStream parent; + + /*< private >*/ + GUnixInputStreamPrivate *priv; +}; + +struct _GUnixInputStreamClass +{ + GInputStreamClass parent_class; + + /*< private >*/ + /* Padding for future expansion */ + void (*_g_reserved1) (void); + void (*_g_reserved2) (void); + void (*_g_reserved3) (void); + void (*_g_reserved4) (void); + void (*_g_reserved5) (void); +}; + +GType g_unix_input_stream_get_type (void) G_GNUC_CONST; + +GInputStream *g_unix_input_stream_new (int fd, + gboolean close_fd_at_close); + +G_END_DECLS + +#endif /* __G_UNIX_INPUT_STREAM_H__ */ diff --git a/gio/gsocketoutputstream.c b/gio/gunixoutputstream.c similarity index 53% rename from gio/gsocketoutputstream.c rename to gio/gunixoutputstream.c index b42162feb..ee02f278f 100644 --- a/gio/gsocketoutputstream.c +++ b/gio/gunixoutputstream.c @@ -33,115 +33,116 @@ #include #include #include "gioerror.h" -#include "gsocketoutputstream.h" +#include "gunixoutputstream.h" #include "gcancellable.h" #include "gsimpleasyncresult.h" #include "gasynchelper.h" #include "glibintl.h" /** - * SECTION:gsocketoutputstream - * @short_description: Socket Output Stream + * SECTION:gunixoutputstream + * @short_description: Unix Output Stream * @see_also: #GOutputStream. * - * #GSocketOutputStream implements #GOutputStream for writing to a socket, including - * asynchronous operations. + * #GUnixOutputStream implements #GOutputStream for writing to a a + * unix file descriptor, including asynchronous operations. The file + * descriptor much be selectable, so it doesn't work with opened files. **/ -G_DEFINE_TYPE (GSocketOutputStream, g_socket_output_stream, G_TYPE_OUTPUT_STREAM); +G_DEFINE_TYPE (GUnixOutputStream, g_unix_output_stream, G_TYPE_OUTPUT_STREAM); -struct _GSocketOutputStreamPrivate { +struct _GUnixOutputStreamPrivate { int fd; gboolean close_fd_at_close; }; -static gssize g_socket_output_stream_write (GOutputStream *stream, - const void *buffer, - gsize count, - GCancellable *cancellable, - GError **error); -static gboolean g_socket_output_stream_close (GOutputStream *stream, - GCancellable *cancellable, - GError **error); -static void g_socket_output_stream_write_async (GOutputStream *stream, - const void *buffer, - gsize count, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer data); -static gssize g_socket_output_stream_write_finish (GOutputStream *stream, - GAsyncResult *result, - GError **error); -static void g_socket_output_stream_close_async (GOutputStream *stream, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer data); -static gboolean g_socket_output_stream_close_finish (GOutputStream *stream, - GAsyncResult *result, - GError **error); +static gssize g_unix_output_stream_write (GOutputStream *stream, + const void *buffer, + gsize count, + GCancellable *cancellable, + GError **error); +static gboolean g_unix_output_stream_close (GOutputStream *stream, + GCancellable *cancellable, + GError **error); +static void g_unix_output_stream_write_async (GOutputStream *stream, + const void *buffer, + gsize count, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer data); +static gssize g_unix_output_stream_write_finish (GOutputStream *stream, + GAsyncResult *result, + GError **error); +static void g_unix_output_stream_close_async (GOutputStream *stream, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer data); +static gboolean g_unix_output_stream_close_finish (GOutputStream *stream, + GAsyncResult *result, + GError **error); static void -g_socket_output_stream_finalize (GObject *object) +g_unix_output_stream_finalize (GObject *object) { - GSocketOutputStream *stream; + GUnixOutputStream *stream; - stream = G_SOCKET_OUTPUT_STREAM (object); + stream = G_UNIX_OUTPUT_STREAM (object); - if (G_OBJECT_CLASS (g_socket_output_stream_parent_class)->finalize) - (*G_OBJECT_CLASS (g_socket_output_stream_parent_class)->finalize) (object); + if (G_OBJECT_CLASS (g_unix_output_stream_parent_class)->finalize) + (*G_OBJECT_CLASS (g_unix_output_stream_parent_class)->finalize) (object); } static void -g_socket_output_stream_class_init (GSocketOutputStreamClass *klass) +g_unix_output_stream_class_init (GUnixOutputStreamClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GOutputStreamClass *stream_class = G_OUTPUT_STREAM_CLASS (klass); - g_type_class_add_private (klass, sizeof (GSocketOutputStreamPrivate)); + g_type_class_add_private (klass, sizeof (GUnixOutputStreamPrivate)); - gobject_class->finalize = g_socket_output_stream_finalize; + gobject_class->finalize = g_unix_output_stream_finalize; - stream_class->write = g_socket_output_stream_write; - stream_class->close = g_socket_output_stream_close; - stream_class->write_async = g_socket_output_stream_write_async; - stream_class->write_finish = g_socket_output_stream_write_finish; - stream_class->close_async = g_socket_output_stream_close_async; - stream_class->close_finish = g_socket_output_stream_close_finish; + stream_class->write = g_unix_output_stream_write; + stream_class->close = g_unix_output_stream_close; + stream_class->write_async = g_unix_output_stream_write_async; + stream_class->write_finish = g_unix_output_stream_write_finish; + stream_class->close_async = g_unix_output_stream_close_async; + stream_class->close_finish = g_unix_output_stream_close_finish; } static void -g_socket_output_stream_init (GSocketOutputStream *socket) +g_unix_output_stream_init (GUnixOutputStream *unix_stream) { - socket->priv = G_TYPE_INSTANCE_GET_PRIVATE (socket, - G_TYPE_SOCKET_OUTPUT_STREAM, - GSocketOutputStreamPrivate); + unix_stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (unix_stream, + G_TYPE_UNIX_OUTPUT_STREAM, + GUnixOutputStreamPrivate); } /** - * g_socket_output_stream_new: - * @fd: socket's file descriptor. + * g_unix_output_stream_new: + * @fd: unix's file descriptor. * @close_fd_at_close: a #gboolean. * - * Creates a new socket output stream for @fd. If @close_fd_at_close - * is %TRUE, the socket will be closed when the output stream is destroyed. + * Creates a new unix output stream for @fd. If @close_fd_at_close + * is %TRUE, the fd will be closed when the output stream is destroyed. * * Returns: #GOutputStream. If @close_fd_at_close is %TRUE, then * @fd will be closed when the #GOutputStream is closed. **/ GOutputStream * -g_socket_output_stream_new (int fd, - gboolean close_fd_at_close) +g_unix_output_stream_new (int fd, + gboolean close_fd_at_close) { - GSocketOutputStream *stream; + GUnixOutputStream *stream; g_return_val_if_fail (fd != -1, NULL); - stream = g_object_new (G_TYPE_SOCKET_OUTPUT_STREAM, NULL); + stream = g_object_new (G_TYPE_UNIX_OUTPUT_STREAM, NULL); stream->priv->fd = fd; stream->priv->close_fd_at_close = close_fd_at_close; @@ -150,19 +151,19 @@ g_socket_output_stream_new (int fd, } static gssize -g_socket_output_stream_write (GOutputStream *stream, - const void *buffer, - gsize count, - GCancellable *cancellable, - GError **error) +g_unix_output_stream_write (GOutputStream *stream, + const void *buffer, + gsize count, + GCancellable *cancellable, + GError **error) { - GSocketOutputStream *socket_stream; + GUnixOutputStream *unix_stream; gssize res; struct pollfd poll_fds[2]; int poll_ret; int cancel_fd; - socket_stream = G_SOCKET_OUTPUT_STREAM (stream); + unix_stream = G_UNIX_OUTPUT_STREAM (stream); cancel_fd = g_cancellable_get_fd (cancellable); if (cancel_fd != -1) @@ -170,7 +171,7 @@ g_socket_output_stream_write (GOutputStream *stream, do { poll_fds[0].events = POLLOUT; - poll_fds[0].fd = socket_stream->priv->fd; + 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); @@ -181,7 +182,7 @@ g_socket_output_stream_write (GOutputStream *stream, { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - _("Error writing to socket: %s"), + _("Error writing to unix: %s"), g_strerror (errno)); return -1; } @@ -192,7 +193,7 @@ g_socket_output_stream_write (GOutputStream *stream, if (g_cancellable_set_error_if_cancelled (cancellable, error)) return -1; - res = write (socket_stream->priv->fd, buffer, count); + res = write (unix_stream->priv->fd, buffer, count); if (res == -1) { if (errno == EINTR) @@ -200,7 +201,7 @@ g_socket_output_stream_write (GOutputStream *stream, g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - _("Error writing to socket: %s"), + _("Error writing to unix: %s"), g_strerror (errno)); } @@ -211,27 +212,27 @@ g_socket_output_stream_write (GOutputStream *stream, } static gboolean -g_socket_output_stream_close (GOutputStream *stream, - GCancellable *cancellable, - GError **error) +g_unix_output_stream_close (GOutputStream *stream, + GCancellable *cancellable, + GError **error) { - GSocketOutputStream *socket_stream; + GUnixOutputStream *unix_stream; int res; - socket_stream = G_SOCKET_OUTPUT_STREAM (stream); + unix_stream = G_UNIX_OUTPUT_STREAM (stream); - if (!socket_stream->priv->close_fd_at_close) + if (!unix_stream->priv->close_fd_at_close) return TRUE; while (1) { /* This might block during the close. Doesn't seem to be a way to avoid it though. */ - res = close (socket_stream->priv->fd); + res = close (unix_stream->priv->fd); if (res == -1) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - _("Error closing socket: %s"), + _("Error closing unix: %s"), g_strerror (errno)); } break; @@ -246,7 +247,7 @@ typedef struct { GAsyncReadyCallback callback; gpointer user_data; GCancellable *cancellable; - GSocketOutputStream *stream; + GUnixOutputStream *stream; } WriteAsyncData; static gboolean @@ -274,7 +275,7 @@ write_async_cb (WriteAsyncData *data, g_set_error (&error, G_IO_ERROR, g_io_error_from_errno (errno), - _("Error reading from socket: %s"), + _("Error reading from unix: %s"), g_strerror (errno)); } break; @@ -283,7 +284,7 @@ write_async_cb (WriteAsyncData *data, simple = g_simple_async_result_new (G_OBJECT (data->stream), data->callback, data->user_data, - g_socket_output_stream_write_async); + g_unix_output_stream_write_async); g_simple_async_result_set_op_res_gssize (simple, count_written); @@ -301,19 +302,19 @@ write_async_cb (WriteAsyncData *data, } static void -g_socket_output_stream_write_async (GOutputStream *stream, - const void *buffer, - gsize count, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +g_unix_output_stream_write_async (GOutputStream *stream, + const void *buffer, + gsize count, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { GSource *source; - GSocketOutputStream *socket_stream; + GUnixOutputStream *unix_stream; WriteAsyncData *data; - socket_stream = G_SOCKET_OUTPUT_STREAM (stream); + unix_stream = G_UNIX_OUTPUT_STREAM (stream); data = g_new0 (WriteAsyncData, 1); data->count = count; @@ -321,9 +322,9 @@ g_socket_output_stream_write_async (GOutputStream *stream, data->callback = callback; data->user_data = user_data; data->cancellable = cancellable; - data->stream = socket_stream; + data->stream = unix_stream; - source = _g_fd_source_new (socket_stream->priv->fd, + source = _g_fd_source_new (unix_stream->priv->fd, POLLOUT, cancellable); @@ -334,15 +335,15 @@ g_socket_output_stream_write_async (GOutputStream *stream, } static gssize -g_socket_output_stream_write_finish (GOutputStream *stream, - GAsyncResult *result, - GError **error) +g_unix_output_stream_write_finish (GOutputStream *stream, + GAsyncResult *result, + GError **error) { GSimpleAsyncResult *simple; gssize nwritten; simple = G_SIMPLE_ASYNC_RESULT (result); - g_assert (g_simple_async_result_get_source_tag (simple) == g_socket_output_stream_write_async); + g_assert (g_simple_async_result_get_source_tag (simple) == g_unix_output_stream_write_async); nwritten = g_simple_async_result_get_op_res_gssize (simple); return nwritten; @@ -357,15 +358,15 @@ typedef struct { static gboolean close_async_cb (CloseAsyncData *data) { - GSocketOutputStream *socket_stream; + GUnixOutputStream *unix_stream; GSimpleAsyncResult *simple; GError *error = NULL; gboolean result; int res; - socket_stream = G_SOCKET_OUTPUT_STREAM (data->stream); + unix_stream = G_UNIX_OUTPUT_STREAM (data->stream); - if (!socket_stream->priv->close_fd_at_close) + if (!unix_stream->priv->close_fd_at_close) { result = TRUE; goto out; @@ -373,12 +374,12 @@ close_async_cb (CloseAsyncData *data) while (1) { - res = close (socket_stream->priv->fd); + res = close (unix_stream->priv->fd); if (res == -1) { g_set_error (&error, G_IO_ERROR, g_io_error_from_errno (errno), - _("Error closing socket: %s"), + _("Error closing unix: %s"), g_strerror (errno)); } break; @@ -390,7 +391,7 @@ close_async_cb (CloseAsyncData *data) simple = g_simple_async_result_new (G_OBJECT (data->stream), data->callback, data->user_data, - g_socket_output_stream_close_async); + g_unix_output_stream_close_async); if (!result) { @@ -406,11 +407,11 @@ close_async_cb (CloseAsyncData *data) } static void -g_socket_output_stream_close_async (GOutputStream *stream, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +g_unix_output_stream_close_async (GOutputStream *stream, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { GSource *idle; CloseAsyncData *data; @@ -428,9 +429,9 @@ g_socket_output_stream_close_async (GOutputStream *stream, } static gboolean -g_socket_output_stream_close_finish (GOutputStream *stream, - GAsyncResult *result, - GError **error) +g_unix_output_stream_close_finish (GOutputStream *stream, + GAsyncResult *result, + GError **error) { /* Failures handled in generic close_finish code */ return TRUE; diff --git a/gio/gunixoutputstream.h b/gio/gunixoutputstream.h new file mode 100644 index 000000000..08043f431 --- /dev/null +++ b/gio/gunixoutputstream.h @@ -0,0 +1,74 @@ +/* GIO - GLib Input, Output and Streaming Library + * + * Copyright (C) 2006-2007 Red Hat, Inc. + * + * 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. + * + * Author: Alexander Larsson + */ + +#ifndef __G_UNIX_OUTPUT_STREAM_H__ +#define __G_UNIX_OUTPUT_STREAM_H__ + +#include + +G_BEGIN_DECLS + +#define G_TYPE_UNIX_OUTPUT_STREAM (g_unix_output_stream_get_type ()) +#define G_UNIX_OUTPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_UNIX_OUTPUT_STREAM, GUnixOutputStream)) +#define G_UNIX_OUTPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_UNIX_OUTPUT_STREAM, GUnixOutputStreamClass)) +#define G_IS_UNIX_OUTPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_UNIX_OUTPUT_STREAM)) +#define G_IS_UNIX_OUTPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_UNIX_OUTPUT_STREAM)) +#define G_UNIX_OUTPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_UNIX_OUTPUT_STREAM, GUnixOutputStreamClass)) + +/** + * GUnixOutputStream: + * + * Implements #GOutputStream for outputting to selectable unix file descriptors + **/ +typedef struct _GUnixOutputStream GUnixOutputStream; +typedef struct _GUnixOutputStreamClass GUnixOutputStreamClass; +typedef struct _GUnixOutputStreamPrivate GUnixOutputStreamPrivate; + +struct _GUnixOutputStream +{ + GOutputStream parent; + + /*< private >*/ + GUnixOutputStreamPrivate *priv; +}; + +struct _GUnixOutputStreamClass +{ + GOutputStreamClass parent_class; + + /*< private >*/ + /* Padding for future expansion */ + void (*_g_reserved1) (void); + void (*_g_reserved2) (void); + void (*_g_reserved3) (void); + void (*_g_reserved4) (void); + void (*_g_reserved5) (void); +}; + +GType g_unix_output_stream_get_type (void) G_GNUC_CONST; + +GOutputStream *g_unix_output_stream_new (int fd, + gboolean close_fd_at_close); + +G_END_DECLS + +#endif /* __G_UNIX_OUTPUT_STREAM_H__ */