MCPcopy Create free account
hub / github.com/apache/thrift / setGenericTimeout

Function setGenericTimeout

lib/cpp/src/thrift/transport/TSocket.cpp:768–792  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

766}
767
768void setGenericTimeout(THRIFT_SOCKET s, int timeout_ms, int optname) {
769 if (timeout_ms < 0) {
770 char errBuf[512];
771 sprintf(errBuf, "TSocket::setGenericTimeout with negative input: %d\n", timeout_ms);
772 TOutput::instance()(errBuf);
773 return;
774 }
775
776 if (s == THRIFT_INVALID_SOCKET) {
777 return;
778 }
779
780#ifdef _WIN32
781 DWORD platform_time = static_cast<DWORD>(timeout_ms);
782#else
783 struct timeval platform_time = {(int)(timeout_ms / 1000), (int)((timeout_ms % 1000) * 1000)};
784#endif
785
786 int ret = setsockopt(s, SOL_SOCKET, optname, cast_sockopt(&platform_time), sizeof(platform_time));
787 if (ret == -1) {
788 int errno_copy
789 = THRIFT_GET_SOCKET_ERROR; // Copy THRIFT_GET_SOCKET_ERROR because we're allocating memory.
790 TOutput::instance().perror("TSocket::setGenericTimeout() setsockopt() ", errno_copy);
791 }
792}
793
794void TSocket::setRecvTimeout(int ms) {
795 setGenericTimeout(socket_, ms, SO_RCVTIMEO);

Callers 2

setRecvTimeoutMethod · 0.85
setSendTimeoutMethod · 0.85

Calls 2

cast_sockoptFunction · 0.70
perrorMethod · 0.45

Tested by

no test coverage detected