You can't rely on errno in libtls In libtls, failure (-1) is always failure. As opposed to "but wait, check errno, it's not really a failure" tls_read() and tls_write() clear the global errno variable. This is to prevent callers from mishandling error conditions. libtls provides tls_error() to get an error message on failure.