Trivial cleanups

This commit is contained in:
Matthias Clasen 2010-07-05 07:40:38 -04:00
parent 48881bad99
commit 1ba87d1a0e

View File

@ -53,9 +53,7 @@
* buffered input stream's buffer, use * buffered input stream's buffer, use
* g_buffered_input_stream_set_buffer_size(). Note that the buffer's size * g_buffered_input_stream_set_buffer_size(). Note that the buffer's size
* cannot be reduced below the size of the data within the buffer. * cannot be reduced below the size of the data within the buffer.
* */
**/
#define DEFAULT_BUFFER_SIZE 4096 #define DEFAULT_BUFFER_SIZE 4096
@ -86,46 +84,46 @@ static void g_buffered_input_stream_finalize (GObject *object);
static gssize g_buffered_input_stream_skip (GInputStream *stream, static gssize g_buffered_input_stream_skip (GInputStream *stream,
gsize count, gsize count,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
static void g_buffered_input_stream_skip_async (GInputStream *stream, static void g_buffered_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 user_data); gpointer user_data);
static gssize g_buffered_input_stream_skip_finish (GInputStream *stream, static gssize g_buffered_input_stream_skip_finish (GInputStream *stream,
GAsyncResult *result, GAsyncResult *result,
GError **error); GError **error);
static gssize g_buffered_input_stream_read (GInputStream *stream, static gssize g_buffered_input_stream_read (GInputStream *stream,
void *buffer, void *buffer,
gsize count, gsize count,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
static void g_buffered_input_stream_read_async (GInputStream *stream, static void g_buffered_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 user_data); gpointer user_data);
static gssize g_buffered_input_stream_read_finish (GInputStream *stream, static gssize g_buffered_input_stream_read_finish (GInputStream *stream,
GAsyncResult *result, GAsyncResult *result,
GError **error); GError **error);
static gssize g_buffered_input_stream_real_fill (GBufferedInputStream *stream, static gssize g_buffered_input_stream_real_fill (GBufferedInputStream *stream,
gssize count, gssize count,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
static void g_buffered_input_stream_real_fill_async (GBufferedInputStream *stream, static void g_buffered_input_stream_real_fill_async (GBufferedInputStream *stream,
gssize count, gssize count,
int io_priority, int io_priority,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
static gssize g_buffered_input_stream_real_fill_finish (GBufferedInputStream *stream, static gssize g_buffered_input_stream_real_fill_finish (GBufferedInputStream *stream,
GAsyncResult *result, GAsyncResult *result,
GError **error); GError **error);
static void compact_buffer (GBufferedInputStream *stream); static void compact_buffer (GBufferedInputStream *stream);
@ -177,12 +175,12 @@ g_buffered_input_stream_class_init (GBufferedInputStreamClass *klass)
/** /**
* g_buffered_input_stream_get_buffer_size: * g_buffered_input_stream_get_buffer_size:
* @stream: #GBufferedInputStream. * @stream: a #GBufferedInputStream
* *
* Gets the size of the input buffer. * Gets the size of the input buffer.
* *
* Returns: the current buffer size. * Returns: the current buffer size.
**/ */
gsize gsize
g_buffered_input_stream_get_buffer_size (GBufferedInputStream *stream) g_buffered_input_stream_get_buffer_size (GBufferedInputStream *stream)
{ {
@ -193,16 +191,16 @@ g_buffered_input_stream_get_buffer_size (GBufferedInputStream *stream)
/** /**
* g_buffered_input_stream_set_buffer_size: * g_buffered_input_stream_set_buffer_size:
* @stream: #GBufferedInputStream. * @stream: a #GBufferedInputStream
* @size: a #gsize. * @size: a #gsize
* *
* Sets the size of the internal buffer of @stream to @size, or to the * Sets the size of the internal buffer of @stream to @size, or to the
* size of the contents of the buffer. The buffer can never be resized * size of the contents of the buffer. The buffer can never be resized
* smaller than its current contents. * smaller than its current contents.
**/ */
void void
g_buffered_input_stream_set_buffer_size (GBufferedInputStream *stream, g_buffered_input_stream_set_buffer_size (GBufferedInputStream *stream,
gsize size) gsize size)
{ {
GBufferedInputStreamPrivate *priv; GBufferedInputStreamPrivate *priv;
gsize in_buffer; gsize in_buffer;
@ -261,7 +259,6 @@ g_buffered_input_stream_set_property (GObject *object,
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
} }
} }
static void static void
@ -313,13 +310,13 @@ g_buffered_input_stream_init (GBufferedInputStream *stream)
/** /**
* g_buffered_input_stream_new: * g_buffered_input_stream_new:
* @base_stream: a #GInputStream. * @base_stream: a #GInputStream
* *
* Creates a new #GInputStream from the given @base_stream, with * Creates a new #GInputStream from the given @base_stream, with
* a buffer set to the default size (4 kilobytes). * a buffer set to the default size (4 kilobytes).
* *
* Returns: a #GInputStream for the given @base_stream. * Returns: a #GInputStream for the given @base_stream.
**/ */
GInputStream * GInputStream *
g_buffered_input_stream_new (GInputStream *base_stream) g_buffered_input_stream_new (GInputStream *base_stream)
{ {
@ -336,14 +333,14 @@ g_buffered_input_stream_new (GInputStream *base_stream)
/** /**
* g_buffered_input_stream_new_sized: * g_buffered_input_stream_new_sized:
* @base_stream: a #GInputStream. * @base_stream: a #GInputStream
* @size: a #gsize. * @size: a #gsize
* *
* Creates a new #GBufferedInputStream from the given @base_stream, * Creates a new #GBufferedInputStream from the given @base_stream,
* with a buffer set to @size. * with a buffer set to @size.
* *
* Returns: a #GInputStream. * Returns: a #GInputStream.
**/ */
GInputStream * GInputStream *
g_buffered_input_stream_new_sized (GInputStream *base_stream, g_buffered_input_stream_new_sized (GInputStream *base_stream,
gsize size) gsize size)
@ -362,10 +359,10 @@ g_buffered_input_stream_new_sized (GInputStream *base_stream,
/** /**
* g_buffered_input_stream_fill: * g_buffered_input_stream_fill:
* @stream: #GBufferedInputStream. * @stream: a #GBufferedInputStream
* @count: the number of bytes that will be read from the stream. * @count: the number of bytes that will be read from the stream
* @cancellable: optional #GCancellable object, %NULL to ignore. * @cancellable: optional #GCancellable object, %NULL to ignore
* @error: location to store the error occuring, or %NULL to ignore. * @error: location to store the error occuring, or %NULL to ignore
* *
* Tries to read @count bytes from the stream into the buffer. * Tries to read @count bytes from the stream into the buffer.
* Will block during this read. * Will block during this read.
@ -394,7 +391,7 @@ g_buffered_input_stream_new_sized (GInputStream *base_stream,
* *
* Returns: the number of bytes read into @stream's buffer, up to @count, * Returns: the number of bytes read into @stream's buffer, up to @count,
* or -1 on error. * or -1 on error.
**/ */
gssize gssize
g_buffered_input_stream_fill (GBufferedInputStream *stream, g_buffered_input_stream_fill (GBufferedInputStream *stream,
gssize count, gssize count,
@ -447,13 +444,13 @@ async_fill_callback_wrapper (GObject *source_object,
/** /**
* g_buffered_input_stream_fill_async: * g_buffered_input_stream_fill_async:
* @stream: #GBufferedInputStream. * @stream: a #GBufferedInputStream
* @count: the number of bytes that will be read from the stream. * @count: the number of bytes that will be read from the stream
* @io_priority: the <link linkend="io-priority">I/O priority</link> * @io_priority: the <link linkend="io-priority">I/O priority</link>
* of the request. * of the request
* @cancellable: optional #GCancellable object * @cancellable: optional #GCancellable object
* @callback: a #GAsyncReadyCallback. * @callback: a #GAsyncReadyCallback
* @user_data: a #gpointer. * @user_data: a #gpointer
* *
* Reads data into @stream's buffer asynchronously, up to @count size. * Reads data into @stream's buffer asynchronously, up to @count size.
* @io_priority can be used to prioritize reads. For the synchronous * @io_priority can be used to prioritize reads. For the synchronous
@ -461,7 +458,7 @@ async_fill_callback_wrapper (GObject *source_object,
* *
* If @count is -1 then the attempted read size is equal to the number * If @count is -1 then the attempted read size is equal to the number
* of bytes that are required to fill the buffer. * of bytes that are required to fill the buffer.
**/ */
void void
g_buffered_input_stream_fill_async (GBufferedInputStream *stream, g_buffered_input_stream_fill_async (GBufferedInputStream *stream,
gssize count, gssize count,
@ -479,9 +476,9 @@ g_buffered_input_stream_fill_async (GBufferedInputStream *stream,
if (count == 0) if (count == 0)
{ {
simple = g_simple_async_result_new (G_OBJECT (stream), simple = g_simple_async_result_new (G_OBJECT (stream),
callback, callback,
user_data, user_data,
g_buffered_input_stream_fill_async); g_buffered_input_stream_fill_async);
g_simple_async_result_complete_in_idle (simple); g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple); g_object_unref (simple);
return; return;
@ -490,20 +487,20 @@ g_buffered_input_stream_fill_async (GBufferedInputStream *stream,
if (count < -1) if (count < -1)
{ {
g_simple_async_report_error_in_idle (G_OBJECT (stream), g_simple_async_report_error_in_idle (G_OBJECT (stream),
callback, callback,
user_data, user_data,
G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
_("Too large count value passed to %s"), _("Too large count value passed to %s"),
G_STRFUNC); G_STRFUNC);
return; return;
} }
if (!g_input_stream_set_pending (G_INPUT_STREAM (stream), &error)) if (!g_input_stream_set_pending (G_INPUT_STREAM (stream), &error))
{ {
g_simple_async_report_gerror_in_idle (G_OBJECT (stream), g_simple_async_report_gerror_in_idle (G_OBJECT (stream),
callback, callback,
user_data, user_data,
error); error);
g_error_free (error); g_error_free (error);
return; return;
} }
@ -518,14 +515,14 @@ g_buffered_input_stream_fill_async (GBufferedInputStream *stream,
/** /**
* g_buffered_input_stream_fill_finish: * g_buffered_input_stream_fill_finish:
* @stream: a #GBufferedInputStream. * @stream: a #GBufferedInputStream
* @result: a #GAsyncResult. * @result: a #GAsyncResult
* @error: a #GError. * @error: a #GError
* *
* Finishes an asynchronous read. * Finishes an asynchronous read.
* *
* Returns: a #gssize of the read stream, or %-1 on an error. * Returns: a #gssize of the read stream, or %-1 on an error.
**/ */
gssize gssize
g_buffered_input_stream_fill_finish (GBufferedInputStream *stream, g_buffered_input_stream_fill_finish (GBufferedInputStream *stream,
GAsyncResult *result, GAsyncResult *result,
@ -554,12 +551,12 @@ g_buffered_input_stream_fill_finish (GBufferedInputStream *stream,
/** /**
* g_buffered_input_stream_get_available: * g_buffered_input_stream_get_available:
* @stream: #GBufferedInputStream. * @stream: #GBufferedInputStream
* *
* Gets the size of the available data within the stream. * Gets the size of the available data within the stream.
* *
* Returns: size of the available stream. * Returns: size of the available stream.
**/ */
gsize gsize
g_buffered_input_stream_get_available (GBufferedInputStream *stream) g_buffered_input_stream_get_available (GBufferedInputStream *stream)
{ {
@ -570,16 +567,16 @@ g_buffered_input_stream_get_available (GBufferedInputStream *stream)
/** /**
* g_buffered_input_stream_peek: * g_buffered_input_stream_peek:
* @stream: a #GBufferedInputStream. * @stream: a #GBufferedInputStream
* @buffer: a pointer to an allocated chunk of memory. * @buffer: a pointer to an allocated chunk of memory
* @offset: a #gsize. * @offset: a #gsize
* @count: a #gsize. * @count: a #gsize
* *
* Peeks in the buffer, copying data of size @count into @buffer, * Peeks in the buffer, copying data of size @count into @buffer,
* offset @offset bytes. * offset @offset bytes.
* *
* Returns: a #gsize of the number of bytes peeked, or %-1 on error. * Returns: a #gsize of the number of bytes peeked, or -1 on error.
**/ */
gsize gsize
g_buffered_input_stream_peek (GBufferedInputStream *stream, g_buffered_input_stream_peek (GBufferedInputStream *stream,
void *buffer, void *buffer,
@ -606,15 +603,15 @@ g_buffered_input_stream_peek (GBufferedInputStream *stream,
/** /**
* g_buffered_input_stream_peek_buffer: * g_buffered_input_stream_peek_buffer:
* @stream: a #GBufferedInputStream. * @stream: a #GBufferedInputStream
* @count: a #gsize to get the number of bytes available in the buffer. * @count: a #gsize to get the number of bytes available in the buffer
* *
* Returns the buffer with the currently available bytes. The returned * Returns the buffer with the currently available bytes. The returned
* buffer must not be modified and will become invalid when reading from * buffer must not be modified and will become invalid when reading from
* the stream or filling the buffer. * the stream or filling the buffer.
* *
* Returns: read-only buffer * Returns: read-only buffer
**/ */
const void* const void*
g_buffered_input_stream_peek_buffer (GBufferedInputStream *stream, g_buffered_input_stream_peek_buffer (GBufferedInputStream *stream,
gsize *count) gsize *count)
@ -787,7 +784,9 @@ g_buffered_input_stream_read (GInputStream *stream,
return count; return count;
} }
/* Full request not available, read all currently availbile and request refill for more */ /* Full request not available, read all currently available and
* request refill for more
*/
memcpy (buffer, priv->buffer + priv->pos, available); memcpy (buffer, priv->buffer + priv->pos, available);
priv->pos = 0; priv->pos = 0;
@ -805,10 +804,10 @@ g_buffered_input_stream_read (GInputStream *stream,
base_stream = G_FILTER_INPUT_STREAM (stream)->base_stream; base_stream = G_FILTER_INPUT_STREAM (stream)->base_stream;
nread = g_input_stream_read (base_stream, nread = g_input_stream_read (base_stream,
(char *)buffer + bytes_read, (char *)buffer + bytes_read,
count, count,
cancellable, cancellable,
error); error);
if (nread < 0 && bytes_read == 0) if (nread < 0 && bytes_read == 0)
return -1; return -1;
@ -841,9 +840,9 @@ g_buffered_input_stream_read (GInputStream *stream,
/** /**
* g_buffered_input_stream_read_byte: * g_buffered_input_stream_read_byte:
* @stream: #GBufferedInputStream. * @stream: a #GBufferedInputStream
* @cancellable: optional #GCancellable object, %NULL to ignore. * @cancellable: optional #GCancellable object, %NULL to ignore
* @error: location to store the error occuring, or %NULL to ignore. * @error: location to store the error occuring, or %NULL to ignore
* *
* Tries to read a single byte from the stream or the buffer. Will block * Tries to read a single byte from the stream or the buffer. Will block
* during this read. * during this read.
@ -860,7 +859,7 @@ g_buffered_input_stream_read (GInputStream *stream,
* On error -1 is returned and @error is set accordingly. * On error -1 is returned and @error is set accordingly.
* *
* Returns: the byte read from the @stream, or -1 on end of stream or error. * Returns: the byte read from the @stream, or -1 on end of stream or error.
**/ */
int int
g_buffered_input_stream_read_byte (GBufferedInputStream *stream, g_buffered_input_stream_read_byte (GBufferedInputStream *stream,
GCancellable *cancellable, GCancellable *cancellable,
@ -934,7 +933,7 @@ fill_async_callback (GObject *source_object,
error = NULL; error = NULL;
res = g_input_stream_read_finish (G_INPUT_STREAM (source_object), res = g_input_stream_read_finish (G_INPUT_STREAM (source_object),
result, &error); result, &error);
g_simple_async_result_set_op_res_gssize (simple, res); g_simple_async_result_set_op_res_gssize (simple, res);
if (res == -1) if (res == -1)
@ -956,7 +955,9 @@ fill_async_callback (GObject *source_object,
g_object_unref (object); g_object_unref (object);
} }
/* Complete immediately, not in idle, since we're already in a mainloop callout */ /* Complete immediately, not in idle, since we're already
* in a mainloop callout
*/
g_simple_async_result_complete (simple); g_simple_async_result_complete (simple);
g_object_unref (simple); g_object_unref (simple);
} }
@ -989,23 +990,23 @@ g_buffered_input_stream_real_fill_async (GBufferedInputStream *stream,
compact_buffer (stream); compact_buffer (stream);
simple = g_simple_async_result_new (G_OBJECT (stream), simple = g_simple_async_result_new (G_OBJECT (stream),
callback, user_data, callback, user_data,
g_buffered_input_stream_real_fill_async); g_buffered_input_stream_real_fill_async);
base_stream = G_FILTER_INPUT_STREAM (stream)->base_stream; base_stream = G_FILTER_INPUT_STREAM (stream)->base_stream;
g_input_stream_read_async (base_stream, g_input_stream_read_async (base_stream,
priv->buffer + priv->end, priv->buffer + priv->end,
count, count,
io_priority, io_priority,
cancellable, cancellable,
fill_async_callback, fill_async_callback,
simple); simple);
} }
static gssize static gssize
g_buffered_input_stream_real_fill_finish (GBufferedInputStream *stream, g_buffered_input_stream_real_fill_finish (GBufferedInputStream *stream,
GAsyncResult *result, GAsyncResult *result,
GError **error) GError **error)
{ {
GSimpleAsyncResult *simple; GSimpleAsyncResult *simple;
gssize nread; gssize nread;
@ -1017,7 +1018,8 @@ g_buffered_input_stream_real_fill_finish (GBufferedInputStream *stream,
return nread; return nread;
} }
typedef struct { typedef struct
{
gssize bytes_read; gssize bytes_read;
gssize count; gssize count;
void *buffer; void *buffer;
@ -1032,8 +1034,8 @@ free_read_async_data (gpointer _data)
static void static void
large_read_callback (GObject *source_object, large_read_callback (GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
ReadAsyncData *data; ReadAsyncData *data;
@ -1044,7 +1046,7 @@ large_read_callback (GObject *source_object,
error = NULL; error = NULL;
nread = g_input_stream_read_finish (G_INPUT_STREAM (source_object), nread = g_input_stream_read_finish (G_INPUT_STREAM (source_object),
result, &error); result, &error);
/* Only report the error if we've not already read some data */ /* Only report the error if we've not already read some data */
if (nread < 0 && data->bytes_read == 0) if (nread < 0 && data->bytes_read == 0)
@ -1056,15 +1058,17 @@ large_read_callback (GObject *source_object,
if (error) if (error)
g_error_free (error); g_error_free (error);
/* Complete immediately, not in idle, since we're already in a mainloop callout */ /* Complete immediately, not in idle, since we're already
* in a mainloop callout
*/
g_simple_async_result_complete (simple); g_simple_async_result_complete (simple);
g_object_unref (simple); g_object_unref (simple);
} }
static void static void
read_fill_buffer_callback (GObject *source_object, read_fill_buffer_callback (GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
GBufferedInputStream *bstream; GBufferedInputStream *bstream;
@ -1081,7 +1085,7 @@ read_fill_buffer_callback (GObject *source_object,
error = NULL; error = NULL;
nread = g_buffered_input_stream_fill_finish (bstream, nread = g_buffered_input_stream_fill_finish (bstream,
result, &error); result, &error);
if (nread < 0 && data->bytes_read == 0) if (nread < 0 && data->bytes_read == 0)
g_simple_async_result_set_from_error (simple, error); g_simple_async_result_set_from_error (simple, error);
@ -1100,19 +1104,21 @@ read_fill_buffer_callback (GObject *source_object,
if (error) if (error)
g_error_free (error); g_error_free (error);
/* Complete immediately, not in idle, since we're already in a mainloop callout */ /* Complete immediately, not in idle, since we're already
* in a mainloop callout
*/
g_simple_async_result_complete (simple); g_simple_async_result_complete (simple);
g_object_unref (simple); g_object_unref (simple);
} }
static void static void
g_buffered_input_stream_read_async (GInputStream *stream, g_buffered_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 user_data) gpointer user_data)
{ {
GBufferedInputStream *bstream; GBufferedInputStream *bstream;
GBufferedInputStreamPrivate *priv; GBufferedInputStreamPrivate *priv;
@ -1129,8 +1135,8 @@ g_buffered_input_stream_read_async (GInputStream *stream,
data->buffer = buffer; data->buffer = buffer;
data->bytes_read = 0; data->bytes_read = 0;
simple = g_simple_async_result_new (G_OBJECT (stream), simple = g_simple_async_result_new (G_OBJECT (stream),
callback, user_data, callback, user_data,
g_buffered_input_stream_read_async); g_buffered_input_stream_read_async);
g_simple_async_result_set_op_res_gpointer (simple, data, free_read_async_data); g_simple_async_result_set_op_res_gpointer (simple, data, free_read_async_data);
available = priv->end - priv->pos; available = priv->end - priv->pos;
@ -1147,7 +1153,9 @@ g_buffered_input_stream_read_async (GInputStream *stream,
} }
/* Full request not available, read all currently availbile and request refill for more */ /* Full request not available, read all currently available
* and request refill for more
*/
memcpy (buffer, priv->buffer + priv->pos, available); memcpy (buffer, priv->buffer + priv->pos, available);
priv->pos = 0; priv->pos = 0;
@ -1165,17 +1173,17 @@ g_buffered_input_stream_read_async (GInputStream *stream,
base_stream = G_FILTER_INPUT_STREAM (stream)->base_stream; base_stream = G_FILTER_INPUT_STREAM (stream)->base_stream;
g_input_stream_read_async (base_stream, g_input_stream_read_async (base_stream,
(char *)buffer + data->bytes_read, (char *)buffer + data->bytes_read,
count, count,
io_priority, cancellable, io_priority, cancellable,
large_read_callback, large_read_callback,
simple); simple);
} }
else else
{ {
class = G_BUFFERED_INPUT_STREAM_GET_CLASS (stream); class = G_BUFFERED_INPUT_STREAM_GET_CLASS (stream);
class->fill_async (bstream, priv->len, io_priority, cancellable, class->fill_async (bstream, priv->len, io_priority, cancellable,
read_fill_buffer_callback, simple); read_fill_buffer_callback, simple);
} }
} }
@ -1196,7 +1204,8 @@ g_buffered_input_stream_read_finish (GInputStream *stream,
return data->bytes_read; return data->bytes_read;
} }
typedef struct { typedef struct
{
gssize bytes_skipped; gssize bytes_skipped;
gssize count; gssize count;
} SkipAsyncData; } SkipAsyncData;
@ -1209,9 +1218,9 @@ free_skip_async_data (gpointer _data)
} }
static void static void
large_skip_callback (GObject *source_object, large_skip_callback (GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
SkipAsyncData *data; SkipAsyncData *data;
@ -1222,7 +1231,7 @@ large_skip_callback (GObject *source_object,
error = NULL; error = NULL;
nread = g_input_stream_skip_finish (G_INPUT_STREAM (source_object), nread = g_input_stream_skip_finish (G_INPUT_STREAM (source_object),
result, &error); result, &error);
/* Only report the error if we've not already read some data */ /* Only report the error if we've not already read some data */
if (nread < 0 && data->bytes_skipped == 0) if (nread < 0 && data->bytes_skipped == 0)
@ -1234,15 +1243,17 @@ large_skip_callback (GObject *source_object,
if (error) if (error)
g_error_free (error); g_error_free (error);
/* Complete immediately, not in idle, since we're already in a mainloop callout */ /* Complete immediately, not in idle, since we're already
* in a mainloop callout
*/
g_simple_async_result_complete (simple); g_simple_async_result_complete (simple);
g_object_unref (simple); g_object_unref (simple);
} }
static void static void
skip_fill_buffer_callback (GObject *source_object, skip_fill_buffer_callback (GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
GBufferedInputStream *bstream; GBufferedInputStream *bstream;
@ -1259,12 +1270,11 @@ skip_fill_buffer_callback (GObject *source_object,
error = NULL; error = NULL;
nread = g_buffered_input_stream_fill_finish (bstream, nread = g_buffered_input_stream_fill_finish (bstream,
result, &error); result, &error);
if (nread < 0 && data->bytes_skipped == 0) if (nread < 0 && data->bytes_skipped == 0)
g_simple_async_result_set_from_error (simple, error); g_simple_async_result_set_from_error (simple, error);
if (nread > 0) if (nread > 0)
{ {
available = priv->end - priv->pos; available = priv->end - priv->pos;
@ -1277,18 +1287,20 @@ skip_fill_buffer_callback (GObject *source_object,
if (error) if (error)
g_error_free (error); g_error_free (error);
/* Complete immediately, not in idle, since we're already in a mainloop callout */ /* Complete immediately, not in idle, since we're already
* in a mainloop callout
*/
g_simple_async_result_complete (simple); g_simple_async_result_complete (simple);
g_object_unref (simple); g_object_unref (simple);
} }
static void static void
g_buffered_input_stream_skip_async (GInputStream *stream, g_buffered_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 user_data) gpointer user_data)
{ {
GBufferedInputStream *bstream; GBufferedInputStream *bstream;
GBufferedInputStreamPrivate *priv; GBufferedInputStreamPrivate *priv;
@ -1304,8 +1316,8 @@ g_buffered_input_stream_skip_async (GInputStream *stream,
data = g_slice_new (SkipAsyncData); data = g_slice_new (SkipAsyncData);
data->bytes_skipped = 0; data->bytes_skipped = 0;
simple = g_simple_async_result_new (G_OBJECT (stream), simple = g_simple_async_result_new (G_OBJECT (stream),
callback, user_data, callback, user_data,
g_buffered_input_stream_skip_async); g_buffered_input_stream_skip_async);
g_simple_async_result_set_op_res_gpointer (simple, data, free_skip_async_data); g_simple_async_result_set_op_res_gpointer (simple, data, free_skip_async_data);
available = priv->end - priv->pos; available = priv->end - priv->pos;
@ -1320,8 +1332,9 @@ g_buffered_input_stream_skip_async (GInputStream *stream,
return; return;
} }
/* Full request not available, skip all currently available
/* Full request not available, skip all currently availbile and request refill for more */ * and request refill for more
*/
priv->pos = 0; priv->pos = 0;
priv->end = 0; priv->end = 0;
@ -1338,16 +1351,16 @@ g_buffered_input_stream_skip_async (GInputStream *stream,
base_stream = G_FILTER_INPUT_STREAM (stream)->base_stream; base_stream = G_FILTER_INPUT_STREAM (stream)->base_stream;
g_input_stream_skip_async (base_stream, g_input_stream_skip_async (base_stream,
count, count,
io_priority, cancellable, io_priority, cancellable,
large_skip_callback, large_skip_callback,
simple); simple);
} }
else else
{ {
class = G_BUFFERED_INPUT_STREAM_GET_CLASS (stream); class = G_BUFFERED_INPUT_STREAM_GET_CLASS (stream);
class->fill_async (bstream, priv->len, io_priority, cancellable, class->fill_async (bstream, priv->len, io_priority, cancellable,
skip_fill_buffer_callback, simple); skip_fill_buffer_callback, simple);
} }
} }