title: Handling SSL_shutdown correctly
body: <p>The OpenSSL documentation on <code>SSL_shutdown</code> states that:</p>
  
  <blockquote>
    <p>It is therefore recommended, to check the return value of <code>SSL_shutdown()</code> and call <code>SSL_shutdown()</code> again, if the bidirectional shutdown is not yet complete (return value of the first call is 0).</p>
  </blockquote>
  
  <p><a href="https://www.openssl.org/docs/ssl/SSL_shutdown.html" rel="nofollow noreferrer">https://www.openssl.org/docs/ssl/SSL_shutdown.html</a></p>
  
  <p>I have a code snippet below where I check for return value 0 from <code>SSL_shutdown</code> and call it again, which I have been using. My question is, is it okay to disregard the return value of <code>SSL_shutdown</code> on the second call or we should keep retrying <code>SSL_shutdown</code> until a 1 (bidirectional shutdown complete) is returned.</p>
  
  <pre><code>int r = SSL_shutdown(ssl);
  //error handling here if r &lt; 0 
  if(!r)
  {
      shutdown(fd,1);
      SSL_shutdown(ssl); //how should I handle return value and error handling here is it required?? 
  }
  SSL_free(ssl);
  SSLMap.erase(fd);
  shutdown(fd,2);
  close(fd);
  </code></pre>