Skip to content

Commit

Permalink
Add preference for ezsockets timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram authored Jun 22, 2018
1 parent f42e255 commit 3e4b2e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ezsockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "global.h"

#include "ezsockets.h"
#include "Preference.h"
#include <iostream>

#if defined(_MSC_VER) // We need the WinSock32 Library on Windows
Expand Down Expand Up @@ -36,6 +37,8 @@
#define INVALID_SOCKET (-1)
#endif

static Preference<unsigned int> timeoutSeconds("ConnectionSecondsTimeout", 5);

// Returns a timeval set to the given number of milliseconds.
inline timeval timevalFromMs(unsigned int ms)
{
Expand Down Expand Up @@ -100,7 +103,9 @@ bool EzSockets::create(int Protocol, int Type)
state = skDISCONNECTED;
sock = socket(AF_INET, Type, Protocol);
if (sock > SOCKET_NONE) {
struct timeval tv = { 2, 0 };
struct timeval tv;
tv.tv_sec = timeoutSeconds;
tv.tv_usec = 0;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(struct timeval));
}
lastCode = sock;
Expand Down

0 comments on commit 3e4b2e5

Please sign in to comment.