There's no good reason for SSL_shutdown() to ever return a value of 0. The attached patch simplifies things.
--- openssl-1.0.1-beta3-0orig/ssl/s3_lib.c 2012-02-10 12:08:49.000000000 -0800 +++ openssl-1.0.1-beta3/ssl/s3_lib.c 2012-03-02 11:19:53.847954000 -0800 @@ -4112,7 +4112,7 @@ if (s->s3->alert_dispatch) return(-1); /* return WANT_WRITE */ } - else if (s->s3->alert_dispatch) + if (s->s3->alert_dispatch) { /* resend it if not sent */ #if 1 @@ -4127,7 +4127,7 @@ } #endif } - else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) + if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) { /* If we are waiting for a close from our peer, we are closed */ s->method->ssl_read_bytes(s,0,NULL,0,0); @@ -4137,11 +4137,7 @@ } } - if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) && - !s->s3->alert_dispatch) - return(1); - else - return(0); + return(1); } int ssl3_write(SSL *s, const void *buf, int len)