[evolution-data-server] Make the SSL stream's stream_read() reusable internally



commit 7cb718f0b5c803094d221cc8db115fbec171b910
Author: Federico Mena Quintero <federico novell com>
Date:   Wed May 26 19:58:35 2010 -0500

    Make the SSL stream's stream_read() reusable internally
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 camel/camel-tcp-stream-ssl.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/camel/camel-tcp-stream-ssl.c b/camel/camel-tcp-stream-ssl.c
index b0778e9..8cddc37 100644
--- a/camel/camel-tcp-stream-ssl.c
+++ b/camel/camel-tcp-stream-ssl.c
@@ -179,11 +179,8 @@ tcp_stream_ssl_finalize (GObject *object)
 }
 
 static gssize
-tcp_stream_ssl_read (CamelStream *stream,
-                     gchar *buffer,
-                     gsize n)
+read_from_prfd (PRFileDesc *fd, gchar *buffer, gsize n)
 {
-	CamelTcpStreamSSL *tcp_stream_ssl = CAMEL_TCP_STREAM_SSL (stream);
 	PRFileDesc *cancel_fd;
 	gssize nread;
 
@@ -195,7 +192,7 @@ tcp_stream_ssl_read (CamelStream *stream,
 	cancel_fd = camel_operation_cancel_prfd (NULL);
 	if (cancel_fd == NULL) {
 		do {
-			nread = PR_Read (tcp_stream_ssl->priv->sockfd, buffer, n);
+			nread = PR_Read (fd, buffer, n);
 			if (nread == -1)
 				set_errno (PR_GetError ());
 		} while (nread == -1 && (PR_GetError () == PR_PENDING_INTERRUPT_ERROR ||
@@ -209,13 +206,13 @@ tcp_stream_ssl_read (CamelStream *stream,
 
 		/* get O_NONBLOCK options */
 		sockopts.option = PR_SockOpt_Nonblocking;
-		PR_GetSocketOption (tcp_stream_ssl->priv->sockfd, &sockopts);
+		PR_GetSocketOption (fd, &sockopts);
 		sockopts.option = PR_SockOpt_Nonblocking;
 		nonblock = sockopts.value.non_blocking;
 		sockopts.value.non_blocking = TRUE;
-		PR_SetSocketOption (tcp_stream_ssl->priv->sockfd, &sockopts);
+		PR_SetSocketOption (fd, &sockopts);
 
-		pollfds[0].fd = tcp_stream_ssl->priv->sockfd;
+		pollfds[0].fd = fd
 		pollfds[0].in_flags = PR_POLL_READ;
 		pollfds[1].fd = cancel_fd;
 		pollfds[1].in_flags = PR_POLL_READ;
@@ -242,7 +239,7 @@ tcp_stream_ssl_read (CamelStream *stream,
 				goto failed;
 			} else {
 				do {
-					nread = PR_Read (tcp_stream_ssl->priv->sockfd, buffer, n);
+					nread = PR_Read (fd, buffer, n);
 					if (nread == -1)
 						set_errno (PR_GetError ());
 				} while (nread == -1 && PR_GetError () == PR_PENDING_INTERRUPT_ERROR);
@@ -256,7 +253,7 @@ tcp_stream_ssl_read (CamelStream *stream,
 		error = errno;
 		sockopts.option = PR_SockOpt_Nonblocking;
 		sockopts.value.non_blocking = nonblock;
-		PR_SetSocketOption (tcp_stream_ssl->priv->sockfd, &sockopts);
+		PR_SetSocketOption (fd, &sockopts);
 		errno = error;
 	}
 
@@ -264,6 +261,16 @@ tcp_stream_ssl_read (CamelStream *stream,
 }
 
 static gssize
+tcp_stream_ssl_read (CamelStream *stream,
+                     gchar *buffer,
+                     gsize n)
+{
+	CamelTcpStreamSSL *ssl = CAMEL_TCP_STREAM_SSL (stream);
+
+	return read_from_prfd (ssl->priv->sockfd, buffer, n);
+}
+
+static gssize
 write_to_prfd (PRFileDesc *fd, const gchar *buffer, gsize n)
 {
 	gssize w, written = 0;



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