+#endif
+}
+
+#if ENABLE_SSL
+static int ssl_check_error(COMSTACK h, tcpip_state *sp, int res)
+{
+#if HAVE_OPENSSL_SSL_H
+ int err = SSL_get_error(sp->ssl, res);
+ TRC(fprintf(stderr, "got err=%d\n", err));
+ if (err == SSL_ERROR_WANT_READ)
+ {
+ TRC(fprintf(stderr, " -> SSL_ERROR_WANT_READ\n"));
+ h->io_pending = CS_WANT_READ;
+ return 1;
+ }
+ if (err == SSL_ERROR_WANT_WRITE)
+ {
+ TRC(fprintf(stderr, " -> SSL_ERROR_WANT_WRITE\n"));
+ h->io_pending = CS_WANT_WRITE;
+ return 1;
+ }
+#elif HAVE_GNUTLS_H
+ TRC(fprintf(stderr, "ssl_check_error error=%d fatal=%d msg=%s\n",
+ res,
+ gnutls_error_is_fatal(res),
+ gnutls_strerror(res)));
+ if (res == GNUTLS_E_AGAIN || res == GNUTLS_E_INTERRUPTED)
+ {
+ int dir = gnutls_record_get_direction(sp->session);
+ TRC(fprintf(stderr, " -> incomplete dir=%d\n", dir));
+ h->io_pending = dir ? CS_WANT_WRITE : CS_WANT_READ;
+ return 1;
+ }
+#endif
+ h->cerrno = CSERRORSSL;
+ return 0;