Skip to content

Commit

Permalink
HPCC-31474 Refactor socket readtms/writtms code to handle nonblocking
Browse files Browse the repository at this point in the history
Cleanup and refactor the jsocket and securesocket readtms/writetms
and derivatives to cope with nonblocking sockets.

Symantically they remain the same.
e.g. readtms will not return until it has written at least min_size.
Duplicate/very similar code in dedupped/consolidated into readtms
and writetms

1) in non-blocking mode, readtms would fire an exception if socket
not ready (EWOULDBLOCK, EAGAIN).
2) jsocket writetms would temporarily place a non-blocking socket
into nonblocking mode.
Now writetms takes a minSize (akin to readtms minSize). It will
return if at least this much is written (but normal usage is with
min=max).
NB: previous writetms in both implementations were
not called anywhere.
3) in non-blocking mode securesocket readtms and writetms would
previously fail if blocked

Signed-off-by: Jake Smith <[email protected]>
  • Loading branch information
jakesmith committed Apr 11, 2024
1 parent 98a711e commit 3a5e979
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 649 deletions.
2 changes: 1 addition & 1 deletion fs/dafsclient/rmtclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ void CRemoteBase::connectSocket(SocketEndpoint &ep, unsigned connectTimeoutMs, u
{
unsigned remaining;
if (tm.timemon->timedout(&remaining))
throwJSocketException(JSOCKERR_connection_failed);
THROWJSOCKEXCEPTION(JSOCKERR_connection_failed);
socket.setown(ISocket::connect_timeout(ep,remaining));
}
else
Expand Down
272 changes: 93 additions & 179 deletions fs/dafsserver/dafsserver.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion roxie/udplib/udpsha.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class CSocketSimulator : public CInterfaceOf<ISocket>
unsigned timeout) override { UNIMPLEMENTED; }
virtual void read(void* buf, size32_t size) override { UNIMPLEMENTED; }
virtual size32_t write(void const* buf, size32_t size) override { UNIMPLEMENTED; }
virtual size32_t writetms(void const* buf, size32_t size, unsigned timeoutms=WAIT_FOREVER) override { UNIMPLEMENTED; }
virtual size32_t writetms(void const* buf, size32_t minSize, size32_t size, unsigned timeoutms=WAIT_FOREVER) override { UNIMPLEMENTED; }

virtual size32_t get_max_send_size() override { UNIMPLEMENTED; }
virtual ISocket* accept(bool allowcancel=false, SocketEndpoint *peerEp = nullptr) override { UNIMPLEMENTED; }
Expand Down
9 changes: 9 additions & 0 deletions system/jlib/jdebug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ class CCycleTimer
{
return static_cast<unsigned>(cycle_to_millisec(elapsedCycles()));
}
inline unsigned remainingMs(unsigned timeoutMs) const
{
if (INFINITE == timeoutMs)
return INFINITE;
unsigned eMs = elapsedMs();
if (eMs >= timeoutMs)
return 0;
return timeoutMs - eMs;
}
};
inline cycle_t queryOneSecCycles() { return oneSecInCycles; }

Expand Down
Loading

0 comments on commit 3a5e979

Please sign in to comment.