Skip to content

Conversation

@amdrozdov
Copy link
Collaborator

No description provided.

@amdrozdov
Copy link
Collaborator Author

Implemented socket timeout for ClientSocket in posix.h implementation, added tests cases and compatibility test.

adrozdov@workstation ~/CLionProjects/Current/bricks/net/tcp
 % make coverage
"/home/adrozdov/CLionProjects/Current/scripts/coverage-report.sh"
test.cc: Generating coverage report.
[==========] Running 18 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 18 tests from TCPTest
[ RUN      ] TCPTest.IPAndPort
[       OK ] TCPTest.IPAndPort (2 ms)
[ RUN      ] TCPTest.ReceiveMessage
[       OK ] TCPTest.ReceiveMessage (0 ms)
[ RUN      ] TCPTest.ReceiveMessageOfTwoParts
[       OK ] TCPTest.ReceiveMessageOfTwoParts (0 ms)
[ RUN      ] TCPTest.ReceiveDelayedMessage
[       OK ] TCPTest.ReceiveDelayedMessage (2 ms)
[ RUN      ] TCPTest.SocketReadTimeoutFailed
[       OK ] TCPTest.SocketReadTimeoutFailed (21 ms)
[ RUN      ] TCPTest.SocketReadTimeoutCompatibility
[       OK ] TCPTest.SocketReadTimeoutCompatibility (1101 ms)
[ RUN      ] TCPTest.SocketReadTimeoutOK
[       OK ] TCPTest.SocketReadTimeoutOK (6 ms)
[ RUN      ] TCPTest.ReceiveMessageAsResponse
[       OK ] TCPTest.ReceiveMessageAsResponse (0 ms)
[ RUN      ] TCPTest.CanNotUseMovedAwayConnection
[       OK ] TCPTest.CanNotUseMovedAwayConnection (1 ms)
[ RUN      ] TCPTest.ReceiveMessageOfTwoUInt16AndTestEndianness
[       OK ] TCPTest.ReceiveMessageOfTwoUInt16AndTestEndianness (1 ms)
[ RUN      ] TCPTest.EchoMessage
[       OK ] TCPTest.EchoMessage (0 ms)
[ RUN      ] TCPTest.EchoThreeMessages
[       OK ] TCPTest.EchoThreeMessages (3 ms)
[ RUN      ] TCPTest.EchoLongMessageTestsDynamicBufferGrowth
[       OK ] TCPTest.EchoLongMessageTestsDynamicBufferGrowth (6 ms)
[ RUN      ] TCPTest.ResolveAddress
[       OK ] TCPTest.ResolveAddress (141 ms)
[ RUN      ] TCPTest.CanNotBindTwoSocketsToTheSamePortSimultaneously
[       OK ] TCPTest.CanNotBindTwoSocketsToTheSamePortSimultaneously (0 ms)
[ RUN      ] TCPTest.WriteExceptionWhileWritingAVeryLongMessage
[       OK ] TCPTest.WriteExceptionWhileWritingAVeryLongMessage (52 ms)
[ RUN      ] TCPTest.PickLocalPort
[       OK ] TCPTest.PickLocalPort (0 ms)
[ RUN      ] TCPTest.PickLocalPortWithHint
[       OK ] TCPTest.PickLocalPortWithHint (0 ms)
[----------] 18 tests from TCPTest (1337 ms total)

[----------] Global test environment tear-down
[==========] 18 tests from 1 test case ran. (1337 ms total)
[  PASSED  ] 18 tests.


CURRENT_BRICKS_NET_LOG("S%05d connect() ...\n", static_cast<SOCKET>(socket));

setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &read_timeout, sizeof(read_timeout));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe skip these calls if the {read,write}_timeout are at their default value? To not change the behavior at all. Who knows what other OSes and/or platforms can do with these seemingly benign calls?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will add default a 0,0 and block

if (*_timeout.s > 0 || *_timeout.u > 0) {
    setsockopt(...)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, ready to merge

@dkorolev dkorolev merged commit 4248e24 into C5T:stable Nov 18, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants