Skip to content

Commit 3e4b2e5

Browse files
authored
Add preference for ezsockets timeout
1 parent f42e255 commit 3e4b2e5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/ezsockets.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "global.h"
1010

1111
#include "ezsockets.h"
12+
#include "Preference.h"
1213
#include <iostream>
1314

1415
#if defined(_MSC_VER) // We need the WinSock32 Library on Windows
@@ -36,6 +37,8 @@
3637
#define INVALID_SOCKET (-1)
3738
#endif
3839

40+
static Preference<unsigned int> timeoutSeconds("ConnectionSecondsTimeout", 5);
41+
3942
// Returns a timeval set to the given number of milliseconds.
4043
inline timeval timevalFromMs(unsigned int ms)
4144
{
@@ -100,7 +103,9 @@ bool EzSockets::create(int Protocol, int Type)
100103
state = skDISCONNECTED;
101104
sock = socket(AF_INET, Type, Protocol);
102105
if (sock > SOCKET_NONE) {
103-
struct timeval tv = { 2, 0 };
106+
struct timeval tv;
107+
tv.tv_sec = timeoutSeconds;
108+
tv.tv_usec = 0;
104109
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(struct timeval));
105110
}
106111
lastCode = sock;

0 commit comments

Comments
 (0)