Index: doc/README
===================================================================
--- doc/README	(revision 1d2e3c2ee2fb4c12ad25832b93ae9513d042717a)
+++ doc/README	(revision ec3e4116687f5e990e6d24e2c79e629665ac5e7e)
@@ -50,5 +50,5 @@
 
 These days, MSN Messenger clients have to connect to the MS Passport servers
-through HTTPS. BitlBee can use serveral SSL libraries for this: GnuTLS, NSS
+through HTTPS. BitlBee can use several SSL libraries for this: GnuTLS, NSS
 (which comes with Mozilla) and OpenSSL. OpenSSL is not GPL-compatible in some
 situations, so using GnuTLS or NSS is preferred. However, especially on *BSD,
Index: protocols/ssl_openssl.c
===================================================================
--- protocols/ssl_openssl.c	(revision 1d2e3c2ee2fb4c12ad25832b93ae9513d042717a)
+++ protocols/ssl_openssl.c	(revision ec3e4116687f5e990e6d24e2c79e629665ac5e7e)
@@ -5,5 +5,5 @@
   \********************************************************************/
 
-/* SSL module - GnuTLS version                                          */
+/* SSL module - OpenTLS version                                          */
 
 /*
@@ -41,11 +41,9 @@
 struct scd
 {
-	ssl_input_function func;
+	SslInputFunction func;
 	gpointer data;
 	int fd;
 	gboolean established;
 	
-	int inpa;
-	int lasterr;		/* Necessary for SSL_get_error */
 	SSL *ssl;
 	SSL_CTX *ssl_ctx;
@@ -56,5 +54,5 @@
 
 
-void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data )
+void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data )
 {
 	struct scd *conn = g_new0( struct scd, 1 );
@@ -95,6 +93,4 @@
 }
 
-static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond );
-
 static void ssl_connected( gpointer data, gint source, GaimInputCondition cond )
 {
@@ -102,36 +98,12 @@
 	
 	if( source == -1 )
-		return ssl_handshake( data, -1, cond );
+		goto ssl_connected_failure;
 	
-	/* Make it non-blocking at least during the handshake... */
-	sock_make_nonblocking( conn->fd );
 	SSL_set_fd( conn->ssl, conn->fd );
 	
-	return ssl_handshake( data, source, cond );
-}	
-
-static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond )
-{
-	struct scd *conn = data;
-	int st;
-	
-	if( conn->inpa != -1 )
-	{
-		gaim_input_remove( conn->inpa );
-		conn->inpa = -1;
-	}
-	
-	if( ( st = SSL_connect( conn->ssl ) ) < 0 )
-	{
-		conn->lasterr = SSL_get_error( conn->ssl, st );
-		if( conn->lasterr != SSL_ERROR_WANT_READ && conn->lasterr != SSL_ERROR_WANT_WRITE )
-			goto ssl_connected_failure;
-		
-		conn->inpa = gaim_input_add( conn->fd, ssl_getdirection( conn ), ssl_handshake, data );
-		return;
-	}
+	if( SSL_connect( conn->ssl ) < 0 )
+		goto ssl_connected_failure;
 	
 	conn->established = TRUE;
-	sock_make_blocking( conn->fd );		/* For now... */
 	conn->func( conn->data, conn, cond );
 	return;
@@ -155,46 +127,16 @@
 int ssl_read( void *conn, char *buf, int len )
 {
-	int st;
+	if( !((struct scd*)conn)->established )
+		return( 0 );
 	
-	if( !((struct scd*)conn)->established )
-	{
-		ssl_errno = SSL_NOHANDSHAKE;
-		return -1;
-	}
-	
-	st = SSL_read( ((struct scd*)conn)->ssl, buf, len );
-	
-	ssl_errno = SSL_OK;
-	if( st <= 0 )
-	{
-		((struct scd*)conn)->lasterr = SSL_get_error( ((struct scd*)conn)->ssl, st );
-		if( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_READ || ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE )
-			ssl_errno = SSL_AGAIN;
-	}
-	
-	return st;
+	return( SSL_read( ((struct scd*)conn)->ssl, buf, len ) );
 }
 
 int ssl_write( void *conn, const char *buf, int len )
 {
-	int st;
+	if( !((struct scd*)conn)->established )
+		return( 0 );
 	
-	if( !((struct scd*)conn)->established )
-	{
-		ssl_errno = SSL_NOHANDSHAKE;
-		return -1;
-	}
-	
-	st = SSL_write( ((struct scd*)conn)->ssl, buf, len );
-	
-	ssl_errno = SSL_OK;
-	if( st <= 0 )
-	{
-		((struct scd*)conn)->lasterr = SSL_get_error( ((struct scd*)conn)->ssl, st );
-		if( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_READ || ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE )
-			ssl_errno = SSL_AGAIN;
-	}
-	
-	return st;
+	return( SSL_write( ((struct scd*)conn)->ssl, buf, len ) );
 }
 
@@ -202,7 +144,4 @@
 {
 	struct scd *conn = conn_;
-	
-	if( conn->inpa != -1 )
-		gaim_input_remove( conn->inpa );
 	
 	if( conn->established )
@@ -220,7 +159,2 @@
 	return( ((struct scd*)conn)->fd );
 }
-
-GaimInputCondition ssl_getdirection( void *conn )
-{
-	return( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ? GAIM_INPUT_WRITE : GAIM_INPUT_READ );
-}
