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

[or-cvs] first steps toward a WANTWRITE SSL_write tls bug fix



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/home2/arma/work/onion/dev/src/common

Modified Files:
	tortls.c 
Log Message:
first steps toward a WANTWRITE SSL_write tls bug fix

how exactly the same do the arguments need to be? :(


Index: tortls.c
===================================================================
RCS file: /home/or/cvsroot/src/common/tortls.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- tortls.c	18 Oct 2003 06:48:46 -0000	1.22
+++ tortls.c	18 Oct 2003 08:00:19 -0000	1.23
@@ -31,6 +31,7 @@
     TOR_TLS_ST_SENTCLOSE, TOR_TLS_ST_CLOSED
   } state;
   int isServer;
+  int wantwrite_n; /* 0 normally, >0 if we returned wantwrite last time */
 };
 
 static X509* tor_tls_create_certificate(crypto_pk_env_t *rsa, 
@@ -293,6 +294,7 @@
   SSL_set_fd(result->ssl, sock);
   result->state = TOR_TLS_ST_HANDSHAKE;
   result->isServer = isServer;
+  result->wantwrite_n = 0;
   return result;
 }
 
@@ -343,13 +345,24 @@
   assert(tls->state == TOR_TLS_ST_OPEN);
   if (n == 0)
     return 0;
+  if(tls->wantwrite_n) {
+    /* if WANTWRITE last time, we must use the _same_ n as before */
+    assert(n >= tls->wantwrite_n);
+    log_fn(LOG_INFO,"resuming pending-write, (%d to flush, reusing %d)",
+           n, tls->wantwrite_n);
+    n = tls->wantwrite_n;
+    tls->wantwrite_n = 0;
+  }
   r = SSL_write(tls->ssl, cp, n);
   err = tor_tls_get_error(tls, r, 0, "writing", LOG_INFO);
   if (err == TOR_TLS_DONE) {
     return r;
-  } else {
-    return err;
-  }  
+  }
+  if (err == TOR_TLS_WANTWRITE) {
+    log_fn(LOG_INFO,"wantwrite. remembering the number %d.",n);
+    tls->wantwrite_n = n;
+  }
+  return err;
 }
 
 /* Perform initial handshake on 'tls'.  When finished, returns