int -> ssize_t for socker recv and send
This commit is contained in:
parent
9641c8cf49
commit
0fd06bb592
@ -36,7 +36,6 @@ set( IXWEBSOCKET_HEADERS
|
|||||||
ixwebsocket/IXSetThreadName.h
|
ixwebsocket/IXSetThreadName.h
|
||||||
ixwebsocket/IXDNSLookup.h
|
ixwebsocket/IXDNSLookup.h
|
||||||
ixwebsocket/IXCancellationRequest.h
|
ixwebsocket/IXCancellationRequest.h
|
||||||
ixwebsocket/IXNetSystem.h
|
|
||||||
ixwebsocket/IXWebSocket.h
|
ixwebsocket/IXWebSocket.h
|
||||||
ixwebsocket/IXWebSocketServer.h
|
ixwebsocket/IXWebSocketServer.h
|
||||||
ixwebsocket/IXWebSocketTransport.h
|
ixwebsocket/IXWebSocketTransport.h
|
||||||
@ -58,6 +57,8 @@ else()
|
|||||||
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/linux/IXSetThreadName_linux.cpp)
|
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/linux/IXSetThreadName_linux.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set (OPENSSL_PREFIX /usr/local/opt/openssl) # Homebrew openssl
|
||||||
|
include_directories(ixwebsocket ${OPENSSL_PREFIX}/include)
|
||||||
|
|
||||||
if (USE_TLS)
|
if (USE_TLS)
|
||||||
add_definitions(-DIXWEBSOCKET_USE_TLS)
|
add_definitions(-DIXWEBSOCKET_USE_TLS)
|
||||||
@ -65,6 +66,8 @@ if (USE_TLS)
|
|||||||
if (APPLE)
|
if (APPLE)
|
||||||
list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketAppleSSL.h)
|
list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketAppleSSL.h)
|
||||||
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketAppleSSL.cpp)
|
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketAppleSSL.cpp)
|
||||||
|
list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketOpenSSL.h)
|
||||||
|
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketOpenSSL.cpp)
|
||||||
elseif (WIN32)
|
elseif (WIN32)
|
||||||
list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketSChannel.h)
|
list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketSChannel.h)
|
||||||
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketSChannel.cpp)
|
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketSChannel.cpp)
|
||||||
|
@ -84,29 +84,29 @@ namespace ix
|
|||||||
_sockfd = -1;
|
_sockfd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::send(char* buffer, size_t length)
|
ssize_t Socket::send(char* buffer, size_t length)
|
||||||
{
|
{
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
#ifdef MSG_NOSIGNAL
|
#ifdef MSG_NOSIGNAL
|
||||||
flags = MSG_NOSIGNAL;
|
flags = MSG_NOSIGNAL;
|
||||||
#endif
|
#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());
|
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;
|
int flags = 0;
|
||||||
#ifdef MSG_NOSIGNAL
|
#ifdef MSG_NOSIGNAL
|
||||||
flags = MSG_NOSIGNAL;
|
flags = MSG_NOSIGNAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (int) ::recv(_sockfd, (char*) buffer, length, flags);
|
return ::recv(_sockfd, (char*) buffer, length, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::getErrno()
|
int Socket::getErrno()
|
||||||
|
@ -35,9 +35,9 @@ namespace ix
|
|||||||
const CancellationRequest& isCancellationRequested);
|
const CancellationRequest& isCancellationRequested);
|
||||||
virtual void close();
|
virtual void close();
|
||||||
|
|
||||||
virtual int send(char* buffer, size_t length);
|
virtual ssize_t send(char* buffer, size_t length);
|
||||||
virtual int send(const std::string& buffer);
|
virtual ssize_t send(const std::string& buffer);
|
||||||
virtual int recv(void* buffer, size_t length);
|
virtual ssize_t recv(void* buffer, size_t length);
|
||||||
|
|
||||||
// Blocking and cancellable versions, working with socket that can be set
|
// Blocking and cancellable versions, working with socket that can be set
|
||||||
// to non blocking mode. Used during HTTP upgrade.
|
// to non blocking mode. Used during HTTP upgrade.
|
||||||
|
@ -203,7 +203,7 @@ namespace ix
|
|||||||
Socket::close();
|
Socket::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SocketAppleSSL::send(char* buf, size_t nbyte)
|
ssize_t SocketAppleSSL::send(char* buf, size_t nbyte)
|
||||||
{
|
{
|
||||||
ssize_t ret = 0;
|
ssize_t ret = 0;
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
@ -218,16 +218,16 @@ namespace ix
|
|||||||
|
|
||||||
if (ret == 0 && errSSLClosedAbort != status)
|
if (ret == 0 && errSSLClosedAbort != status)
|
||||||
ret = -1;
|
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());
|
return send((char*)&buffer[0], buffer.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// No wait support
|
// No wait support
|
||||||
int SocketAppleSSL::recv(void* buf, size_t nbyte)
|
ssize_t SocketAppleSSL::recv(void* buf, size_t nbyte)
|
||||||
{
|
{
|
||||||
OSStatus status = errSSLWouldBlock;
|
OSStatus status = errSSLWouldBlock;
|
||||||
while (errSSLWouldBlock == status)
|
while (errSSLWouldBlock == status)
|
||||||
|
@ -28,9 +28,9 @@ namespace ix
|
|||||||
const CancellationRequest& isCancellationRequested) final;
|
const CancellationRequest& isCancellationRequested) final;
|
||||||
virtual void close() final;
|
virtual void close() final;
|
||||||
|
|
||||||
virtual int send(char* buffer, size_t length) final;
|
virtual ssize_t send(char* buffer, size_t length) final;
|
||||||
virtual int send(const std::string& buffer) final;
|
virtual ssize_t send(const std::string& buffer) final;
|
||||||
virtual int recv(void* buffer, size_t length) final;
|
virtual ssize_t recv(void* buffer, size_t length) final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SSLContextRef _sslContext;
|
SSLContextRef _sslContext;
|
||||||
|
@ -43,9 +43,9 @@ namespace ix
|
|||||||
{
|
{
|
||||||
errMsg = "no error";
|
errMsg = "no error";
|
||||||
|
|
||||||
int fd = socket(address->ai_family,
|
auto fd = socket(address->ai_family,
|
||||||
address->ai_socktype,
|
address->ai_socktype,
|
||||||
address->ai_protocol);
|
address->ai_protocol);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
errMsg = "Cannot create a socket";
|
errMsg = "Cannot create a socket";
|
||||||
|
@ -326,7 +326,7 @@ namespace ix
|
|||||||
Socket::close();
|
Socket::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SocketOpenSSL::send(char* buf, size_t nbyte)
|
ssize_t SocketOpenSSL::send(char* buf, size_t nbyte)
|
||||||
{
|
{
|
||||||
ssize_t sent = 0;
|
ssize_t sent = 0;
|
||||||
|
|
||||||
@ -340,7 +340,7 @@ namespace ix
|
|||||||
}
|
}
|
||||||
|
|
||||||
ERR_clear_error();
|
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);
|
int reason = SSL_get_error(_ssl_connection, write_result);
|
||||||
|
|
||||||
if (reason == SSL_ERROR_NONE) {
|
if (reason == SSL_ERROR_NONE) {
|
||||||
@ -353,16 +353,16 @@ namespace ix
|
|||||||
return -1;
|
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());
|
return send((char*)&buffer[0], buffer.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// No wait support
|
// No wait support
|
||||||
int SocketOpenSSL::recv(void* buf, size_t nbyte)
|
ssize_t SocketOpenSSL::recv(void* buf, size_t nbyte)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -374,7 +374,7 @@ namespace ix
|
|||||||
}
|
}
|
||||||
|
|
||||||
ERR_clear_error();
|
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)
|
if (read_result > 0)
|
||||||
{
|
{
|
||||||
|
@ -31,9 +31,9 @@ namespace ix
|
|||||||
const CancellationRequest& isCancellationRequested) final;
|
const CancellationRequest& isCancellationRequested) final;
|
||||||
virtual void close() final;
|
virtual void close() final;
|
||||||
|
|
||||||
virtual int send(char* buffer, size_t length) final;
|
virtual ssize_t send(char* buffer, size_t length) final;
|
||||||
virtual int send(const std::string& buffer) final;
|
virtual ssize_t send(const std::string& buffer) final;
|
||||||
virtual int recv(void* buffer, size_t length) final;
|
virtual ssize_t recv(void* buffer, size_t length) final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void openSSLInitialize();
|
void openSSLInitialize();
|
||||||
|
@ -60,7 +60,7 @@ namespace ix
|
|||||||
uint16_t code;
|
uint16_t code;
|
||||||
std::string reason;
|
std::string reason;
|
||||||
|
|
||||||
WebSocketCloseInfo(uint64_t c = 0,
|
WebSocketCloseInfo(uint16_t c = 0,
|
||||||
const std::string& r = std::string())
|
const std::string& r = std::string())
|
||||||
: code(c)
|
: code(c)
|
||||||
, reason(r)
|
, reason(r)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user