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.
This commit is contained in:
ehofman 2003-12-14 14:45:29 +00:00
parent a659969bcf
commit 79d1aaf7f5
2 changed files with 7 additions and 2 deletions

View File

@ -42,7 +42,8 @@ SGSocket::SGSocket( const string& host, const string& port_,
client(0), client(0),
is_tcp(false), is_tcp(false),
is_server(false), is_server(false),
first_read(false) first_read(false),
timeout(0)
{ {
if (!init) if (!init)
{ {
@ -386,7 +387,7 @@ SGSocket::poll()
netSocket* writers[1]; netSocket* writers[1];
writers[0] = 0; writers[0] = 0;
int result = netSocket::select( readers, writers, 0 ); int result = netSocket::select( readers, writers, timeout );
if (result > 0 && is_server && client == 0) if (result > 0 && is_server && client == 0)
{ {

View File

@ -64,6 +64,7 @@ private:
bool is_tcp; bool is_tcp;
bool is_server; bool is_server;
bool first_read; bool first_read;
int timeout;
static bool init; static bool init;
@ -156,6 +157,9 @@ public:
*/ */
bool nonblock(); bool nonblock();
// set timeout (default: 0)
inline void set_timeout(int i) { timeout = i; }
/** @return the remote host name */ /** @return the remote host name */
inline string get_hostname() const { return hostname; } inline string get_hostname() const { return hostname; }