Skip to content

Commit

Permalink
Socket: remove wait helper members
Browse files Browse the repository at this point in the history
  • Loading branch information
mporsch committed Aug 5, 2023
1 parent acf720d commit a16f587
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/socket_buffered_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ BufferPtr SocketBufferedImpl::GetBuffer()

std::optional<BufferPtr> SocketBufferedImpl::Receive(Duration timeout)
{
if(!this->sock->WaitReadable(timeout)) {
if(!WaitReadableBlocking(this->sock->fd, timeout)) {
return {std::nullopt}; // timeout exceeded
}
return SocketBufferedImpl::Receive();
Expand All @@ -46,7 +46,7 @@ BufferPtr SocketBufferedImpl::Receive()
std::optional<std::pair<BufferPtr, Address>>
SocketBufferedImpl::ReceiveFrom(Duration timeout)
{
if(!this->sock->WaitReadable(timeout)) {
if(!WaitReadableBlocking(this->sock->fd, timeout)) {
return {std::nullopt}; // timeout exceeded
}
return SocketBufferedImpl::ReceiveFrom();
Expand Down
16 changes: 3 additions & 13 deletions src/socket_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ size_t SocketImpl::Receive(char *data, size_t size)
std::optional<std::pair<size_t, Address>>
SocketImpl::ReceiveFrom(char *data, size_t size, Duration timeout)
{
if(!WaitReadable(timeout)) {
if(!WaitReadableBlocking(fd, timeout)) {
return {std::nullopt}; // timeout exceeded
}
return {ReceiveFrom(data, size)};
Expand Down Expand Up @@ -206,7 +206,7 @@ size_t SocketImpl::SendSome(char const *data, size_t size)
size_t SocketImpl::SendTo(char const *data, size_t size,
SockAddrView const &dstAddr, Duration timeout)
{
if(!WaitWritable(timeout)) {
if(!WaitWritableBlocking(fd, timeout)) {
return 0U; // timeout exceeded
}
return SendTo(data, size, dstAddr);
Expand Down Expand Up @@ -255,7 +255,7 @@ void SocketImpl::Listen()
std::optional<std::pair<SocketTcp, Address>>
SocketImpl::Accept(Duration timeout)
{
if(!WaitReadable(timeout)) {
if(!WaitReadableBlocking(fd, timeout)) {
return {std::nullopt}; // timeout exceeded
}
return Accept();
Expand All @@ -271,16 +271,6 @@ std::pair<SocketTcp, Address> SocketImpl::Accept()
};
}

bool SocketImpl::WaitReadable(Duration timeout)
{
return WaitReadableBlocking(fd, timeout);
}

bool SocketImpl::WaitWritable(Duration timeout)
{
return WaitWritableBlocking(fd, timeout);
}

void SocketImpl::SetSockOptNonBlocking()
{
SetBlocking(fd, false, "failed to set socket option non-blocking");
Expand Down
3 changes: 0 additions & 3 deletions src/socket_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ struct SocketImpl
Accept(Duration timeout);
virtual std::pair<SocketTcp, Address> Accept();

bool WaitReadable(Duration timeout);
bool WaitWritable(Duration timeout);

void SetSockOptNonBlocking();
void SetSockOptReuseAddr();
void SetSockOptBroadcast();
Expand Down
6 changes: 3 additions & 3 deletions src/socket_tls_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,15 @@ bool SocketTlsImpl::HandleError(int error)
return true;
case SSL_ERROR_WANT_READ:
return std::visit([this](auto &&d) -> bool {
auto readable = WaitReadable(d.Remaining());
auto readable = WaitReadableBlocking(fd, d.Remaining());
d.Tick();
return readable;
}, deadline);
case SSL_ERROR_WANT_WRITE:
return std::visit([this](auto &&d) -> bool {
auto readable = WaitWritable(d.Remaining());
auto writable = WaitWritableBlocking(fd, d.Remaining());
d.Tick();
return readable;
return writable;
}, deadline);
case SSL_ERROR_SSL:
throw std::system_error(SslError(error), errorMessage);
Expand Down

0 comments on commit a16f587

Please sign in to comment.