[evolution-data-server] Bug 737733 - [IMAPx] Prevent "Stream has outstanding operation" error
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug 737733 - [IMAPx] Prevent "Stream has outstanding operation" error
- Date: Fri, 17 Oct 2014 12:18:46 +0000 (UTC)
commit 783623dc46d9ef1f0867f75a3ca4c16614f1ea39
Author: Milan Crha <mcrha redhat com>
Date: Fri Oct 17 14:15:42 2014 +0200
Bug 737733 - [IMAPx] Prevent "Stream has outstanding operation" error
...by guarding writes to output streams with a lock, to not write
to the same stream in multiple threads at once.
camel/providers/imapx/camel-imapx-server.c | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index d77bd86..4e33498 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -1272,9 +1272,11 @@ imapx_command_start (CamelIMAPXServer *is,
string = g_strdup_printf (
"%c%05u %s\r\n", is->tagprefix, ic->tag, cp->data);
+ g_mutex_lock (&is->priv->stream_lock);
g_output_stream_write_all (
output_stream, string, strlen (string),
NULL, cancellable, &local_error);
+ g_mutex_unlock (&is->priv->stream_lock);
g_free (string);
if (local_error != NULL)
@@ -2189,14 +2191,17 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
size than it actually is, which results in no data being read from
the server for that particular offset. */
if (body_size) {
+ g_mutex_lock (&is->priv->stream_lock);
if (!g_output_stream_write_all (
output_stream, body_data, body_size,
NULL, cancellable, error)) {
+ g_mutex_unlock (&is->priv->stream_lock);
g_prefix_error (
error, "%s: ",
_("Error writing to cache stream"));
return FALSE;
}
+ g_mutex_unlock (&is->priv->stream_lock);
}
}
}
@@ -3138,9 +3143,11 @@ imapx_continuation (CamelIMAPXServer *is,
return FALSE;
c (is->tagprefix, "got auth continuation, feeding token '%s' back to auth mech\n", resp);
+ g_mutex_lock (&is->priv->stream_lock);
n_bytes_written = g_output_stream_write_all (
output_stream, resp, strlen (resp),
NULL, cancellable, error);
+ g_mutex_unlock (&is->priv->stream_lock);
g_free (resp);
if (n_bytes_written < 0)
@@ -3165,11 +3172,13 @@ imapx_continuation (CamelIMAPXServer *is,
if (file_input_stream == NULL)
return FALSE;
+ g_mutex_lock (&is->priv->stream_lock);
n_bytes_written = g_output_stream_splice (
output_stream,
G_INPUT_STREAM (file_input_stream),
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
cancellable, error);
+ g_mutex_unlock (&is->priv->stream_lock);
g_object_unref (file_input_stream);
@@ -3178,9 +3187,11 @@ imapx_continuation (CamelIMAPXServer *is,
break; }
case CAMEL_IMAPX_COMMAND_STRING:
+ g_mutex_lock (&is->priv->stream_lock);
n_bytes_written = g_output_stream_write_all (
output_stream, cp->ob, cp->ob_size,
NULL, cancellable, error);
+ g_mutex_unlock (&is->priv->stream_lock);
if (n_bytes_written < 0)
return FALSE;
break;
@@ -3210,9 +3221,11 @@ noskip:
c (is->tagprefix, "next part of command \"%c%05u: %s\"\n", is->tagprefix, ic->tag, cp->data);
+ g_mutex_lock (&is->priv->stream_lock);
n_bytes_written = g_output_stream_write_all (
output_stream, cp->data, strlen (cp->data),
NULL, cancellable, error);
+ g_mutex_unlock (&is->priv->stream_lock);
if (n_bytes_written < 0)
return FALSE;
@@ -3225,8 +3238,10 @@ noskip:
c (is->tagprefix, "%p: queueing continuation\n", ic);
}
+ g_mutex_lock (&is->priv->stream_lock);
n_bytes_written = g_output_stream_write_all (
output_stream, "\r\n", 2, NULL, cancellable, error);
+ g_mutex_unlock (&is->priv->stream_lock);
if (n_bytes_written < 0)
return FALSE;
@@ -3525,8 +3540,10 @@ imapx_command_idle_stop (CamelIMAPXServer *is,
cancellable = g_weak_ref_get (&is->priv->parser_cancellable);
+ g_mutex_lock (&is->priv->stream_lock);
success = g_output_stream_write_all (
output_stream, "DONE\r\n", 6, NULL, cancellable, error);
+ g_mutex_unlock (&is->priv->stream_lock);
if (!success) {
g_prefix_error (error, "Unable to issue DONE: ");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]