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/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)
|
||||
|
@ -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()
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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";
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user