From: ehofman Date: Sun, 14 Dec 2003 14:45:29 +0000 (+0000) Subject: Melchior FRANZ: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=79d1aaf7f58c113e92afd8e6359cf7cf3be55484;p=simgear.git Melchior FRANZ: There's another problem with sg_socket.cxx: the timeout value is hardcoded as 0. This is appropriate for servers as they continuously poll the socket and never want to wait for clients. But clients *do* want to wait a few seconds for a server response. --- diff --git a/simgear/io/sg_socket.cxx b/simgear/io/sg_socket.cxx index 4012d71a..7407f6ec 100644 --- a/simgear/io/sg_socket.cxx +++ b/simgear/io/sg_socket.cxx @@ -42,7 +42,8 @@ SGSocket::SGSocket( const string& host, const string& port_, client(0), is_tcp(false), is_server(false), - first_read(false) + first_read(false), + timeout(0) { if (!init) { @@ -386,7 +387,7 @@ SGSocket::poll() netSocket* writers[1]; writers[0] = 0; - int result = netSocket::select( readers, writers, 0 ); + int result = netSocket::select( readers, writers, timeout ); if (result > 0 && is_server && client == 0) { diff --git a/simgear/io/sg_socket.hxx b/simgear/io/sg_socket.hxx index 4e1d9e05..704e67d3 100644 --- a/simgear/io/sg_socket.hxx +++ b/simgear/io/sg_socket.hxx @@ -64,6 +64,7 @@ private: bool is_tcp; bool is_server; bool first_read; + int timeout; static bool init; @@ -156,6 +157,9 @@ public: */ bool nonblock(); + // set timeout (default: 0) + inline void set_timeout(int i) { timeout = i; } + /** @return the remote host name */ inline string get_hostname() const { return hostname; }