
static void __attribute__((noreturn))
ssl_print_error_and_exit(SSL *ssl, const char *op, int ret)
{
  int subcode = SSL_get_error(ssl, ret);
  switch (subcode) {
  case SSL_ERROR_NONE:
    fprintf(stderr, "error: %s: no error to report\n", op);
    break;
  case SSL_ERROR_WANT_READ:
  case SSL_ERROR_WANT_WRITE:
  case SSL_ERROR_WANT_X509_LOOKUP:
  case SSL_ERROR_WANT_CONNECT:
  case SSL_ERROR_WANT_ACCEPT:
    fprintf(stderr, "error: %s: invalid blocking state %d\n", op, subcode);
    break;
  case SSL_ERROR_SSL:
    fprintf(stderr, "error: %s: TLS layer problem\n", op);
  case SSL_ERROR_SYSCALL:
    fprintf(stderr, "error: %s: system call failed: %s\n", op, strerror(errno));
    break;
  case SSL_ERROR_ZERO_RETURN:
    fprintf(stderr, "error: %s: zero return\n", op);
  }
  exit(1);
}

