mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-10-28 15:02:17 +01:00
build
docs
gio
completion
fam
fen
gdbus-2.0
gvdb
inotify
tests
win32
xdgmime
.gitignore
ChangeLog
Makefile.am
abicheck.sh
data-to-c.pl
dbus-daemon.xml
gaction.c
gaction.h
gactiongroup.c
gactiongroup.h
gactiongroupexporter.c
gactiongroupexporter.h
gactionmap.c
gactionmap.h
gappinfo.c
gappinfo.h
gapplication.c
gapplication.h
gapplicationcommandline.c
gapplicationcommandline.h
gapplicationimpl-dbus.c
gapplicationimpl.h
gasynchelper.c
gasynchelper.h
gasyncinitable.c
gasyncinitable.h
gasyncresult.c
gasyncresult.h
gbufferedinputstream.c
gbufferedinputstream.h
gbufferedoutputstream.c
gbufferedoutputstream.h
gcancellable.c
gcancellable.h
gcharsetconverter.c
gcharsetconverter.h
gcontenttype-win32.c
gcontenttype.c
gcontenttype.h
gcontenttypeprivate.h
gconverter.c
gconverter.h
gconverterinputstream.c
gconverterinputstream.h
gconverteroutputstream.c
gconverteroutputstream.h
gcredentials.c
gcredentials.h
gdatainputstream.c
gdatainputstream.h
gdataoutputstream.c
gdataoutputstream.h
gdbus-tool.c
gdbusactiongroup.c
gdbusactiongroup.h
gdbusaddress.c
gdbusaddress.h
gdbusauth.c
gdbusauth.h
gdbusauthmechanism.c
gdbusauthmechanism.h
gdbusauthmechanismanon.c
gdbusauthmechanismanon.h
gdbusauthmechanismexternal.c
gdbusauthmechanismexternal.h
gdbusauthmechanismsha1.c
gdbusauthmechanismsha1.h
gdbusauthobserver.c
gdbusauthobserver.h
gdbusconnection.c
gdbusconnection.h
gdbusdaemon.c
gdbusdaemon.h
gdbuserror.c
gdbuserror.h
gdbusinterface.c
gdbusinterface.h
gdbusinterfaceskeleton.c
gdbusinterfaceskeleton.h
gdbusintrospection.c
gdbusintrospection.h
gdbusmenumodel.c
gdbusmenumodel.h
gdbusmessage.c
gdbusmessage.h
gdbusmethodinvocation.c
gdbusmethodinvocation.h
gdbusnameowning.c
gdbusnameowning.h
gdbusnamewatching.c
gdbusnamewatching.h
gdbusobject.c
gdbusobject.h
gdbusobjectmanager.c
gdbusobjectmanager.h
gdbusobjectmanagerclient.c
gdbusobjectmanagerclient.h
gdbusobjectmanagerserver.c
gdbusobjectmanagerserver.h
gdbusobjectproxy.c
gdbusobjectproxy.h
gdbusobjectskeleton.c
gdbusobjectskeleton.h
gdbusprivate.c
gdbusprivate.h
gdbusproxy.c
gdbusproxy.h
gdbusserver.c
gdbusserver.h
gdbusutils.c
gdbusutils.h
gdelayedsettingsbackend.c
gdelayedsettingsbackend.h
gdesktopappinfo.c
gdesktopappinfo.h
gdrive.c
gdrive.h
gdummyfile.c
gdummyfile.h
gdummyproxyresolver.c
gdummyproxyresolver.h
gdummytlsbackend.c
gdummytlsbackend.h
gemblem.c
gemblem.h
gemblemedicon.c
gemblemedicon.h
gfile.c
gfile.h
gfileattribute-priv.h
gfileattribute.c
gfileattribute.h
gfiledescriptorbased.c
gfiledescriptorbased.h
gfileenumerator.c
gfileenumerator.h
gfileicon.c
gfileicon.h
gfileinfo-priv.h
gfileinfo.c
gfileinfo.h
gfileinputstream.c
gfileinputstream.h
gfileiostream.c
gfileiostream.h
gfilemonitor.c
gfilemonitor.h
gfilenamecompleter.c
gfilenamecompleter.h
gfileoutputstream.c
gfileoutputstream.h
gfilterinputstream.c
gfilterinputstream.h
gfilteroutputstream.c
gfilteroutputstream.h
gicon.c
gicon.h
ginetaddress.c
ginetaddress.h
ginetaddressmask.c
ginetaddressmask.h
ginetsocketaddress.c
ginetsocketaddress.h
ginitable.c
ginitable.h
ginputstream.c
ginputstream.h
gio-querymodules.c
gio.h
gio.rc.in
gio.symbols
gioenums.h
gioenumtypes.c.template
gioenumtypes.h.template
gioerror.c
gioerror.h
giomodule-priv.h
giomodule.c
giomodule.h
gioscheduler.c
gioscheduler.h
giostream.c
giostream.h
giotypes.h
gkeyfilesettingsbackend.c
glib-compile-resources.c
glib-compile-schemas.c
gloadableicon.c
gloadableicon.h
glocaldirectorymonitor.c
glocaldirectorymonitor.h
glocalfile.c
glocalfile.h
glocalfileenumerator.c
glocalfileenumerator.h
glocalfileinfo.c
glocalfileinfo.h
glocalfileinputstream.c
glocalfileinputstream.h
glocalfileiostream.c
glocalfileiostream.h
glocalfilemonitor.c
glocalfilemonitor.h
glocalfileoutputstream.c
glocalfileoutputstream.h
glocalvfs.c
glocalvfs.h
gmemoryinputstream.c
gmemoryinputstream.h
gmemoryoutputstream.c
gmemoryoutputstream.h
gmemorysettingsbackend.c
gmenu.c
gmenu.h
gmenuexporter.c
gmenuexporter.h
gmenumodel.c
gmenumodel.h
gmount.c
gmount.h
gmountoperation.c
gmountoperation.h
gmountprivate.h
gnativevolumemonitor.c
gnativevolumemonitor.h
gnetworkaddress.c
gnetworkaddress.h
gnetworkingprivate.h
gnetworkmonitor.c
gnetworkmonitor.h
gnetworkmonitorbase.c
gnetworkmonitorbase.h
gnetworkmonitornetlink.c
gnetworkmonitornetlink.h
gnetworkservice.c
gnetworkservice.h
gnextstepsettingsbackend.c
gnullsettingsbackend.c
goutputstream.c
goutputstream.h
gpermission.c
gpermission.h
gpollableinputstream.c
gpollableinputstream.h
gpollableoutputstream.c
gpollableoutputstream.h
gpollableutils.c
gpollableutils.h
gpollfilemonitor.c
gpollfilemonitor.h
gproxy.c
gproxy.h
gproxyaddress.c
gproxyaddress.h
gproxyaddressenumerator.c
gproxyaddressenumerator.h
gproxyresolver.c
gproxyresolver.h
gregistrysettingsbackend.c
gregistrysettingsbackend.h
gremoteactiongroup.c
gremoteactiongroup.h
gresolver.c
gresolver.h
gresource-tool.c
gresource.c
gresource.h
gresourcefile.c
gresourcefile.h
gschema.dtd
gseekable.c
gseekable.h
gsettings-mapping.c
gsettings-mapping.h
gsettings-tool.c
gsettings.c
gsettings.h
gsettingsbackend.c
gsettingsbackend.h
gsettingsbackendinternal.h
gsettingsschema-internal.h
gsettingsschema.c
gsettingsschema.h
gsimpleaction.c
gsimpleaction.h
gsimpleactiongroup.c
gsimpleactiongroup.h
gsimpleasyncresult.c
gsimpleasyncresult.h
gsimplepermission.c
gsimplepermission.h
gsocket.c
gsocket.h
gsocketaddress.c
gsocketaddress.h
gsocketaddressenumerator.c
gsocketaddressenumerator.h
gsocketclient.c
gsocketclient.h
gsocketconnectable.c
gsocketconnectable.h
gsocketconnection.c
gsocketconnection.h
gsocketcontrolmessage.c
gsocketcontrolmessage.h
gsocketinputstream.c
gsocketinputstream.h
gsocketlistener.c
gsocketlistener.h
gsocketoutputstream.c
gsocketoutputstream.h
gsocketservice.c
gsocketservice.h
gsocks4aproxy.c
gsocks4aproxy.h
gsocks4proxy.c
gsocks4proxy.h
gsocks5proxy.c
gsocks5proxy.h
gsrvtarget.c
gsrvtarget.h
gtask.c
gtask.h
gtcpconnection.c
gtcpconnection.h
gtcpwrapperconnection.c
gtcpwrapperconnection.h
gtestdbus.c
gtestdbus.h
gthemedicon.c
gthemedicon.h
gthreadedresolver.c
gthreadedresolver.h
gthreadedsocketservice.c
gthreadedsocketservice.h
gtlsbackend.c
gtlsbackend.h
gtlscertificate.c
gtlscertificate.h
gtlsclientconnection.c
gtlsclientconnection.h
gtlsconnection.c
gtlsconnection.h
gtlsdatabase.c
gtlsdatabase.h
gtlsfiledatabase.c
gtlsfiledatabase.h
gtlsinteraction.c
gtlsinteraction.h
gtlspassword.c
gtlspassword.h
gtlsserverconnection.c
gtlsserverconnection.h
gunionvolumemonitor.c
gunionvolumemonitor.h
gunixconnection.c
gunixconnection.h
gunixcredentialsmessage.c
gunixcredentialsmessage.h
gunixfdlist.c
gunixfdlist.h
gunixfdmessage.c
gunixfdmessage.h
gunixinputstream.c
gunixinputstream.h
gunixmount.c
gunixmount.h
gunixmounts.c
gunixmounts.h
gunixoutputstream.c
gunixoutputstream.h
gunixsocketaddress.c
gunixsocketaddress.h
gunixvolume.c
gunixvolume.h
gunixvolumemonitor.c
gunixvolumemonitor.h
gvfs.c
gvfs.h
gvolume.c
gvolume.h
gvolumemonitor.c
gvolumemonitor.h
gwin32appinfo.c
gwin32appinfo.h
gwin32inputstream.c
gwin32inputstream.h
gwin32mount.c
gwin32mount.h
gwin32outputstream.c
gwin32outputstream.h
gwin32volumemonitor.c
gwin32volumemonitor.h
gzlibcompressor.c
gzlibcompressor.h
gzlibdecompressor.c
gzlibdecompressor.h
makefile.msc
strinfo.c
glib
gmodule
gobject
gthread
m4macros
po
tests
.dir-locals.el
.gitignore
AUTHORS
COPYING
ChangeLog.pre-1-2
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-14
ChangeLog.pre-2-16
ChangeLog.pre-2-18
ChangeLog.pre-2-2
ChangeLog.pre-2-20
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
HACKING
INSTALL.in
Makefile.am
Makefile.decl
NEWS
NEWS.pre-1-3
README.commits
README.in
README.win32
acglib.m4
acinclude.m4
autogen.sh
config.h.win32.in
configure.ac
gio-2.0.pc.in
gio-unix-2.0.pc.in
gio-windows-2.0.pc.in
glib-2.0.pc.in
glib-gettextize.in
glib-zip.in
glib.doap
gmodule-2.0.pc.in
gmodule-export-2.0.pc.in
gmodule-no-export-2.0.pc.in
gobject-2.0.pc.in
gthread-2.0.pc.in
makefile.msc
mkinstalldirs
msvc_recommended_pragmas.h
sanity_check
win32-fixup.pl
351 lines
10 KiB
C
351 lines
10 KiB
C
|
|
/* GIO - GLib Input, Output and Streaming Library
|
||
|
|
*
|
||
|
|
* Copyright (C) 2010 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.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include "config.h"
|
||
|
|
|
||
|
|
#include <errno.h>
|
||
|
|
|
||
|
|
#include "gpollableinputstream.h"
|
||
|
|
#include "gasynchelper.h"
|
||
|
|
#include "glibintl.h"
|
||
|
|
|
||
|
|
/**
|
||
|
|
* SECTION:gpollableutils
|
||
|
|
* @short_description: #GPollableInputStream / #GPollableOutputStream utilities
|
||
|
|
* @include: gio/gio.h
|
||
|
|
*
|
||
|
|
* Utility functions for #GPollableInputStream and
|
||
|
|
* #GPollableOutputStream implementations.
|
||
|
|
*/
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
GSource source;
|
||
|
|
|
||
|
|
GObject *stream;
|
||
|
|
} GPollableSource;
|
||
|
|
|
||
|
|
static gboolean
|
||
|
|
pollable_source_prepare (GSource *source,
|
||
|
|
gint *timeout)
|
||
|
|
{
|
||
|
|
*timeout = -1;
|
||
|
|
return FALSE;
|
||
|
|
}
|
||
|
|
|
||
|
|
static gboolean
|
||
|
|
pollable_source_check (GSource *source)
|
||
|
|
{
|
||
|
|
return FALSE;
|
||
|
|
}
|
||
|
|
|
||
|
|
static gboolean
|
||
|
|
pollable_source_dispatch (GSource *source,
|
||
|
|
GSourceFunc callback,
|
||
|
|
gpointer user_data)
|
||
|
|
{
|
||
|
|
GPollableSourceFunc func = (GPollableSourceFunc)callback;
|
||
|
|
GPollableSource *pollable_source = (GPollableSource *)source;
|
||
|
|
|
||
|
|
return (*func) (pollable_source->stream, user_data);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void
|
||
|
|
pollable_source_finalize (GSource *source)
|
||
|
|
{
|
||
|
|
GPollableSource *pollable_source = (GPollableSource *)source;
|
||
|
|
|
||
|
|
g_object_unref (pollable_source->stream);
|
||
|
|
}
|
||
|
|
|
||
|
|
static gboolean
|
||
|
|
pollable_source_closure_callback (GObject *stream,
|
||
|
|
gpointer data)
|
||
|
|
{
|
||
|
|
GClosure *closure = data;
|
||
|
|
|
||
|
|
GValue param = G_VALUE_INIT;
|
||
|
|
GValue result_value = G_VALUE_INIT;
|
||
|
|
gboolean result;
|
||
|
|
|
||
|
|
g_value_init (&result_value, G_TYPE_BOOLEAN);
|
||
|
|
|
||
|
|
g_value_init (¶m, G_TYPE_OBJECT);
|
||
|
|
g_value_set_object (¶m, stream);
|
||
|
|
|
||
|
|
g_closure_invoke (closure, &result_value, 1, ¶m, NULL);
|
||
|
|
|
||
|
|
result = g_value_get_boolean (&result_value);
|
||
|
|
g_value_unset (&result_value);
|
||
|
|
g_value_unset (¶m);
|
||
|
|
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
static GSourceFuncs pollable_source_funcs =
|
||
|
|
{
|
||
|
|
pollable_source_prepare,
|
||
|
|
pollable_source_check,
|
||
|
|
pollable_source_dispatch,
|
||
|
|
pollable_source_finalize,
|
||
|
|
(GSourceFunc)pollable_source_closure_callback,
|
||
|
|
(GSourceDummyMarshal)g_cclosure_marshal_generic,
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* g_pollable_source_new:
|
||
|
|
* @pollable_stream: the stream associated with the new source
|
||
|
|
*
|
||
|
|
* Utility method for #GPollableInputStream and #GPollableOutputStream
|
||
|
|
* implementations. Creates a new #GSource that expects a callback of
|
||
|
|
* type #GPollableSourceFunc. The new source does not actually do
|
||
|
|
* anything on its own; use g_source_add_child_source() to add other
|
||
|
|
* sources to it to cause it to trigger.
|
||
|
|
*
|
||
|
|
* Return value: (transfer full): the new #GSource.
|
||
|
|
*
|
||
|
|
* Since: 2.28
|
||
|
|
*/
|
||
|
|
GSource *
|
||
|
|
g_pollable_source_new (GObject *pollable_stream)
|
||
|
|
{
|
||
|
|
GSource *source;
|
||
|
|
GPollableSource *pollable_source;
|
||
|
|
|
||
|
|
g_return_val_if_fail (G_IS_POLLABLE_INPUT_STREAM (pollable_stream) ||
|
||
|
|
G_IS_POLLABLE_OUTPUT_STREAM (pollable_stream), NULL);
|
||
|
|
|
||
|
|
source = g_source_new (&pollable_source_funcs, sizeof (GPollableSource));
|
||
|
|
g_source_set_name (source, "GPollableSource");
|
||
|
|
pollable_source = (GPollableSource *)source;
|
||
|
|
pollable_source->stream = g_object_ref (pollable_stream);
|
||
|
|
|
||
|
|
return source;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* g_pollable_source_new_full:
|
||
|
|
* @pollable_stream: (type GObject): the stream associated with the
|
||
|
|
* new source
|
||
|
|
* @child_source: (allow-none): optional child source to attach
|
||
|
|
* @cancellable: (allow-none): optional #GCancellable to attach
|
||
|
|
*
|
||
|
|
* Utility method for #GPollableInputStream and #GPollableOutputStream
|
||
|
|
* implementations. Creates a new #GSource, as with
|
||
|
|
* g_pollable_source_new(), but also attaching @child_source (with a
|
||
|
|
* dummy callback), and @cancellable, if they are non-%NULL.
|
||
|
|
*
|
||
|
|
* Return value: (transfer full): the new #GSource.
|
||
|
|
*
|
||
|
|
* Since: 2.34
|
||
|
|
*/
|
||
|
|
GSource *
|
||
|
|
g_pollable_source_new_full (gpointer pollable_stream,
|
||
|
|
GSource *child_source,
|
||
|
|
GCancellable *cancellable)
|
||
|
|
{
|
||
|
|
GSource *source;
|
||
|
|
|
||
|
|
g_return_val_if_fail (G_IS_POLLABLE_INPUT_STREAM (pollable_stream) ||
|
||
|
|
G_IS_POLLABLE_OUTPUT_STREAM (pollable_stream), NULL);
|
||
|
|
|
||
|
|
source = g_pollable_source_new (pollable_stream);
|
||
|
|
if (child_source)
|
||
|
|
{
|
||
|
|
g_source_set_dummy_callback (child_source);
|
||
|
|
g_source_add_child_source (source, child_source);
|
||
|
|
}
|
||
|
|
if (cancellable)
|
||
|
|
{
|
||
|
|
GSource *cancellable_source = g_cancellable_source_new (cancellable);
|
||
|
|
|
||
|
|
g_source_set_dummy_callback (cancellable_source);
|
||
|
|
g_source_add_child_source (source, cancellable_source);
|
||
|
|
g_source_unref (cancellable_source);
|
||
|
|
}
|
||
|
|
|
||
|
|
return source;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* g_pollable_stream_read:
|
||
|
|
* @stream: a #GInputStream
|
||
|
|
* @buffer: a buffer to read data into
|
||
|
|
* @count: the number of bytes to read
|
||
|
|
* @blocking: whether to do blocking I/O
|
||
|
|
* @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
|
||
|
|
* @error: location to store the error occurring, or %NULL to ignore
|
||
|
|
*
|
||
|
|
* Tries to read from @stream, as with g_input_stream_read() (if
|
||
|
|
* @blocking is %TRUE) or g_pollable_input_stream_read_nonblocking()
|
||
|
|
* (if @blocking is %FALSE). This can be used to more easily share
|
||
|
|
* code between blocking and non-blocking implementations of a method.
|
||
|
|
*
|
||
|
|
* If @blocking is %FALSE, then @stream must be a
|
||
|
|
* #GPollableInputStream for which g_pollable_input_stream_can_poll()
|
||
|
|
* returns %TRUE, or else the behavior is undefined. If @blocking is
|
||
|
|
* %TRUE, then @stream does not need to be a #GPollableInputStream.
|
||
|
|
*
|
||
|
|
* Returns: the number of bytes read, or -1 on error.
|
||
|
|
*
|
||
|
|
* Since: 2.34
|
||
|
|
*/
|
||
|
|
gssize
|
||
|
|
g_pollable_stream_read (GInputStream *stream,
|
||
|
|
void *buffer,
|
||
|
|
gsize count,
|
||
|
|
gboolean blocking,
|
||
|
|
GCancellable *cancellable,
|
||
|
|
GError **error)
|
||
|
|
{
|
||
|
|
if (blocking)
|
||
|
|
{
|
||
|
|
return g_input_stream_read (stream,
|
||
|
|
buffer, count,
|
||
|
|
cancellable, error);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
return g_pollable_input_stream_read_nonblocking (G_POLLABLE_INPUT_STREAM (stream),
|
||
|
|
buffer, count,
|
||
|
|
cancellable, error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* g_pollable_stream_write:
|
||
|
|
* @stream: a #GOutputStream.
|
||
|
|
* @buffer: (array length=count) (element-type guint8): the buffer
|
||
|
|
* containing the data to write.
|
||
|
|
* @count: the number of bytes to write
|
||
|
|
* @blocking: whether to do blocking I/O
|
||
|
|
* @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
|
||
|
|
* @error: location to store the error occurring, or %NULL to ignore
|
||
|
|
*
|
||
|
|
* Tries to write to @stream, as with g_output_stream_write() (if
|
||
|
|
* @blocking is %TRUE) or g_pollable_output_stream_write_nonblocking()
|
||
|
|
* (if @blocking is %FALSE). This can be used to more easily share
|
||
|
|
* code between blocking and non-blocking implementations of a method.
|
||
|
|
*
|
||
|
|
* If @blocking is %FALSE, then @stream must be a
|
||
|
|
* #GPollableOutputStream for which
|
||
|
|
* g_pollable_output_stream_can_poll() returns %TRUE or else the
|
||
|
|
* behavior is undefined. If @blocking is %TRUE, then @stream does not
|
||
|
|
* need to be a #GPollableOutputStream.
|
||
|
|
*
|
||
|
|
* Returns: the number of bytes written, or -1 on error.
|
||
|
|
*
|
||
|
|
* Since: 2.34
|
||
|
|
*/
|
||
|
|
gssize
|
||
|
|
g_pollable_stream_write (GOutputStream *stream,
|
||
|
|
const void *buffer,
|
||
|
|
gsize count,
|
||
|
|
gboolean blocking,
|
||
|
|
GCancellable *cancellable,
|
||
|
|
GError **error)
|
||
|
|
{
|
||
|
|
if (blocking)
|
||
|
|
{
|
||
|
|
return g_output_stream_write (stream,
|
||
|
|
buffer, count,
|
||
|
|
cancellable, error);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
return g_pollable_output_stream_write_nonblocking (G_POLLABLE_OUTPUT_STREAM (stream),
|
||
|
|
buffer, count,
|
||
|
|
cancellable, error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* g_pollable_stream_write_all:
|
||
|
|
* @stream: a #GOutputStream.
|
||
|
|
* @buffer: (array length=count) (element-type guint8): the buffer
|
||
|
|
* containing the data to write.
|
||
|
|
* @count: the number of bytes to write
|
||
|
|
* @blocking: whether to do blocking I/O
|
||
|
|
* @bytes_written: (out): location to store the number of bytes that was
|
||
|
|
* written to the stream
|
||
|
|
* @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
|
||
|
|
* @error: location to store the error occurring, or %NULL to ignore
|
||
|
|
*
|
||
|
|
* Tries to write @count bytes to @stream, as with
|
||
|
|
* g_output_stream_write_all(), but using g_pollable_stream_write()
|
||
|
|
* rather than g_output_stream_write().
|
||
|
|
*
|
||
|
|
* On a successful write of @count bytes, %TRUE is returned, and
|
||
|
|
* @bytes_written is set to @count.
|
||
|
|
*
|
||
|
|
* If there is an error during the operation (including
|
||
|
|
* %G_IO_ERROR_WOULD_BLOCK in the non-blocking case), %FALSE is
|
||
|
|
* returned and @error is set to indicate the error status,
|
||
|
|
* @bytes_written is updated to contain the number of bytes written
|
||
|
|
* into the stream before the error occurred.
|
||
|
|
*
|
||
|
|
* As with g_pollable_stream_write(), if @blocking is %FALSE, then
|
||
|
|
* @stream must be a #GPollableOutputStream for which
|
||
|
|
* g_pollable_output_stream_can_poll() returns %TRUE or else the
|
||
|
|
* behavior is undefined. If @blocking is %TRUE, then @stream does not
|
||
|
|
* need to be a #GPollableOutputStream.
|
||
|
|
*
|
||
|
|
* Return value: %TRUE on success, %FALSE if there was an error
|
||
|
|
*
|
||
|
|
* Since: 2.34
|
||
|
|
*/
|
||
|
|
gboolean
|
||
|
|
g_pollable_stream_write_all (GOutputStream *stream,
|
||
|
|
const void *buffer,
|
||
|
|
gsize count,
|
||
|
|
gboolean blocking,
|
||
|
|
gsize *bytes_written,
|
||
|
|
GCancellable *cancellable,
|
||
|
|
GError **error)
|
||
|
|
{
|
||
|
|
gsize _bytes_written;
|
||
|
|
gssize res;
|
||
|
|
|
||
|
|
_bytes_written = 0;
|
||
|
|
while (_bytes_written < count)
|
||
|
|
{
|
||
|
|
res = g_pollable_stream_write (stream,
|
||
|
|
(char *)buffer + _bytes_written,
|
||
|
|
count - _bytes_written,
|
||
|
|
blocking,
|
||
|
|
cancellable, error);
|
||
|
|
if (res == -1)
|
||
|
|
{
|
||
|
|
if (bytes_written)
|
||
|
|
*bytes_written = _bytes_written;
|
||
|
|
return FALSE;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (res == 0)
|
||
|
|
g_warning ("Write returned zero without error");
|
||
|
|
|
||
|
|
_bytes_written += res;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (bytes_written)
|
||
|
|
*bytes_written = _bytes_written;
|
||
|
|
|
||
|
|
return TRUE;
|
||
|
|
}
|