Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ixwebsocket/IXHttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ namespace ix
// Parse response:
if (headers.find("Content-Length") != headers.end())
{
ssize_t contentLength = -1;
std::ptrdiff_t contentLength = -1;
ss.str("");
ss << headers["Content-Length"];
ss >> contentLength;
Expand Down
4 changes: 2 additions & 2 deletions ixwebsocket/IXSelectInterruptPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace ix
int fd = _fildes[kPipeWriteIndex];
if (fd == -1) return false;

ssize_t ret = -1;
std::ptrdiff_t ret = -1;
do
{
ret = ::write(fd, &value, sizeof(value));
Expand All @@ -139,7 +139,7 @@ namespace ix

uint64_t value = 0;

ssize_t readret = -1;
std::ptrdiff_t readret = -1;
do
{
readret = ::read(fd, &value, sizeof(value));
Expand Down
12 changes: 6 additions & 6 deletions ixwebsocket/IXSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ namespace ix
_sockfd = -1;
}

ssize_t Socket::send(char* buffer, size_t length)
std::ptrdiff_t Socket::send(char* buffer, size_t length)
{
int flags = 0;
#ifdef MSG_NOSIGNAL
Expand All @@ -254,12 +254,12 @@ namespace ix
#endif
}

ssize_t Socket::send(const std::string& buffer)
std::ptrdiff_t Socket::send(const std::string& buffer)
{
return send((char*) &buffer[0], buffer.size());
}

ssize_t Socket::recv(void* buffer, size_t length)
std::ptrdiff_t Socket::recv(void* buffer, size_t length)
{
int flags = 0;
#ifdef MSG_NOSIGNAL
Expand Down Expand Up @@ -333,7 +333,7 @@ namespace ix
{
if (isCancellationRequested && isCancellationRequested()) return false;

ssize_t ret = send((char*) &str[offset], len);
std::ptrdiff_t ret = send((char*) &str[offset], len);

// We wrote some bytes, as needed, all good.
if (ret > 0)
Expand Down Expand Up @@ -368,7 +368,7 @@ namespace ix
{
if (isCancellationRequested && isCancellationRequested()) return false;

ssize_t ret;
std::ptrdiff_t ret;
ret = recv(buffer, 1);

// We read one byte, as needed, all good.
Expand Down Expand Up @@ -434,7 +434,7 @@ namespace ix
}

size_t size = std::min(readBuffer.size(), length - bytesRead);
ssize_t ret = recv((char*) &readBuffer[0], size);
std::ptrdiff_t ret = recv((char*) &readBuffer[0], size);

if (ret > 0)
{
Expand Down
18 changes: 4 additions & 14 deletions ixwebsocket/IXSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,13 @@
#pragma once

#include <atomic>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <mutex>
#include <string>

#ifdef __APPLE__
#include <sys/types.h>
#endif

#ifdef _WIN32
#include <basetsd.h>
#ifdef _MSC_VER
typedef SSIZE_T ssize_t;
#endif
#endif

#include "IXCancellationRequest.h"
#include "IXNetSystem.h"
#include "IXProgressCallback.h"
Expand Down Expand Up @@ -65,9 +55,9 @@ namespace ix
const CancellationRequest& isCancellationRequested);
virtual void close();

virtual ssize_t send(char* buffer, size_t length);
ssize_t send(const std::string& buffer);
virtual ssize_t recv(void* buffer, size_t length);
virtual std::ptrdiff_t send(char* buffer, size_t length);
std::ptrdiff_t send(const std::string& buffer);
virtual std::ptrdiff_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.
Expand Down
12 changes: 6 additions & 6 deletions ixwebsocket/IXSocketAppleSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace ix

size_t requested_sz = *len;

ssize_t status = read(fd, data, requested_sz);
std::ptrdiff_t status = read(fd, data, requested_sz);

if (status > 0)
{
Expand Down Expand Up @@ -123,7 +123,7 @@ namespace ix
assert(len != nullptr);

size_t to_write_sz = *len;
ssize_t status = write(fd, data, to_write_sz);
std::ptrdiff_t status = write(fd, data, to_write_sz);

if (status > 0)
{
Expand Down Expand Up @@ -251,7 +251,7 @@ namespace ix
Socket::close();
}

ssize_t SocketAppleSSL::send(char* buf, size_t nbyte)
std::ptrdiff_t SocketAppleSSL::send(char* buf, size_t nbyte)
{
OSStatus status = errSSLWouldBlock;
while (status == errSSLWouldBlock)
Expand All @@ -260,7 +260,7 @@ namespace ix
std::lock_guard<std::mutex> lock(_mutex);
status = SSLWrite(_sslContext, buf, nbyte, &processed);

if (processed > 0) return (ssize_t) processed;
if (processed > 0) return (std::ptrdiff_t) processed;

// The connection was reset, inform the caller that this
// Socket should close
Expand All @@ -281,7 +281,7 @@ namespace ix
}

// No wait support
ssize_t SocketAppleSSL::recv(void* buf, size_t nbyte)
std::ptrdiff_t SocketAppleSSL::recv(void* buf, size_t nbyte)
{
OSStatus status = errSSLWouldBlock;
while (status == errSSLWouldBlock)
Expand All @@ -290,7 +290,7 @@ namespace ix
std::lock_guard<std::mutex> lock(_mutex);
status = SSLRead(_sslContext, buf, nbyte, &processed);

if (processed > 0) return (ssize_t) processed;
if (processed > 0) return (std::ptrdiff_t) processed;

// The connection was reset, inform the caller that this
// Socket should close
Expand Down
4 changes: 2 additions & 2 deletions ixwebsocket/IXSocketAppleSSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace ix
const CancellationRequest& isCancellationRequested) final;
virtual void close() final;

virtual ssize_t send(char* buffer, size_t length) final;
virtual ssize_t recv(void* buffer, size_t length) final;
virtual std::ptrdiff_t send(char* buffer, size_t length) final;
virtual std::ptrdiff_t recv(void* buffer, size_t length) final;

private:
static std::string getSSLErrorDescription(OSStatus status);
Expand Down
8 changes: 4 additions & 4 deletions ixwebsocket/IXSocketMbedTLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ namespace ix
Socket::close();
}

ssize_t SocketMbedTLS::send(char* buf, size_t nbyte)
std::ptrdiff_t SocketMbedTLS::send(char* buf, size_t nbyte)
{
std::lock_guard<std::mutex> lock(_mutex);

ssize_t res = mbedtls_ssl_write(&_ssl, (unsigned char*) buf, nbyte);
std::ptrdiff_t res = mbedtls_ssl_write(&_ssl, (unsigned char*) buf, nbyte);

if (res > 0)
{
Expand All @@ -356,13 +356,13 @@ namespace ix
}
}

ssize_t SocketMbedTLS::recv(void* buf, size_t nbyte)
std::ptrdiff_t SocketMbedTLS::recv(void* buf, size_t nbyte)
{
while (true)
{
std::lock_guard<std::mutex> lock(_mutex);

ssize_t res = mbedtls_ssl_read(&_ssl, (unsigned char*) buf, (int) nbyte);
std::ptrdiff_t res = mbedtls_ssl_read(&_ssl, (unsigned char*) buf, (int) nbyte);

if (res > 0)
{
Expand Down
4 changes: 2 additions & 2 deletions ixwebsocket/IXSocketMbedTLS.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace ix
const CancellationRequest& isCancellationRequested) final;
virtual void close() final;

virtual ssize_t send(char* buffer, size_t length) final;
virtual ssize_t recv(void* buffer, size_t length) final;
virtual std::ptrdiff_t send(char* buffer, size_t length) final;
virtual std::ptrdiff_t recv(void* buffer, size_t length) final;

private:
mbedtls_ssl_context _ssl;
Expand Down
8 changes: 4 additions & 4 deletions ixwebsocket/IXSocketOpenSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ namespace ix
Socket::close();
}

ssize_t SocketOpenSSL::send(char* buf, size_t nbyte)
std::ptrdiff_t SocketOpenSSL::send(char* buf, size_t nbyte)
{
std::lock_guard<std::mutex> lock(_mutex);

Expand All @@ -828,7 +828,7 @@ namespace ix
}

ERR_clear_error();
ssize_t write_result = SSL_write(_ssl_connection, buf, (int) nbyte);
std::ptrdiff_t write_result = SSL_write(_ssl_connection, buf, (int) nbyte);
int reason = SSL_get_error(_ssl_connection, (int) write_result);

if (reason == SSL_ERROR_NONE)
Expand All @@ -846,7 +846,7 @@ namespace ix
}
}

ssize_t SocketOpenSSL::recv(void* buf, size_t nbyte)
std::ptrdiff_t SocketOpenSSL::recv(void* buf, size_t nbyte)
{
while (true)
{
Expand All @@ -858,7 +858,7 @@ namespace ix
}

ERR_clear_error();
ssize_t read_result = SSL_read(_ssl_connection, buf, (int) nbyte);
std::ptrdiff_t read_result = SSL_read(_ssl_connection, buf, (int) nbyte);

if (read_result > 0)
{
Expand Down
4 changes: 2 additions & 2 deletions ixwebsocket/IXSocketOpenSSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace ix
const CancellationRequest& isCancellationRequested) final;
virtual void close() final;

virtual ssize_t send(char* buffer, size_t length) final;
virtual ssize_t recv(void* buffer, size_t length) final;
virtual std::ptrdiff_t send(char* buffer, size_t length) final;
virtual std::ptrdiff_t recv(void* buffer, size_t length) final;

private:
void openSSLInitialize();
Expand Down
8 changes: 4 additions & 4 deletions ixwebsocket/IXUdpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ namespace ix
return true;
}

ssize_t UdpSocket::sendto(const std::string& buffer)
std::ptrdiff_t UdpSocket::sendto(const std::string& buffer)
{
return (ssize_t)::sendto(
return (std::ptrdiff_t)::sendto(
_sockfd, buffer.data(), static_cast<int>(buffer.size()), 0, (struct sockaddr*) &_server, sizeof(_server));
}

ssize_t UdpSocket::recvfrom(char* buffer, size_t length)
std::ptrdiff_t UdpSocket::recvfrom(char* buffer, size_t length)
{
#ifdef _WIN32
int addressLen = (int) sizeof(_server);
#else
socklen_t addressLen = (socklen_t) sizeof(_server);
#endif
return (ssize_t)::recvfrom(
return (std::ptrdiff_t)::recvfrom(
_sockfd, buffer, static_cast<int>(length), 0, (struct sockaddr*) &_server, &addressLen);
}
} // namespace ix
12 changes: 3 additions & 9 deletions ixwebsocket/IXUdpSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@
#pragma once

#include <atomic>
#include <cstddef>
#include <memory>
#include <string>

#ifdef _WIN32
#include <basetsd.h>
#ifdef _MSC_VER
typedef SSIZE_T ssize_t;
#endif
#endif

#include "IXNetSystem.h"

namespace ix
Expand All @@ -29,8 +23,8 @@ namespace ix

// Virtual methods
bool init(const std::string& host, int port, std::string& errMsg);
ssize_t sendto(const std::string& buffer);
ssize_t recvfrom(char* buffer, size_t length);
std::ptrdiff_t sendto(const std::string& buffer);
std::ptrdiff_t recvfrom(char* buffer, size_t length);

void close();

Expand Down
4 changes: 2 additions & 2 deletions ixwebsocket/IXWebSocketTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ namespace ix

while (_txbuf.size())
{
ssize_t ret = 0;
std::ptrdiff_t ret = 0;
{
std::lock_guard<std::mutex> lock(_socketMutex);
ret = _socket->send((char*) &_txbuf[0], _txbuf.size());
Expand Down Expand Up @@ -1116,7 +1116,7 @@ namespace ix
// There's also no point in reading more bytes than needed.
if (_rxbufWanted > 0 && _rxbuf.size() >= _rxbufWanted) break;

ssize_t ret = _socket->recv((char*) &_readbuf[0], _readbuf.size());
std::ptrdiff_t ret = _socket->recv((char*) &_readbuf[0], _readbuf.size());

if (ret < 0 && Socket::isWaitNeeded())
{
Expand Down
Loading