mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 22:46:15 +01:00
Removed. Removed. Added. Added. Renamed GSocket*Stream to GUnix*Stream and
2007-11-27 Alexander Larsson <alexl@redhat.com> * 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). svn path=/trunk/; revision=5956
This commit is contained in:
parent
e3607fcdf3
commit
77657981f0
@ -1,3 +1,14 @@
|
|||||||
|
2007-11-27 Alexander Larsson <alexl@redhat.com>
|
||||||
|
|
||||||
|
* 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 <awalton@svn.gnome.org>
|
2007-11-27 Andrew Walton <awalton@svn.gnome.org>
|
||||||
* gappinfo.c:
|
* gappinfo.c:
|
||||||
* gappinfo.h:
|
* gappinfo.h:
|
||||||
|
@ -81,11 +81,15 @@ unix_sources = \
|
|||||||
gunixvolume.h \
|
gunixvolume.h \
|
||||||
gunixvolumemonitor.c \
|
gunixvolumemonitor.c \
|
||||||
gunixvolumemonitor.h \
|
gunixvolumemonitor.h \
|
||||||
|
gunixinputstream.c \
|
||||||
|
gunixoutputstream.c \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
giounixincludedir=$(includedir)/gio-unix-2.0/gio
|
giounixincludedir=$(includedir)/gio-unix-2.0/gio
|
||||||
giounixinclude_HEADERS = \
|
giounixinclude_HEADERS = \
|
||||||
gunixmounts.h \
|
gunixmounts.h \
|
||||||
|
gunixinputstream.h \
|
||||||
|
gunixoutputstream.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -138,8 +142,6 @@ libgio_2_0_la_SOURCES = \
|
|||||||
gpollfilemonitor.h \
|
gpollfilemonitor.h \
|
||||||
gseekable.c \
|
gseekable.c \
|
||||||
gsimpleasyncresult.c \
|
gsimpleasyncresult.c \
|
||||||
gsocketinputstream.c \
|
|
||||||
gsocketoutputstream.c \
|
|
||||||
gthemedicon.c \
|
gthemedicon.c \
|
||||||
gunionvolumemonitor.c \
|
gunionvolumemonitor.c \
|
||||||
gunionvolumemonitor.h \
|
gunionvolumemonitor.h \
|
||||||
@ -207,8 +209,6 @@ gioinclude_HEADERS = \
|
|||||||
goutputstream.h \
|
goutputstream.h \
|
||||||
gseekable.h \
|
gseekable.h \
|
||||||
gsimpleasyncresult.h \
|
gsimpleasyncresult.h \
|
||||||
gsocketinputstream.h \
|
|
||||||
gsocketoutputstream.h \
|
|
||||||
gthemedicon.h \
|
gthemedicon.h \
|
||||||
gvfs.h \
|
gvfs.h \
|
||||||
gvolume.h \
|
gvolume.h \
|
||||||
|
@ -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 <alexl@redhat.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __G_SOCKET_INPUT_STREAM_H__
|
|
||||||
#define __G_SOCKET_INPUT_STREAM_H__
|
|
||||||
|
|
||||||
#include <gio/ginputstream.h>
|
|
||||||
|
|
||||||
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__ */
|
|
@ -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 <alexl@redhat.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __G_SOCKET_OUTPUT_STREAM_H__
|
|
||||||
#define __G_SOCKET_OUTPUT_STREAM_H__
|
|
||||||
|
|
||||||
#include <gio/goutputstream.h>
|
|
||||||
|
|
||||||
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__ */
|
|
@ -34,125 +34,127 @@
|
|||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "gsimpleasyncresult.h"
|
#include "gsimpleasyncresult.h"
|
||||||
#include "gsocketinputstream.h"
|
#include "gunixinputstream.h"
|
||||||
#include "gcancellable.h"
|
#include "gcancellable.h"
|
||||||
#include "gasynchelper.h"
|
#include "gasynchelper.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:gsocketinputstream
|
* SECTION:gunixinputstream
|
||||||
* @short_description: Socket Input Stream
|
* @short_description: Unix Input Stream
|
||||||
* @see_also: #GInputStream.
|
* @see_also: #GInputStream.
|
||||||
*
|
*
|
||||||
* #GSocketInputStream implements #GInputStream for reading from a socket,
|
* #GUnixInputStream implements #GInputStream for reading from a
|
||||||
* including asynchronous operations.
|
* 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;
|
int fd;
|
||||||
gboolean close_fd_at_close;
|
gboolean close_fd_at_close;
|
||||||
};
|
};
|
||||||
|
|
||||||
static gssize g_socket_input_stream_read (GInputStream *stream,
|
static gssize g_unix_input_stream_read (GInputStream *stream,
|
||||||
void *buffer,
|
void *buffer,
|
||||||
gsize count,
|
gsize count,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
static gboolean g_socket_input_stream_close (GInputStream *stream,
|
static gboolean g_unix_input_stream_close (GInputStream *stream,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
static void g_socket_input_stream_read_async (GInputStream *stream,
|
static void g_unix_input_stream_read_async (GInputStream *stream,
|
||||||
void *buffer,
|
void *buffer,
|
||||||
gsize count,
|
gsize count,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static gssize g_socket_input_stream_read_finish (GInputStream *stream,
|
static gssize g_unix_input_stream_read_finish (GInputStream *stream,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error);
|
GError **error);
|
||||||
static void g_socket_input_stream_skip_async (GInputStream *stream,
|
static void g_unix_input_stream_skip_async (GInputStream *stream,
|
||||||
gsize count,
|
gsize count,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static gssize g_socket_input_stream_skip_finish (GInputStream *stream,
|
static gssize g_unix_input_stream_skip_finish (GInputStream *stream,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error);
|
GError **error);
|
||||||
static void g_socket_input_stream_close_async (GInputStream *stream,
|
static void g_unix_input_stream_close_async (GInputStream *stream,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static gboolean g_socket_input_stream_close_finish (GInputStream *stream,
|
static gboolean g_unix_input_stream_close_finish (GInputStream *stream,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
|
||||||
static void
|
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)
|
if (G_OBJECT_CLASS (g_unix_input_stream_parent_class)->finalize)
|
||||||
(*G_OBJECT_CLASS (g_socket_input_stream_parent_class)->finalize) (object);
|
(*G_OBJECT_CLASS (g_unix_input_stream_parent_class)->finalize) (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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);
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
GInputStreamClass *stream_class = G_INPUT_STREAM_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->read = g_unix_input_stream_read;
|
||||||
stream_class->close = g_socket_input_stream_close;
|
stream_class->close = g_unix_input_stream_close;
|
||||||
stream_class->read_async = g_socket_input_stream_read_async;
|
stream_class->read_async = g_unix_input_stream_read_async;
|
||||||
stream_class->read_finish = g_socket_input_stream_read_finish;
|
stream_class->read_finish = g_unix_input_stream_read_finish;
|
||||||
if (0)
|
if (0)
|
||||||
{
|
{
|
||||||
/* TODO: Implement instead of using fallbacks */
|
/* TODO: Implement instead of using fallbacks */
|
||||||
stream_class->skip_async = g_socket_input_stream_skip_async;
|
stream_class->skip_async = g_unix_input_stream_skip_async;
|
||||||
stream_class->skip_finish = g_socket_input_stream_skip_finish;
|
stream_class->skip_finish = g_unix_input_stream_skip_finish;
|
||||||
}
|
}
|
||||||
stream_class->close_async = g_socket_input_stream_close_async;
|
stream_class->close_async = g_unix_input_stream_close_async;
|
||||||
stream_class->close_finish = g_socket_input_stream_close_finish;
|
stream_class->close_finish = g_unix_input_stream_close_finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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,
|
unix_stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (unix_stream,
|
||||||
G_TYPE_SOCKET_INPUT_STREAM,
|
G_TYPE_UNIX_INPUT_STREAM,
|
||||||
GSocketInputStreamPrivate);
|
GUnixInputStreamPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_socket_input_stream_new:
|
* g_unix_input_stream_new:
|
||||||
* @fd: socket file descriptor.
|
* @fd: unix file descriptor.
|
||||||
* @close_fd_at_close: a #gboolean.
|
* @close_fd_at_close: a #gboolean.
|
||||||
*
|
*
|
||||||
* Creates a new #GSocketInputStream for the given @fd. If @close_fd_at_close
|
* Creates a new #GUnixInputStream for the given @fd. If @close_fd_at_close
|
||||||
* is %TRUE, the socket will be closed when the stream is closed.
|
* is %TRUE, the file descriptor will be closed when the stream is closed.
|
||||||
*
|
*
|
||||||
* Returns: a #GSocketInputStream.
|
* Returns: a #GUnixInputStream.
|
||||||
**/
|
**/
|
||||||
GInputStream *
|
GInputStream *
|
||||||
g_socket_input_stream_new (int fd,
|
g_unix_input_stream_new (int fd,
|
||||||
gboolean close_fd_at_close)
|
gboolean close_fd_at_close)
|
||||||
{
|
{
|
||||||
GSocketInputStream *stream;
|
GUnixInputStream *stream;
|
||||||
|
|
||||||
g_return_val_if_fail (fd != -1, NULL);
|
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->fd = fd;
|
||||||
stream->priv->close_fd_at_close = close_fd_at_close;
|
stream->priv->close_fd_at_close = close_fd_at_close;
|
||||||
@ -161,19 +163,19 @@ g_socket_input_stream_new (int fd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gssize
|
static gssize
|
||||||
g_socket_input_stream_read (GInputStream *stream,
|
g_unix_input_stream_read (GInputStream *stream,
|
||||||
void *buffer,
|
void *buffer,
|
||||||
gsize count,
|
gsize count,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSocketInputStream *socket_stream;
|
GUnixInputStream *unix_stream;
|
||||||
gssize res;
|
gssize res;
|
||||||
struct pollfd poll_fds[2];
|
struct pollfd poll_fds[2];
|
||||||
int poll_ret;
|
int poll_ret;
|
||||||
int cancel_fd;
|
int cancel_fd;
|
||||||
|
|
||||||
socket_stream = G_SOCKET_INPUT_STREAM (stream);
|
unix_stream = G_UNIX_INPUT_STREAM (stream);
|
||||||
|
|
||||||
cancel_fd = g_cancellable_get_fd (cancellable);
|
cancel_fd = g_cancellable_get_fd (cancellable);
|
||||||
if (cancel_fd != -1)
|
if (cancel_fd != -1)
|
||||||
@ -181,7 +183,7 @@ g_socket_input_stream_read (GInputStream *stream,
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
poll_fds[0].events = POLLIN;
|
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].events = POLLIN;
|
||||||
poll_fds[1].fd = cancel_fd;
|
poll_fds[1].fd = cancel_fd;
|
||||||
poll_ret = poll (poll_fds, 2, -1);
|
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_set_error (error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errno),
|
g_io_error_from_errno (errno),
|
||||||
_("Error reading from socket: %s"),
|
_("Error reading from unix: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -202,7 +204,7 @@ g_socket_input_stream_read (GInputStream *stream,
|
|||||||
{
|
{
|
||||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||||
break;
|
break;
|
||||||
res = read (socket_stream->priv->fd, buffer, count);
|
res = read (unix_stream->priv->fd, buffer, count);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
{
|
{
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
@ -210,7 +212,7 @@ g_socket_input_stream_read (GInputStream *stream,
|
|||||||
|
|
||||||
g_set_error (error, G_IO_ERROR,
|
g_set_error (error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errno),
|
g_io_error_from_errno (errno),
|
||||||
_("Error reading from socket: %s"),
|
_("Error reading from unix: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,27 +223,27 @@ g_socket_input_stream_read (GInputStream *stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
g_socket_input_stream_close (GInputStream *stream,
|
g_unix_input_stream_close (GInputStream *stream,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSocketInputStream *socket_stream;
|
GUnixInputStream *unix_stream;
|
||||||
int res;
|
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;
|
return TRUE;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* This might block during the close. Doesn't seem to be a way to avoid it though. */
|
/* 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)
|
if (res == -1)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR,
|
g_set_error (error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errno),
|
g_io_error_from_errno (errno),
|
||||||
_("Error closing socket: %s"),
|
_("Error closing unix: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -256,7 +258,7 @@ typedef struct {
|
|||||||
GAsyncReadyCallback callback;
|
GAsyncReadyCallback callback;
|
||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
GSocketInputStream *stream;
|
GUnixInputStream *stream;
|
||||||
} ReadAsyncData;
|
} ReadAsyncData;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -284,7 +286,7 @@ read_async_cb (ReadAsyncData *data,
|
|||||||
|
|
||||||
g_set_error (&error, G_IO_ERROR,
|
g_set_error (&error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errno),
|
g_io_error_from_errno (errno),
|
||||||
_("Error reading from socket: %s"),
|
_("Error reading from unix: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -293,7 +295,7 @@ read_async_cb (ReadAsyncData *data,
|
|||||||
simple = g_simple_async_result_new (G_OBJECT (data->stream),
|
simple = g_simple_async_result_new (G_OBJECT (data->stream),
|
||||||
data->callback,
|
data->callback,
|
||||||
data->user_data,
|
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);
|
g_simple_async_result_set_op_res_gssize (simple, count_read);
|
||||||
|
|
||||||
@ -311,7 +313,7 @@ read_async_cb (ReadAsyncData *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_socket_input_stream_read_async (GInputStream *stream,
|
g_unix_input_stream_read_async (GInputStream *stream,
|
||||||
void *buffer,
|
void *buffer,
|
||||||
gsize count,
|
gsize count,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
@ -320,10 +322,10 @@ g_socket_input_stream_read_async (GInputStream *stream,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSource *source;
|
GSource *source;
|
||||||
GSocketInputStream *socket_stream;
|
GUnixInputStream *unix_stream;
|
||||||
ReadAsyncData *data;
|
ReadAsyncData *data;
|
||||||
|
|
||||||
socket_stream = G_SOCKET_INPUT_STREAM (stream);
|
unix_stream = G_UNIX_INPUT_STREAM (stream);
|
||||||
|
|
||||||
data = g_new0 (ReadAsyncData, 1);
|
data = g_new0 (ReadAsyncData, 1);
|
||||||
data->count = count;
|
data->count = count;
|
||||||
@ -331,9 +333,9 @@ g_socket_input_stream_read_async (GInputStream *stream,
|
|||||||
data->callback = callback;
|
data->callback = callback;
|
||||||
data->user_data = user_data;
|
data->user_data = user_data;
|
||||||
data->cancellable = cancellable;
|
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,
|
POLLIN,
|
||||||
cancellable);
|
cancellable);
|
||||||
|
|
||||||
@ -344,7 +346,7 @@ g_socket_input_stream_read_async (GInputStream *stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gssize
|
static gssize
|
||||||
g_socket_input_stream_read_finish (GInputStream *stream,
|
g_unix_input_stream_read_finish (GInputStream *stream,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
@ -352,14 +354,14 @@ g_socket_input_stream_read_finish (GInputStream *stream,
|
|||||||
gssize nread;
|
gssize nread;
|
||||||
|
|
||||||
simple = G_SIMPLE_ASYNC_RESULT (result);
|
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);
|
nread = g_simple_async_result_get_op_res_gssize (simple);
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_socket_input_stream_skip_async (GInputStream *stream,
|
g_unix_input_stream_skip_async (GInputStream *stream,
|
||||||
gsize count,
|
gsize count,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
@ -371,7 +373,7 @@ g_socket_input_stream_skip_async (GInputStream *stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gssize
|
static gssize
|
||||||
g_socket_input_stream_skip_finish (GInputStream *stream,
|
g_unix_input_stream_skip_finish (GInputStream *stream,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
@ -397,15 +399,15 @@ close_async_data_free (gpointer _data)
|
|||||||
static gboolean
|
static gboolean
|
||||||
close_async_cb (CloseAsyncData *data)
|
close_async_cb (CloseAsyncData *data)
|
||||||
{
|
{
|
||||||
GSocketInputStream *socket_stream;
|
GUnixInputStream *unix_stream;
|
||||||
GSimpleAsyncResult *simple;
|
GSimpleAsyncResult *simple;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean result;
|
gboolean result;
|
||||||
int res;
|
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;
|
result = TRUE;
|
||||||
goto out;
|
goto out;
|
||||||
@ -413,12 +415,12 @@ close_async_cb (CloseAsyncData *data)
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
res = close (socket_stream->priv->fd);
|
res = close (unix_stream->priv->fd);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
{
|
{
|
||||||
g_set_error (&error, G_IO_ERROR,
|
g_set_error (&error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errno),
|
g_io_error_from_errno (errno),
|
||||||
_("Error closing socket: %s"),
|
_("Error closing unix: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -430,7 +432,7 @@ close_async_cb (CloseAsyncData *data)
|
|||||||
simple = g_simple_async_result_new (G_OBJECT (data->stream),
|
simple = g_simple_async_result_new (G_OBJECT (data->stream),
|
||||||
data->callback,
|
data->callback,
|
||||||
data->user_data,
|
data->user_data,
|
||||||
g_socket_input_stream_close_async);
|
g_unix_input_stream_close_async);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
@ -446,7 +448,7 @@ close_async_cb (CloseAsyncData *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_socket_input_stream_close_async (GInputStream *stream,
|
g_unix_input_stream_close_async (GInputStream *stream,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
@ -468,7 +470,7 @@ g_socket_input_stream_close_async (GInputStream *stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
g_socket_input_stream_close_finish (GInputStream *stream,
|
g_unix_input_stream_close_finish (GInputStream *stream,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
74
gio/gunixinputstream.h
Normal file
74
gio/gunixinputstream.h
Normal file
@ -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 <alexl@redhat.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __G_UNIX_INPUT_STREAM_H__
|
||||||
|
#define __G_UNIX_INPUT_STREAM_H__
|
||||||
|
|
||||||
|
#include <gio/ginputstream.h>
|
||||||
|
|
||||||
|
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__ */
|
@ -33,115 +33,116 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "gsocketoutputstream.h"
|
#include "gunixoutputstream.h"
|
||||||
#include "gcancellable.h"
|
#include "gcancellable.h"
|
||||||
#include "gsimpleasyncresult.h"
|
#include "gsimpleasyncresult.h"
|
||||||
#include "gasynchelper.h"
|
#include "gasynchelper.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:gsocketoutputstream
|
* SECTION:gunixoutputstream
|
||||||
* @short_description: Socket Output Stream
|
* @short_description: Unix Output Stream
|
||||||
* @see_also: #GOutputStream.
|
* @see_also: #GOutputStream.
|
||||||
*
|
*
|
||||||
* #GSocketOutputStream implements #GOutputStream for writing to a socket, including
|
* #GUnixOutputStream implements #GOutputStream for writing to a a
|
||||||
* asynchronous operations.
|
* 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;
|
int fd;
|
||||||
gboolean close_fd_at_close;
|
gboolean close_fd_at_close;
|
||||||
};
|
};
|
||||||
|
|
||||||
static gssize g_socket_output_stream_write (GOutputStream *stream,
|
static gssize g_unix_output_stream_write (GOutputStream *stream,
|
||||||
const void *buffer,
|
const void *buffer,
|
||||||
gsize count,
|
gsize count,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
static gboolean g_socket_output_stream_close (GOutputStream *stream,
|
static gboolean g_unix_output_stream_close (GOutputStream *stream,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
static void g_socket_output_stream_write_async (GOutputStream *stream,
|
static void g_unix_output_stream_write_async (GOutputStream *stream,
|
||||||
const void *buffer,
|
const void *buffer,
|
||||||
gsize count,
|
gsize count,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static gssize g_socket_output_stream_write_finish (GOutputStream *stream,
|
static gssize g_unix_output_stream_write_finish (GOutputStream *stream,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error);
|
GError **error);
|
||||||
static void g_socket_output_stream_close_async (GOutputStream *stream,
|
static void g_unix_output_stream_close_async (GOutputStream *stream,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static gboolean g_socket_output_stream_close_finish (GOutputStream *stream,
|
static gboolean g_unix_output_stream_close_finish (GOutputStream *stream,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
|
||||||
static void
|
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)
|
if (G_OBJECT_CLASS (g_unix_output_stream_parent_class)->finalize)
|
||||||
(*G_OBJECT_CLASS (g_socket_output_stream_parent_class)->finalize) (object);
|
(*G_OBJECT_CLASS (g_unix_output_stream_parent_class)->finalize) (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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);
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
GOutputStreamClass *stream_class = G_OUTPUT_STREAM_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->write = g_unix_output_stream_write;
|
||||||
stream_class->close = g_socket_output_stream_close;
|
stream_class->close = g_unix_output_stream_close;
|
||||||
stream_class->write_async = g_socket_output_stream_write_async;
|
stream_class->write_async = g_unix_output_stream_write_async;
|
||||||
stream_class->write_finish = g_socket_output_stream_write_finish;
|
stream_class->write_finish = g_unix_output_stream_write_finish;
|
||||||
stream_class->close_async = g_socket_output_stream_close_async;
|
stream_class->close_async = g_unix_output_stream_close_async;
|
||||||
stream_class->close_finish = g_socket_output_stream_close_finish;
|
stream_class->close_finish = g_unix_output_stream_close_finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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,
|
unix_stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (unix_stream,
|
||||||
G_TYPE_SOCKET_OUTPUT_STREAM,
|
G_TYPE_UNIX_OUTPUT_STREAM,
|
||||||
GSocketOutputStreamPrivate);
|
GUnixOutputStreamPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_socket_output_stream_new:
|
* g_unix_output_stream_new:
|
||||||
* @fd: socket's file descriptor.
|
* @fd: unix's file descriptor.
|
||||||
* @close_fd_at_close: a #gboolean.
|
* @close_fd_at_close: a #gboolean.
|
||||||
*
|
*
|
||||||
* Creates a new socket output stream for @fd. If @close_fd_at_close
|
* Creates a new unix output stream for @fd. If @close_fd_at_close
|
||||||
* is %TRUE, the socket will be closed when the output stream is destroyed.
|
* is %TRUE, the fd will be closed when the output stream is destroyed.
|
||||||
*
|
*
|
||||||
* Returns: #GOutputStream. If @close_fd_at_close is %TRUE, then
|
* Returns: #GOutputStream. If @close_fd_at_close is %TRUE, then
|
||||||
* @fd will be closed when the #GOutputStream is closed.
|
* @fd will be closed when the #GOutputStream is closed.
|
||||||
**/
|
**/
|
||||||
GOutputStream *
|
GOutputStream *
|
||||||
g_socket_output_stream_new (int fd,
|
g_unix_output_stream_new (int fd,
|
||||||
gboolean close_fd_at_close)
|
gboolean close_fd_at_close)
|
||||||
{
|
{
|
||||||
GSocketOutputStream *stream;
|
GUnixOutputStream *stream;
|
||||||
|
|
||||||
g_return_val_if_fail (fd != -1, NULL);
|
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->fd = fd;
|
||||||
stream->priv->close_fd_at_close = close_fd_at_close;
|
stream->priv->close_fd_at_close = close_fd_at_close;
|
||||||
@ -150,19 +151,19 @@ g_socket_output_stream_new (int fd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gssize
|
static gssize
|
||||||
g_socket_output_stream_write (GOutputStream *stream,
|
g_unix_output_stream_write (GOutputStream *stream,
|
||||||
const void *buffer,
|
const void *buffer,
|
||||||
gsize count,
|
gsize count,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSocketOutputStream *socket_stream;
|
GUnixOutputStream *unix_stream;
|
||||||
gssize res;
|
gssize res;
|
||||||
struct pollfd poll_fds[2];
|
struct pollfd poll_fds[2];
|
||||||
int poll_ret;
|
int poll_ret;
|
||||||
int cancel_fd;
|
int cancel_fd;
|
||||||
|
|
||||||
socket_stream = G_SOCKET_OUTPUT_STREAM (stream);
|
unix_stream = G_UNIX_OUTPUT_STREAM (stream);
|
||||||
|
|
||||||
cancel_fd = g_cancellable_get_fd (cancellable);
|
cancel_fd = g_cancellable_get_fd (cancellable);
|
||||||
if (cancel_fd != -1)
|
if (cancel_fd != -1)
|
||||||
@ -170,7 +171,7 @@ g_socket_output_stream_write (GOutputStream *stream,
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
poll_fds[0].events = POLLOUT;
|
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].events = POLLIN;
|
||||||
poll_fds[1].fd = cancel_fd;
|
poll_fds[1].fd = cancel_fd;
|
||||||
poll_ret = poll (poll_fds, 2, -1);
|
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_set_error (error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errno),
|
g_io_error_from_errno (errno),
|
||||||
_("Error writing to socket: %s"),
|
_("Error writing to unix: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -192,7 +193,7 @@ g_socket_output_stream_write (GOutputStream *stream,
|
|||||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
res = write (socket_stream->priv->fd, buffer, count);
|
res = write (unix_stream->priv->fd, buffer, count);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
{
|
{
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
@ -200,7 +201,7 @@ g_socket_output_stream_write (GOutputStream *stream,
|
|||||||
|
|
||||||
g_set_error (error, G_IO_ERROR,
|
g_set_error (error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errno),
|
g_io_error_from_errno (errno),
|
||||||
_("Error writing to socket: %s"),
|
_("Error writing to unix: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,27 +212,27 @@ g_socket_output_stream_write (GOutputStream *stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
g_socket_output_stream_close (GOutputStream *stream,
|
g_unix_output_stream_close (GOutputStream *stream,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSocketOutputStream *socket_stream;
|
GUnixOutputStream *unix_stream;
|
||||||
int res;
|
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;
|
return TRUE;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* This might block during the close. Doesn't seem to be a way to avoid it though. */
|
/* 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)
|
if (res == -1)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR,
|
g_set_error (error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errno),
|
g_io_error_from_errno (errno),
|
||||||
_("Error closing socket: %s"),
|
_("Error closing unix: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -246,7 +247,7 @@ typedef struct {
|
|||||||
GAsyncReadyCallback callback;
|
GAsyncReadyCallback callback;
|
||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
GSocketOutputStream *stream;
|
GUnixOutputStream *stream;
|
||||||
} WriteAsyncData;
|
} WriteAsyncData;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -274,7 +275,7 @@ write_async_cb (WriteAsyncData *data,
|
|||||||
|
|
||||||
g_set_error (&error, G_IO_ERROR,
|
g_set_error (&error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errno),
|
g_io_error_from_errno (errno),
|
||||||
_("Error reading from socket: %s"),
|
_("Error reading from unix: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -283,7 +284,7 @@ write_async_cb (WriteAsyncData *data,
|
|||||||
simple = g_simple_async_result_new (G_OBJECT (data->stream),
|
simple = g_simple_async_result_new (G_OBJECT (data->stream),
|
||||||
data->callback,
|
data->callback,
|
||||||
data->user_data,
|
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);
|
g_simple_async_result_set_op_res_gssize (simple, count_written);
|
||||||
|
|
||||||
@ -301,7 +302,7 @@ write_async_cb (WriteAsyncData *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_socket_output_stream_write_async (GOutputStream *stream,
|
g_unix_output_stream_write_async (GOutputStream *stream,
|
||||||
const void *buffer,
|
const void *buffer,
|
||||||
gsize count,
|
gsize count,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
@ -310,10 +311,10 @@ g_socket_output_stream_write_async (GOutputStream *stream,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSource *source;
|
GSource *source;
|
||||||
GSocketOutputStream *socket_stream;
|
GUnixOutputStream *unix_stream;
|
||||||
WriteAsyncData *data;
|
WriteAsyncData *data;
|
||||||
|
|
||||||
socket_stream = G_SOCKET_OUTPUT_STREAM (stream);
|
unix_stream = G_UNIX_OUTPUT_STREAM (stream);
|
||||||
|
|
||||||
data = g_new0 (WriteAsyncData, 1);
|
data = g_new0 (WriteAsyncData, 1);
|
||||||
data->count = count;
|
data->count = count;
|
||||||
@ -321,9 +322,9 @@ g_socket_output_stream_write_async (GOutputStream *stream,
|
|||||||
data->callback = callback;
|
data->callback = callback;
|
||||||
data->user_data = user_data;
|
data->user_data = user_data;
|
||||||
data->cancellable = cancellable;
|
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,
|
POLLOUT,
|
||||||
cancellable);
|
cancellable);
|
||||||
|
|
||||||
@ -334,7 +335,7 @@ g_socket_output_stream_write_async (GOutputStream *stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gssize
|
static gssize
|
||||||
g_socket_output_stream_write_finish (GOutputStream *stream,
|
g_unix_output_stream_write_finish (GOutputStream *stream,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
@ -342,7 +343,7 @@ g_socket_output_stream_write_finish (GOutputStream *stream,
|
|||||||
gssize nwritten;
|
gssize nwritten;
|
||||||
|
|
||||||
simple = G_SIMPLE_ASYNC_RESULT (result);
|
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);
|
nwritten = g_simple_async_result_get_op_res_gssize (simple);
|
||||||
return nwritten;
|
return nwritten;
|
||||||
@ -357,15 +358,15 @@ typedef struct {
|
|||||||
static gboolean
|
static gboolean
|
||||||
close_async_cb (CloseAsyncData *data)
|
close_async_cb (CloseAsyncData *data)
|
||||||
{
|
{
|
||||||
GSocketOutputStream *socket_stream;
|
GUnixOutputStream *unix_stream;
|
||||||
GSimpleAsyncResult *simple;
|
GSimpleAsyncResult *simple;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean result;
|
gboolean result;
|
||||||
int res;
|
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;
|
result = TRUE;
|
||||||
goto out;
|
goto out;
|
||||||
@ -373,12 +374,12 @@ close_async_cb (CloseAsyncData *data)
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
res = close (socket_stream->priv->fd);
|
res = close (unix_stream->priv->fd);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
{
|
{
|
||||||
g_set_error (&error, G_IO_ERROR,
|
g_set_error (&error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errno),
|
g_io_error_from_errno (errno),
|
||||||
_("Error closing socket: %s"),
|
_("Error closing unix: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -390,7 +391,7 @@ close_async_cb (CloseAsyncData *data)
|
|||||||
simple = g_simple_async_result_new (G_OBJECT (data->stream),
|
simple = g_simple_async_result_new (G_OBJECT (data->stream),
|
||||||
data->callback,
|
data->callback,
|
||||||
data->user_data,
|
data->user_data,
|
||||||
g_socket_output_stream_close_async);
|
g_unix_output_stream_close_async);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
@ -406,7 +407,7 @@ close_async_cb (CloseAsyncData *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_socket_output_stream_close_async (GOutputStream *stream,
|
g_unix_output_stream_close_async (GOutputStream *stream,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
@ -428,7 +429,7 @@ g_socket_output_stream_close_async (GOutputStream *stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
g_socket_output_stream_close_finish (GOutputStream *stream,
|
g_unix_output_stream_close_finish (GOutputStream *stream,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
74
gio/gunixoutputstream.h
Normal file
74
gio/gunixoutputstream.h
Normal file
@ -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 <alexl@redhat.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __G_UNIX_OUTPUT_STREAM_H__
|
||||||
|
#define __G_UNIX_OUTPUT_STREAM_H__
|
||||||
|
|
||||||
|
#include <gio/goutputstream.h>
|
||||||
|
|
||||||
|
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__ */
|
Loading…
Reference in New Issue
Block a user