From 972eaf91a0aa9ac99ff0134b295c0e143cc1f2e8 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 3 Dec 2015 21:37:34 +0800 Subject: [PATCH] ssl zero return indicates shutdown Signed-off-by: Andy Green --- lib/ssl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ssl.c b/lib/ssl.c index cb19d60..ad56ebe 100644 --- a/lib/ssl.c +++ b/lib/ssl.c @@ -441,7 +441,11 @@ lws_ssl_capable_read(struct libwebsocket_context *context, return lws_ssl_capable_read_no_ssl(context, wsi, buf, len); n = SSL_read(wsi->ssl, buf, len); - if (n >= 0) { + /* manpage: returning 0 means connection shut down */ + if (!n) + return LWS_SSL_CAPABLE_ERROR; + + if (n > 0) { /* * if it was our buffer that limited what we read, * check if SSL has additional data pending inside SSL buffers. @@ -490,7 +494,7 @@ lws_ssl_capable_write(struct libwebsocket *wsi, unsigned char *buf, int len) return lws_ssl_capable_write_no_ssl(wsi, buf, len); n = SSL_write(wsi->ssl, buf, len); - if (n >= 0) + if (n > 0) return n; n = SSL_get_error(wsi->ssl, n); -- 2.7.4