# HG changeset patch # User Tero Marttila # Date 1241654231 -10800 # Node ID 7bfbe9070c50a74b335190b5453df85a0436fb80 # Parent 471ca1e744da70963395328fdf36eaf5858f5772 slight tweaks to ssl_client's handshake-done logic diff -r 471ca1e744da -r 7bfbe9070c50 src/ssl_client.c --- 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); diff -r 471ca1e744da -r 7bfbe9070c50 src/transport.c --- 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); + } } diff -r 471ca1e744da -r 7bfbe9070c50 src/transport_internal.h --- 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. *