Listing 7. Calling SSL_shutdown

r=SSL_shutdown(ssl);
if(!r){
  /* If we called SSL_shutdown() first then
     we always get return value of '0'. In
     this case, try again, but first send a
     TCP FIN to trigger the other side's
     close_notify*/
  shutdown(s,1);
  r=SSL_shutdown(ssl);
}
switch(r){
  case 1:
    break; /* Success */
  case 0:
  case -1:
  default:
    berr_exit("Shutdown failed");
}