slight tweaks to ssl_client's handshake-done logic
authorTero Marttila <terom@fixme.fi>
Thu, 07 May 2009 02:57:11 +0300
changeset 183 7bfbe9070c50
parent 182 471ca1e744da
child 184 2ab01ab33cfa
slight tweaks to ssl_client's handshake-done logic
src/ssl_client.c
src/transport.c
src/transport_internal.h
--- a/src/ssl_client.c	Thu May 07 02:49:49 2009 +0300
+++ b/src/ssl_client.c	Thu May 07 02:57:11 2009 +0300
@@ -210,16 +210,17 @@
         RESET_ERROR(&err);
 
         // perform the next handshake step
+        // this returns zero when the handshake is not yet done, errors/completion then trigger the else-if-else below
         if (ssl_client_handshake(client, &err) == 0) {
             // handshake continues
         
-            // XXX: this state flag is completely wrong
-        } else if (SSL_CLIENT_TRANSPORT(client)->connected) {
-            // the async connect process has now completed, either succesfully or with an error
+        } else if (!SSL_CLIENT_TRANSPORT(client)->connected) {
+            // the async connect+handshake process has completed
             // invoke the user connect callback directly with appropriate error
             transport_connected(SSL_CLIENT_TRANSPORT(client), ERROR_CODE(&err) ? &err : NULL, true);
 
         } else {
+            // in-connection re-handshake completed
             if (ERROR_CODE(&err))
                 // the re-handshake failed, so this transport is dead
                 transport_error(SSL_CLIENT_TRANSPORT(client), &err);
--- a/src/transport.c	Thu May 07 02:49:49 2009 +0300
+++ b/src/transport.c	Thu May 07 02:57:11 2009 +0300
@@ -35,21 +35,24 @@
 {
     const struct transport_type *type = object_type(&transport->base_obj, &transport_type_type);
 
-    // update state
-    transport->connected = true;
-
     if (direct || !type->methods._connected) {
         // user callback
-        if (err)
+        if (err) {
             // connect failed
             transport->info.cb_tbl->on_error(transport, err, transport->info.cb_arg);
-        else
+
+        } else {
+            // update state
+            transport->connected = true;
+
             // connect succesfull
             transport->info.cb_tbl->on_connect(transport, transport->info.cb_arg);
+        }
 
     } else {
         // wrapper method
         type->methods._connected(transport, err);
+
     }
 }
 
--- a/src/transport_internal.h	Thu May 07 02:49:49 2009 +0300
+++ b/src/transport_internal.h	Thu May 07 02:57:11 2009 +0300
@@ -102,7 +102,8 @@
  *
  * If called from the transport_methods::_connected method, pass in direct to avoid recursion.
  *
- * XXX: This sets the transport::connected flag, regardless of which callback it invokes.
+ * This sets the transport::connected flag before calling transport_callbacks::on_connected (i.e. directly) without any
+ * error set.
  *
  * XXX: implement proper layering of types by taking a transport_type arg and chaining down from there.
  *