Skip to content

Commit

Permalink
fix(SecureSocket): Refactor detection of timeout when reading, writin…
Browse files Browse the repository at this point in the history
…g and handshaking (#4510)

* fix(SecureSocket): Refactor detection of timeout when reading, writing or handshaking. (#3725)

* enh(SecureSocket): some trivial C++17 modernisation changes.

* chore: indentation and compiler warning

---------

Co-authored-by: Alex Fabijanic <alex@pocoproject.org>
  • Loading branch information
matejk and aleks-f committed Mar 26, 2024
1 parent 2b8f3e1 commit c6a171d
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 100 deletions.
10 changes: 5 additions & 5 deletions Net/src/SocketImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ SocketImpl* SocketImpl::acceptConnection(SocketAddress& clientAddr)
return new StreamSocketImpl(sd);
}
error(); // will throw
return 0;
return nullptr;
}


Expand Down Expand Up @@ -527,7 +527,7 @@ int SocketImpl::sendTo(const SocketBufVec& buffers, const SocketAddress& address
msgHdr.msg_namelen = address.length();
msgHdr.msg_iov = const_cast<iovec*>(&buffers[0]);
msgHdr.msg_iovlen = buffers.size();
msgHdr.msg_control = 0;
msgHdr.msg_control = nullptr;
msgHdr.msg_controllen = 0;
msgHdr.msg_flags = flags;
rc = sendmsg(_sockfd, &msgHdr, flags);
Expand Down Expand Up @@ -613,7 +613,7 @@ int SocketImpl::receiveFrom(SocketBufVec& buffers, struct sockaddr** pSA, poco_s
msgHdr.msg_namelen = **ppSALen;
msgHdr.msg_iov = &buffers[0];
msgHdr.msg_iovlen = buffers.size();
msgHdr.msg_control = 0;
msgHdr.msg_control = nullptr;
msgHdr.msg_controllen = 0;
msgHdr.msg_flags = flags;
rc = recvmsg(_sockfd, &msgHdr, flags);
Expand Down Expand Up @@ -652,7 +652,7 @@ int SocketImpl::available()
if (result && (type() == SOCKET_TYPE_DATAGRAM))
{
std::vector<char> buf(result);
result = recvfrom(sockfd(), &buf[0], result, MSG_PEEK, NULL, NULL);
result = recvfrom(sockfd(), &buf[0], result, MSG_PEEK, nullptr, nullptr);
}
#endif
return result;
Expand Down Expand Up @@ -1114,7 +1114,7 @@ void SocketImpl::setReusePort(bool flag)
int value = flag ? 1 : 0;
setOption(SOL_SOCKET, SO_REUSEPORT, value);
}
catch (IOException&)
catch (const IOException&)
{
// ignore error, since not all implementations
// support SO_REUSEPORT, even if the macro
Expand Down
2 changes: 1 addition & 1 deletion NetSSL_OpenSSL/include/Poco/Net/SecureStreamSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class NetSSL_API SecureStreamSocket: public StreamSocket
/// a SecureStreamSocketImpl, otherwise an InvalidArgumentException
/// will be thrown.

virtual ~SecureStreamSocket();
~SecureStreamSocket() override;
/// Destroys the StreamSocket.

SecureStreamSocket& operator = (const Socket& socket);
Expand Down
36 changes: 18 additions & 18 deletions NetSSL_OpenSSL/include/Poco/Net/SecureStreamSocketImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,97 +39,97 @@ class NetSSL_API SecureStreamSocketImpl: public StreamSocketImpl
SecureStreamSocketImpl(StreamSocketImpl* pStreamSocket, Context::Ptr pContext);
/// Creates the SecureStreamSocketImpl.

SocketImpl* acceptConnection(SocketAddress& clientAddr);
SocketImpl* acceptConnection(SocketAddress& clientAddr) override;
/// Not supported by a SecureStreamSocket.
///
/// Throws a Poco::InvalidAccessException.

void connect(const SocketAddress& address);
void connect(const SocketAddress& address) override;
/// Initializes the socket and establishes a connection to
/// the TCP server at the given address.
///
/// Can also be used for UDP sockets. In this case, no
/// connection is established. Instead, incoming and outgoing
/// packets are restricted to the specified address.

void connect(const SocketAddress& address, const Poco::Timespan& timeout);
void connect(const SocketAddress& address, const Poco::Timespan& timeout) override;
/// Initializes the socket, sets the socket timeout and
/// establishes a connection to the TCP server at the given address.

void connectNB(const SocketAddress& address);
void connectNB(const SocketAddress& address) override;
/// Initializes the socket and establishes a connection to
/// the TCP server at the given address. Prior to opening the
/// connection the socket is set to nonblocking mode.

void bind(const SocketAddress& address, bool reuseAddress = false);
void bind(const SocketAddress& address, bool reuseAddress = false) override;
/// Not supported by a SecureStreamSocket.
///
/// Throws a Poco::InvalidAccessException.

void listen(int backlog = 64);
void listen(int backlog = 64) override;
/// Not supported by a SecureStreamSocket.
///
/// Throws a Poco::InvalidAccessException.

void close();
void close() override;
/// Close the socket.

int sendBytes(const void* buffer, int length, int flags = 0);
int sendBytes(const void* buffer, int length, int flags = 0) override;
/// Sends the contents of the given buffer through
/// the socket. Any specified flags are ignored.
///
/// Returns the number of bytes sent, which may be
/// less than the number of bytes specified.

int receiveBytes(void* buffer, int length, int flags = 0);
int receiveBytes(void* buffer, int length, int flags = 0) override;
/// Receives data from the socket and stores it
/// in buffer. Up to length bytes are received.
///
/// Returns the number of bytes received.

int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0);
int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0) override;
/// Not supported by a SecureStreamSocket.
///
/// Throws a Poco::InvalidAccessException.

int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0);
int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0) override;
/// Not supported by a SecureStreamSocket.
///
/// Throws a Poco::InvalidAccessException.

void sendUrgent(unsigned char data);
void sendUrgent(unsigned char data) override;
/// Not supported by a SecureStreamSocket.
///
/// Throws a Poco::InvalidAccessException.

int available();
int available() override;
/// Returns the number of bytes available that can be read
/// without causing the socket to block.
///
/// For an SSL connection, returns the number of bytes that
/// can be read from the currently buffered SSL record,
/// before a new record is read from the underlying socket.

void shutdownReceive();
void shutdownReceive() override;
/// Shuts down the receiving part of the socket connection.
///
/// Since SSL does not support a half shutdown, this does
/// nothing.

void shutdownSend();
void shutdownSend() override;
/// Shuts down the receiving part of the socket connection.
///
/// Since SSL does not support a half shutdown, this does
/// nothing.

void shutdown();
void shutdown() override;
/// Shuts down the SSL connection.

void abort();
/// Aborts the connection by closing the underlying
/// TCP connection. No orderly SSL shutdown is performed.

bool secure() const;
bool secure() const override;
/// Returns true iff the socket's connection is secure
/// (using SSL or TLS).

Expand Down Expand Up @@ -203,7 +203,7 @@ class NetSSL_API SecureStreamSocketImpl: public StreamSocketImpl
void connectSSL();
/// Performs a SSL client-side handshake on an already connected TCP socket.

~SecureStreamSocketImpl();
~SecureStreamSocketImpl() override;
/// Destroys the SecureStreamSocketImpl.

static int lastError();
Expand Down
Loading

0 comments on commit c6a171d

Please sign in to comment.