 If <a href="../man3/SSL_shutdown.html">SSL_shutdown(3)</a> returns a negative result then we must call <a href="../man3/SSL_get_error.html">SSL_get_error(3)</a> to work out what to do next. We use our handle_io_failure() function that we developed earlier for this:</p>

<pre><code>/*
 * Repeatedly call SSL_shutdown() until the connection is fully
 * closed.
 */
while ((ret = SSL_shutdown(ssl)) != 1) {
    if (ret &lt; 0 &amp;&amp; handle_io_failure(ssl, ret) == 1)
        continue; /* Retry */
}</code></pr