1178172Simp=pod 2178172Simp 3178172Simp=head1 NAME 4178172Simp 5178172SimpSSL_get_error - obtain result code for TLS/SSL I/O operation 6178172Simp 7178172Simp=head1 SYNOPSIS 8178172Simp 9178172Simp #include <openssl/ssl.h> 10178172Simp 11178172Simp int SSL_get_error(const SSL *ssl, int ret); 12178172Simp 13178172Simp=head1 DESCRIPTION 14178172Simp 15178172SimpSSL_get_error() returns a result code (suitable for the C "switch" 16178172Simpstatement) for a preceding call to SSL_connect(), SSL_accept(), SSL_do_handshake(), 17178172SimpSSL_read(), SSL_peek(), or SSL_write() on B<ssl>. The value returned by 18178172Simpthat TLS/SSL I/O function must be passed to SSL_get_error() in parameter 19178172SimpB<ret>. 20178172Simp 21178172SimpIn addition to B<ssl> and B<ret>, SSL_get_error() inspects the 22178172Simpcurrent thread's OpenSSL error queue. Thus, SSL_get_error() must be 23178172Simpused in the same thread that performed the TLS/SSL I/O operation, and no 24178172Simpother OpenSSL function calls should appear in between. The current 25178172Simpthread's error queue must be empty before the TLS/SSL I/O operation is 26178172Simpattempted, or SSL_get_error() will not work reliably. 27178172Simp 28178172Simp=head1 RETURN VALUES 29178172Simp 30178172SimpThe following return values can currently occur: 31178172Simp 32178172Simp=over 4 33178172Simp 34178172Simp=item SSL_ERROR_NONE 35178172Simp 36178172SimpThe TLS/SSL I/O operation completed. This result code is returned 37178172Simpif and only if B<ret E<gt> 0>. 38178172Simp 39178172Simp=item SSL_ERROR_ZERO_RETURN 40178172Simp 41178172SimpThe TLS/SSL connection has been closed. 42196994SphkIf the protocol version is SSL 3.0 or higher, this result code is returned only 43196994Sphkif a closure alert has occurred in the protocol, i.e. if the connection has been 44178172Simpclosed cleanly. 45196994SphkNote that in this case B<SSL_ERROR_ZERO_RETURN> does not necessarily 46196994Sphkindicate that the underlying transport has been closed. 47178172Simp 48178172Simp 49206717Sjmallett=item SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE 50178172Simp 51178172SimpThe operation did not complete; the same TLS/SSL I/O function should be 52178172Simpcalled again later. If, by then, the underlying B<BIO> has data 53178172Simpavailable for reading (if the result code is B<SSL_ERROR_WANT_READ>) 54178172Simpor allows writing data (B<SSL_ERROR_WANT_WRITE>), then some TLS/SSL 55178172Simpprotocol progress will take place, i.e. at least part of an TLS/SSL 56178172Simprecord will be read or written. Note that the retry may again lead to 57178172Simpa B<SSL_ERROR_WANT_READ> or B<SSL_ERROR_WANT_WRITE> condition. 58178172SimpThere is no fixed upper limit for the number of iterations that 59178172Simpmay be necessary until progress becomes visible at application 60215971Sjmallettprotocol level. 61215971Sjmallett 62233644SjmallettFor socket B<BIO>s (e.g. when SSL_set_fd() was used), select() or 63232449Sjmallettpoll() on the underlying socket can be used to find out when the 64233644SjmallettTLS/SSL I/O function should be retried. 65232449Sjmallett 66215971SjmallettCaveat: Any TLS/SSL I/O function can lead to either of 67233644SjmallettB<SSL_ERROR_WANT_READ> and B<SSL_ERROR_WANT_WRITE>. In particular, 68215971SjmallettSSL_read() or SSL_peek() may want to write data and SSL_write() may want 69233644Sjmallettto read data. This is mainly because TLS/SSL handshakes may occur at any 70178172Simptime during the protocol (initiated by either the client or the server); 71215971SjmallettSSL_read(), SSL_peek(), and SSL_write() will handle any pending handshakes. 72215971Sjmallett 73215971Sjmallett=item SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_ACCEPT 74232449Sjmallett 75232449SjmallettThe operation did not complete; the same TLS/SSL I/O function should be 76232449Sjmallettcalled again later. The underlying BIO was not connected yet to the peer 77215971Sjmallettand the call would block in connect()/accept(). The SSL function should be 78215971Sjmallettcalled again when the connection is established. These messages can only 79215971Sjmallettappear with a BIO_s_connect() or BIO_s_accept() BIO, respectively. 80215971SjmallettIn order to find out, when the connection has been successfully established, 81215971Sjmalletton many platforms select() or poll() for writing on the socket file descriptor 82215971Sjmallettcan be used. 83215971Sjmallett 84178172Simp=item SSL_ERROR_WANT_X509_LOOKUP 85178172Simp 86178172SimpThe operation did not complete because an application callback set by 87178172SimpSSL_CTX_set_client_cert_cb() has asked to be called again. 88178172SimpThe TLS/SSL I/O function should be called again later. 89178172SimpDetails depend on the application. 90178172Simp 91178172Simp=item SSL_ERROR_SYSCALL 92178172Simp 93178172SimpSome non-recoverable, fatal I/O error occurred. The OpenSSL error queue may 94178172Simpcontain more information on the error. For socket I/O on Unix systems, consult 95208165SrrsB<errno> for details. If this error occurs then no further I/O operations should 96224207Sattiliobe performed on the connection and SSL_shutdown() must not be called. 97178172Simp 98224207Sattilio=item SSL_ERROR_SSL 99178172Simp 100178172SimpA non-recoverable, fatal error in the SSL library occurred, usually a protocol 101178172Simperror. The OpenSSL error queue contains more information on the error. If this 102178172Simperror occurs then no further I/O operations should be performed on the 103178172Simpconnection and SSL_shutdown() must not be called. 104250338Sattilio 105250338Sattilio=back 106250338Sattilio 107250338Sattilio=head1 SEE ALSO 108178172Simp 109178172SimpL<ssl(3)|ssl(3)>, L<err(3)|err(3)> 110178172Simp 111178172Simp=head1 HISTORY 112178172Simp 113178172SimpSSL_get_error() was added in SSLeay 0.8. 114178172Simp 115178172Simp=cut 116195376Ssam