summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorPeter Keresztes Schmidt <carbenium@outlook.com>2019-07-31 15:27:42 +0200
committerPeter Keresztes Schmidt <carbenium@outlook.com>2019-08-08 13:57:42 +0200
commit3b1188ce04910e91c7cec8afed7a30a9ee052cd3 (patch)
tree929938e39986da2b412a347b8622551dbee5c4ac /client
parentb4047cdfe316d624e5cb1d83d165d25339775a72 (diff)
downloadgvfs-3b1188ce04910e91c7cec8afed7a30a9ee052cd3.tar.gz
fuse: cleanup {read,write}_stream functions
Remove unnecessary while loop since g_input_stream_read_all and g_output_stream_write_all guarantee that all data is read/written when exiting successfully.
Diffstat (limited to 'client')
-rw-r--r--client/gvfsfusedaemon.c74
1 files changed, 23 insertions, 51 deletions
diff --git a/client/gvfsfusedaemon.c b/client/gvfsfusedaemon.c
index b0be2f71..1ca6d121 100644
--- a/client/gvfsfusedaemon.c
+++ b/client/gvfsfusedaemon.c
@@ -1258,7 +1258,7 @@ read_stream (FileHandle *fh, gchar *output_buf, size_t output_buf_size, off_t of
{
GInputStream *input_stream;
gint n_bytes_skipped = 0;
- gint n_bytes_read = 0;
+ gsize n_bytes_read = 0;
gint result = 0;
GError *error = NULL;
@@ -1318,36 +1318,22 @@ read_stream (FileHandle *fh, gchar *output_buf, size_t output_buf_size, off_t of
if (result == 0)
{
- while (n_bytes_read < output_buf_size)
- {
- gboolean part_result;
- gsize part_bytes_read = 0;
-
- part_result = g_input_stream_read_all (input_stream,
- output_buf + n_bytes_read,
- output_buf_size - n_bytes_read,
- &part_bytes_read,
- NULL,
- &error);
-
- n_bytes_read += part_bytes_read;
- fh->pos += part_bytes_read;
-
- if (!part_result || part_bytes_read == 0)
- break;
- }
+ g_input_stream_read_all (input_stream,
+ output_buf,
+ output_buf_size,
+ &n_bytes_read,
+ NULL,
+ &error);
+ fh->pos += n_bytes_read;
result = n_bytes_read;
- if (n_bytes_read < output_buf_size)
+ if (error != NULL)
{
- g_debug ("read_stream: wanted %zd bytes, but got %d.\n", output_buf_size, n_bytes_read);
+ g_debug ("read_stream: wanted %zd bytes, but got %zd.\n", output_buf_size, n_bytes_read);
- if (error)
- {
- result = -errno_from_error (error);
- g_error_free (error);
- }
+ result = -errno_from_error (error);
+ g_error_free (error);
}
}
@@ -1413,7 +1399,7 @@ write_stream (FileHandle *fh,
off_t offset)
{
GOutputStream *output_stream;
- gint n_bytes_written = 0;
+ gsize n_bytes_written = 0;
gint result = 0;
GError *error = NULL;
@@ -1447,34 +1433,20 @@ write_stream (FileHandle *fh,
if (result == 0)
{
- while (n_bytes_written < input_buf_size)
- {
- gboolean part_result;
- gsize part_bytes_written = 0;
-
- part_result = g_output_stream_write_all (output_stream,
- (void *) (input_buf + n_bytes_written),
- input_buf_size - n_bytes_written,
- &part_bytes_written,
- NULL,
- &error);
-
- n_bytes_written += part_bytes_written;
- fh->pos += part_bytes_written;
-
- if (!part_result)
- break;
- }
+ g_output_stream_write_all (output_stream,
+ input_buf,
+ input_buf_size,
+ &n_bytes_written,
+ NULL,
+ &error);
+ fh->pos += n_bytes_written;
result = n_bytes_written;
- if (n_bytes_written < input_buf_size)
+ if (error)
{
- if (error)
- {
- result = -errno_from_error (error);
- g_error_free (error);
- }
+ result = -errno_from_error (error);
+ g_error_free (error);
}
else if (!g_output_stream_flush (output_stream, NULL, &error))
{