From 5020870cdf2f36150e5370d584805b09a1762048 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Mon, 6 Jan 2020 15:19:14 -0800 Subject: [PATCH] (apple ssl) unify read and write ssl utility code --- docs/CHANGELOG.md | 4 +++ ixwebsocket/IXSocketAppleSSL.cpp | 47 +++++++++++++++++++++----------- ixwebsocket/IXWebSocketVersion.h | 2 +- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8a2e056a..13115d34 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All changes to this project will be documented in this file. +## [7.9.2] - 2020-01-06 + +(apple ssl) unify read and write ssl utility code + ## [7.9.1] - 2020-01-06 (websocket client) better error propagation when errors are detected while sending data diff --git a/ixwebsocket/IXSocketAppleSSL.cpp b/ixwebsocket/IXSocketAppleSSL.cpp index e82f6f26..3dbad319 100644 --- a/ixwebsocket/IXSocketAppleSSL.cpp +++ b/ixwebsocket/IXSocketAppleSSL.cpp @@ -100,7 +100,8 @@ namespace ix { case ENOENT: return errSSLClosedGraceful; - case EAGAIN: return errSSLWouldBlock; + case EAGAIN: return errSSLWouldBlock; // EWOULDBLOCK is a define for EAGAIN on osx + case EINPROGRESS: return errSSLWouldBlock; case ECONNRESET: return errSSLClosedAbort; @@ -142,13 +143,16 @@ namespace ix else { *len = 0; - if (errno == EAGAIN) + switch (errno) { - return errSSLWouldBlock; - } - else - { - return errSecIO; + case ENOENT: return errSSLClosedGraceful; + + case EAGAIN: return errSSLWouldBlock; // EWOULDBLOCK is a define for EAGAIN on osx + case EINPROGRESS: return errSSLWouldBlock; + + case ECONNRESET: return errSSLClosedAbort; + + default: return errSecIO; } } } @@ -234,20 +238,31 @@ namespace ix ssize_t SocketAppleSSL::send(char* buf, size_t nbyte) { - ssize_t ret = 0; - OSStatus status; - do + OSStatus status = errSSLWouldBlock; + while (status == errSSLWouldBlock) { size_t processed = 0; std::lock_guard lock(_mutex); status = SSLWrite(_sslContext, buf, nbyte, &processed); - ret += processed; - buf += processed; - nbyte -= processed; - } while (nbyte > 0 && status == errSSLWouldBlock); - if (ret == 0 && errSSLClosedAbort != status) ret = -1; - return ret; + if (processed > 0) return (ssize_t) processed; + + // The connection was reset, inform the caller that this + // Socket should close + if (status == errSSLClosedGraceful || status == errSSLClosedNoNotify || + status == errSSLClosedAbort) + { + errno = ECONNRESET; + return -1; + } + + if (status == errSSLWouldBlock) + { + errno = EWOULDBLOCK; + return -1; + } + } + return -1; } ssize_t SocketAppleSSL::send(const std::string& buffer) diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index b1b03f6c..927d9f12 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "7.9.1" +#define IX_WEBSOCKET_VERSION "7.9.2"