[evolution-patches] soup patch for rcd bug #58434



I think this should fix the rcd-sucking-up-all-cpu bug. It hopefully
also fixes the weird delays in Connector 1.5 sometimes.


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libsoup/ChangeLog,v
retrieving revision 1.427
diff -u -r1.427 ChangeLog
--- ChangeLog	11 May 2004 21:30:31 -0000	1.427
+++ ChangeLog	18 May 2004 21:44:05 -0000
@@ -1,3 +1,21 @@
+2004-05-18  Dan Winship  <danw novell com>
+
+	* libsoup/soup-ssl.h:
+	* libsoup/soup-nossl.c: define some GError codes and stuff
+
+	* libsoup/soup-gnutls.c: add missing #include <gnutls/x509.h>
+	(do_handshake): when returning G_IO_STATUS_AGAIN, set the GError
+	to SOUP_SSL_ERROR_HANDSHAKE_NEEDS_READ or _NEEDS_WRITE
+	appropriately.
+
+	* libsoup/soup-socket.c (soup_socket_write): Handle
+	SOUP_SSL_ERROR_HANDSHAKE_NEEDS_READ, by setting an io watch for
+	G_IO_IN instead of G_IO_OUT. Fixes the rcd-sucking-up-all-cpu bug
+	(#58434)
+	(read_from_network): Handle the reverse case (which would cause
+	hanging rather than spinning, and might be the cause of some
+	connector 1.5 slowness?)
+
 2004-05-11  Dan Winship  <danw novell com>
 
 	* libsoup/soup-misc.c (soup_signal_connect_once): Do this less
Index: libsoup/soup-gnutls.c
===================================================================
RCS file: /cvs/gnome/libsoup/libsoup/soup-gnutls.c,v
retrieving revision 1.13
diff -u -r1.13 soup-gnutls.c
--- libsoup/soup-gnutls.c	2 Feb 2004 18:01:28 -0000	1.13
+++ libsoup/soup-gnutls.c	18 May 2004 21:44:05 -0000
@@ -20,6 +20,7 @@
 #include <glib.h>
 
 #include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
 
 #include "soup-ssl.h"
 #include "soup-misc.h"
@@ -115,8 +116,14 @@
 	result = gnutls_handshake (chan->session);
 
 	if (result == GNUTLS_E_AGAIN ||
-	    result == GNUTLS_E_INTERRUPTED)
+	    result == GNUTLS_E_INTERRUPTED) {
+		g_set_error (err, SOUP_SSL_ERROR,
+			     (gnutls_record_get_direction (chan->session) ?
+			      SOUP_SSL_ERROR_HANDSHAKE_NEEDS_WRITE :
+			      SOUP_SSL_ERROR_HANDSHAKE_NEEDS_READ),
+			     "Handshaking...");
 		return G_IO_STATUS_AGAIN;
+	}
 
 	if (result < 0) {
 		g_set_error (err, G_IO_CHANNEL_ERROR,
Index: libsoup/soup-nossl.c
===================================================================
RCS file: /cvs/gnome/libsoup/libsoup/soup-nossl.c,v
retrieving revision 1.1
diff -u -r1.1 soup-nossl.c
--- libsoup/soup-nossl.c	18 Nov 2003 16:00:21 -0000	1.1
+++ libsoup/soup-nossl.c	18 May 2004 21:44:05 -0000
@@ -9,11 +9,11 @@
 #include <config.h>
 #endif
 
-#ifndef HAVE_SSL
-
 #include "soup-ssl.h"
 #include "soup-misc.h"
 
+#ifndef HAVE_SSL
+
 gboolean soup_ssl_supported = FALSE;
 
 GIOChannel *
@@ -48,3 +48,17 @@
 }
 
 #endif /* ! HAVE_SSL */
+
+/**
+ * soup_ssl_error_quark:
+ *
+ * Return value: The quark used as %SOUP_SSL_ERROR
+ **/
+GQuark
+soup_ssl_error_quark (void)
+{
+	static GQuark error;
+	if (!error)
+		error = g_quark_from_static_string ("soup_ssl_error_quark");
+	return error;
+}
Index: libsoup/soup-socket.c
===================================================================
RCS file: /cvs/gnome/libsoup/libsoup/soup-socket.c,v
retrieving revision 1.51
diff -u -r1.51 soup-socket.c
--- libsoup/soup-socket.c	10 Feb 2004 22:52:15 -0000	1.51
+++ libsoup/soup-socket.c	18 May 2004 21:44:05 -0000
@@ -836,12 +836,21 @@
 read_from_network (SoupSocket *sock, gpointer buffer, gsize len, gsize *nread)
 {
 	GIOStatus status;
+	GIOCondition cond = G_IO_IN;
+	GError *err = NULL;
 
 	if (!sock->priv->iochannel) 
 		return SOUP_SOCKET_EOF;
 
 	status = g_io_channel_read_chars (sock->priv->iochannel,
-					  buffer, len, nread, NULL);
+					  buffer, len, nread, &err);
+	if (err) {
+		if (err->domain == SOUP_SSL_ERROR &&
+		    err->code == SOUP_SSL_ERROR_HANDSHAKE_NEEDS_WRITE)
+			cond = G_IO_OUT;
+		g_error_free (err);
+	}
+
 	switch (status) {
 	case G_IO_STATUS_NORMAL:
 	case G_IO_STATUS_AGAIN:
@@ -850,7 +859,7 @@
 
 		if (!sock->priv->read_tag) {
 			sock->priv->read_tag =
-				g_io_add_watch (sock->priv->iochannel, G_IO_IN,
+				g_io_add_watch (sock->priv->iochannel, cond,
 						socket_read_watch, sock);
 		}
 		return SOUP_SOCKET_WOULD_BLOCK;
@@ -1035,6 +1044,8 @@
 {
 	GIOStatus status;
 	gpointer pipe_handler;
+	GIOCondition cond = G_IO_OUT;
+	GError *err = NULL;
 
 	g_return_val_if_fail (SOUP_IS_SOCKET (sock), SOUP_SOCKET_ERROR);
 
@@ -1051,8 +1062,15 @@
 
 	pipe_handler = signal (SIGPIPE, SIG_IGN);
 	status = g_io_channel_write_chars (sock->priv->iochannel,
-					   buffer, len, nwrote, NULL);
+					   buffer, len, nwrote, &err);
 	signal (SIGPIPE, pipe_handler);
+	if (err) {
+		if (err->domain == SOUP_SSL_ERROR &&
+		    err->code == SOUP_SSL_ERROR_HANDSHAKE_NEEDS_READ)
+			cond = G_IO_IN;
+		g_error_free (err);
+	}
+
 	if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN) {
 		g_mutex_unlock (sock->priv->iolock);
 		return SOUP_SOCKET_ERROR;
@@ -1064,7 +1082,7 @@
 	}
 
 	sock->priv->write_tag =
-		g_io_add_watch (sock->priv->iochannel, G_IO_OUT,
+		g_io_add_watch (sock->priv->iochannel, cond, 
 				socket_write_watch, sock);
 	g_mutex_unlock (sock->priv->iolock);
 	return SOUP_SOCKET_WOULD_BLOCK;
Index: libsoup/soup-ssl.h
===================================================================
RCS file: /cvs/gnome/libsoup/libsoup/soup-ssl.h,v
retrieving revision 1.7
diff -u -r1.7 soup-ssl.h
--- libsoup/soup-ssl.h	23 Sep 2003 19:35:41 -0000	1.7
+++ libsoup/soup-ssl.h	18 May 2004 21:44:05 -0000
@@ -24,4 +24,13 @@
 					      const char  *remote_host,
 					      gpointer     credentials);
 
+#define SOUP_SSL_ERROR soup_ssl_error_quark()
+
+GQuark soup_ssl_error_quark (void);
+
+typedef enum {
+	SOUP_SSL_ERROR_HANDSHAKE_NEEDS_READ,
+	SOUP_SSL_ERROR_HANDSHAKE_NEEDS_WRITE
+} SoupSocketError;
+
 #endif /* SOUP_SSL_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]