Apparently, there are still chances we have to deal with buggy pod2man versions.
[openssl.git] / demos / tunala / sm.c
index ee661c5197679483697fbdc853ad2796656a36b7..25359e67ef49d99663c4ab9fea6dfe62c072ab8f 100644 (file)
@@ -55,7 +55,7 @@ SSL *state_machine_get_SSL(state_machine_t *machine)
        return machine->ssl;
 }
 
-void state_machine_set_SSL(state_machine_t *machine, SSL *ssl, int is_server)
+int state_machine_set_SSL(state_machine_t *machine, SSL *ssl, int is_server)
 {
        if(machine->ssl)
                /* Shouldn't ever be set twice */
@@ -75,13 +75,21 @@ void state_machine_set_SSL(state_machine_t *machine, SSL *ssl, int is_server)
        /* If we're the first one to generate traffic - do it now otherwise we
         * go into the next select empty-handed and our peer will not send data
         * but will similarly wait for us. */
-       state_machine_churn(machine);
+       return state_machine_churn(machine);
 }
 
 /* Performs the data-IO loop and returns zero if the machine should close */
 int state_machine_churn(state_machine_t *machine)
 {
        unsigned int loop;
+       if(machine->ssl == NULL) {
+               if(buffer_empty(&machine->clean_out))
+                       /* Time to close this state-machine altogether */
+                       return 0;
+               else
+                       /* Still buffered data on the clean side to go out */
+                       return 1;
+       }
        /* Do this loop twice to cover any dependencies about which precise
         * order of reads and writes is required. */
        for(loop = 0; loop < 2; loop++) {
@@ -90,21 +98,14 @@ int state_machine_churn(state_machine_t *machine)
                buffer_from_SSL(&machine->clean_out, machine->ssl);
                buffer_from_BIO(&machine->dirty_out, machine->bio_fromssl);
        }
-       if(machine->ssl == NULL) {
-               if(buffer_empty(&machine->clean_out))
-                       /* Time to close this state-machine altogether */
+       /* We close on the SSL side if the info callback noticed some problems
+        * or an SSL shutdown was underway and shutdown traffic had all been
+        * sent. */
+       if(SSL_get_app_data(machine->ssl) || (SSL_get_shutdown(machine->ssl) &&
+                               buffer_empty(&machine->dirty_out))) {
+               /* Great, we can seal off the dirty side completely */
+               if(!state_machine_close_dirty(machine))
                        return 0;
-               else
-                       /* Still buffered data on the clean side to go out */
-                       return 1;
-       }
-       if(SSL_get_shutdown(machine->ssl)) {
-               /* An SSL shutdown was underway */
-               if(buffer_empty(&machine->dirty_out)) {
-                       /* Great, we can seal off the dirty side completely */
-                       if(!state_machine_close_dirty(machine))
-                               return 0;
-               }
        }
        /* Either the SSL is alive and well, or the closing process still has
         * outgoing data waiting to be sent */