[...] The other party MUST respond with a close_notify alert of its own and close down the connection immediately, discarding any pending writes.
I've read this before, but I've also checked the sources of SSL_write and they seem contradictory:
SSL_write does not return with error when SSL_RECEIVED_SHUTDOWN is set, but does so when SSL_SENT_SHUTDOWN is set. Why is this? A minor bug? If the RFC states the end who receives a close_notify should discard any pending writes then it surely seems a bug to allow SSL_write for a connection where SSL_RECEIVED_SHUTDOWN is set?
....
> If your question is whether you can still read any data that may have
been in flight when you send your close_notify, I believe the answer
is no. Further data received from the peer is discarded after a
close_notify is sent.
I also believe so, especially since SSL_shutdown docs seem to hint that once SSL_shutdown is called, it should be called again until fully done (serving SSL_WANT_READ/WRITE as needed). In other words, SSL_shutdown becomes the only function called until the SSL connection is fully closed, no more SSL_read is called and thus it cannot report any received data. SSL_shutdown does not return with any data.
Regarding the SSL_RECEIVED_SHUTDOWN - do you think this is a minor bug?