diff --git a/CMakeLists.txt b/CMakeLists.txt index 89f136b7..e43f1987 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,6 @@ set( IXWEBSOCKET_HEADERS ixwebsocket/IXSetThreadName.h ixwebsocket/IXDNSLookup.h ixwebsocket/IXCancellationRequest.h - ixwebsocket/IXNetSystem.h ixwebsocket/IXWebSocket.h ixwebsocket/IXWebSocketServer.h ixwebsocket/IXWebSocketTransport.h @@ -58,6 +57,8 @@ else() list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/linux/IXSetThreadName_linux.cpp) endif() +set (OPENSSL_PREFIX /usr/local/opt/openssl) # Homebrew openssl +include_directories(ixwebsocket ${OPENSSL_PREFIX}/include) if (USE_TLS) add_definitions(-DIXWEBSOCKET_USE_TLS) @@ -65,6 +66,8 @@ if (USE_TLS) if (APPLE) list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketAppleSSL.h) list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketAppleSSL.cpp) + list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketOpenSSL.h) + list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketOpenSSL.cpp) elseif (WIN32) list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketSChannel.h) list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketSChannel.cpp) diff --git a/ixwebsocket/IXSocket.cpp b/ixwebsocket/IXSocket.cpp index 92f1f2ef..fda9eb4a 100644 --- a/ixwebsocket/IXSocket.cpp +++ b/ixwebsocket/IXSocket.cpp @@ -84,29 +84,29 @@ namespace ix _sockfd = -1; } - int Socket::send(char* buffer, size_t length) + ssize_t Socket::send(char* buffer, size_t length) { int flags = 0; #ifdef MSG_NOSIGNAL flags = MSG_NOSIGNAL; #endif - return (int) ::send(_sockfd, buffer, length, flags); + return ::send(_sockfd, buffer, length, flags); } - int Socket::send(const std::string& buffer) + ssize_t Socket::send(const std::string& buffer) { return send((char*)&buffer[0], buffer.size()); } - int Socket::recv(void* buffer, size_t length) + ssize_t Socket::recv(void* buffer, size_t length) { int flags = 0; #ifdef MSG_NOSIGNAL flags = MSG_NOSIGNAL; #endif - return (int) ::recv(_sockfd, (char*) buffer, length, flags); + return ::recv(_sockfd, (char*) buffer, length, flags); } int Socket::getErrno() diff --git a/ixwebsocket/IXSocket.h b/ixwebsocket/IXSocket.h index 890b832f..16f556a1 100644 --- a/ixwebsocket/IXSocket.h +++ b/ixwebsocket/IXSocket.h @@ -35,9 +35,9 @@ namespace ix const CancellationRequest& isCancellationRequested); virtual void close(); - virtual int send(char* buffer, size_t length); - virtual int send(const std::string& buffer); - virtual int recv(void* buffer, size_t length); + virtual ssize_t send(char* buffer, size_t length); + virtual ssize_t send(const std::string& buffer); + virtual ssize_t recv(void* buffer, size_t length); // Blocking and cancellable versions, working with socket that can be set // to non blocking mode. Used during HTTP upgrade. diff --git a/ixwebsocket/IXSocketAppleSSL.cpp b/ixwebsocket/IXSocketAppleSSL.cpp index 9aec505e..01c4ce2c 100644 --- a/ixwebsocket/IXSocketAppleSSL.cpp +++ b/ixwebsocket/IXSocketAppleSSL.cpp @@ -203,7 +203,7 @@ namespace ix Socket::close(); } - int SocketAppleSSL::send(char* buf, size_t nbyte) + ssize_t SocketAppleSSL::send(char* buf, size_t nbyte) { ssize_t ret = 0; OSStatus status; @@ -218,16 +218,16 @@ namespace ix if (ret == 0 && errSSLClosedAbort != status) ret = -1; - return (int) ret; + return ret; } - int SocketAppleSSL::send(const std::string& buffer) + ssize_t SocketAppleSSL::send(const std::string& buffer) { return send((char*)&buffer[0], buffer.size()); } // No wait support - int SocketAppleSSL::recv(void* buf, size_t nbyte) + ssize_t SocketAppleSSL::recv(void* buf, size_t nbyte) { OSStatus status = errSSLWouldBlock; while (errSSLWouldBlock == status) diff --git a/ixwebsocket/IXSocketAppleSSL.h b/ixwebsocket/IXSocketAppleSSL.h index e9796e72..6eac39d4 100644 --- a/ixwebsocket/IXSocketAppleSSL.h +++ b/ixwebsocket/IXSocketAppleSSL.h @@ -28,9 +28,9 @@ namespace ix const CancellationRequest& isCancellationRequested) final; virtual void close() final; - virtual int send(char* buffer, size_t length) final; - virtual int send(const std::string& buffer) final; - virtual int recv(void* buffer, size_t length) final; + virtual ssize_t send(char* buffer, size_t length) final; + virtual ssize_t send(const std::string& buffer) final; + virtual ssize_t recv(void* buffer, size_t length) final; private: SSLContextRef _sslContext; diff --git a/ixwebsocket/IXSocketConnect.cpp b/ixwebsocket/IXSocketConnect.cpp index 27b7953a..2eb9312d 100644 --- a/ixwebsocket/IXSocketConnect.cpp +++ b/ixwebsocket/IXSocketConnect.cpp @@ -43,9 +43,9 @@ namespace ix { errMsg = "no error"; - int fd = socket(address->ai_family, - address->ai_socktype, - address->ai_protocol); + auto fd = socket(address->ai_family, + address->ai_socktype, + address->ai_protocol); if (fd < 0) { errMsg = "Cannot create a socket"; diff --git a/ixwebsocket/IXSocketOpenSSL.cpp b/ixwebsocket/IXSocketOpenSSL.cpp index fe03d739..332d9e3e 100644 --- a/ixwebsocket/IXSocketOpenSSL.cpp +++ b/ixwebsocket/IXSocketOpenSSL.cpp @@ -326,7 +326,7 @@ namespace ix Socket::close(); } - int SocketOpenSSL::send(char* buf, size_t nbyte) + ssize_t SocketOpenSSL::send(char* buf, size_t nbyte) { ssize_t sent = 0; @@ -340,7 +340,7 @@ namespace ix } ERR_clear_error(); - int write_result = SSL_write(_ssl_connection, buf + sent, (int) nbyte); + ssize_t write_result = SSL_write(_ssl_connection, buf + sent, (int) nbyte); int reason = SSL_get_error(_ssl_connection, write_result); if (reason == SSL_ERROR_NONE) { @@ -353,16 +353,16 @@ namespace ix return -1; } } - return (int) sent; + return sent; } - int SocketOpenSSL::send(const std::string& buffer) + ssize_t SocketOpenSSL::send(const std::string& buffer) { return send((char*)&buffer[0], buffer.size()); } // No wait support - int SocketOpenSSL::recv(void* buf, size_t nbyte) + ssize_t SocketOpenSSL::recv(void* buf, size_t nbyte) { while (true) { @@ -374,7 +374,7 @@ namespace ix } ERR_clear_error(); - int read_result = SSL_read(_ssl_connection, buf, (int) nbyte); + ssize_t read_result = SSL_read(_ssl_connection, buf, (int) nbyte); if (read_result > 0) { diff --git a/ixwebsocket/IXSocketOpenSSL.h b/ixwebsocket/IXSocketOpenSSL.h index 4c11c3f6..4fdfd48b 100644 --- a/ixwebsocket/IXSocketOpenSSL.h +++ b/ixwebsocket/IXSocketOpenSSL.h @@ -31,9 +31,9 @@ namespace ix const CancellationRequest& isCancellationRequested) final; virtual void close() final; - virtual int send(char* buffer, size_t length) final; - virtual int send(const std::string& buffer) final; - virtual int recv(void* buffer, size_t length) final; + virtual ssize_t send(char* buffer, size_t length) final; + virtual ssize_t send(const std::string& buffer) final; + virtual ssize_t recv(void* buffer, size_t length) final; private: void openSSLInitialize(); diff --git a/ixwebsocket/IXWebSocket.h b/ixwebsocket/IXWebSocket.h index fecca6fd..ef75d8df 100644 --- a/ixwebsocket/IXWebSocket.h +++ b/ixwebsocket/IXWebSocket.h @@ -60,7 +60,7 @@ namespace ix uint16_t code; std::string reason; - WebSocketCloseInfo(uint64_t c = 0, + WebSocketCloseInfo(uint16_t c = 0, const std::string& r = std::string()) : code(c) , reason(r)