Skip to content

Commit 74b2443

Browse files
authored
Merge branch 'master' into use-auditwheel
2 parents 47abcb0 + 80ab6d3 commit 74b2443

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/network/linkers_socket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void Linkers::Construct() {
184184
}
185185

186186
// start listener
187-
listener_->SetTimeout(socket_timeout_);
187+
listener_->SetTimeout(socket_timeout_ * 1000 * 60);
188188
listener_->Listen(incoming_cnt);
189189
std::thread listen_thread(&Linkers::ListenThread, this, incoming_cnt);
190190
const int connect_fail_constant_factor = 20;

src/network/socket_wrapper.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <unistd.h>
3737

3838
#include <ifaddrs.h>
39+
#include <sys/time.h>
3940

4041
#endif // defined(_WIN32)
4142

@@ -117,8 +118,16 @@ class TcpSocket {
117118
}
118119
~TcpSocket() {
119120
}
120-
inline void SetTimeout(int timeout) {
121-
setsockopt(sockfd_, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<char*>(&timeout), sizeof(timeout));
121+
inline void SetTimeout(int timeout_ms) {
122+
#if defined(_WIN32)
123+
DWORD timeout = static_cast<DWORD>(timeout_ms);
124+
setsockopt(sockfd_, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<const char*>(&timeout), sizeof(timeout));
125+
#else
126+
struct timeval tv;
127+
tv.tv_sec = timeout_ms / 1000;
128+
tv.tv_usec = (timeout_ms % 1000) * 1000;
129+
setsockopt(sockfd_, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
130+
#endif
122131
}
123132
inline void ConfigSocket() {
124133
if (sockfd_ == INVALID_SOCKET) {

0 commit comments

Comments
 (0)