Don't wait forever

This commit is contained in:
simon.kagstrom 2009-02-08 11:52:09 +00:00
parent 09bca43d1c
commit 331320c6e5
3 changed files with 25 additions and 4 deletions

View File

@ -103,14 +103,28 @@ void C64::c64_ctor1(void)
this->peer = NULL;
if (fixme_tmp_network_server) {
int i;
this->peer = new Network("localhost", this->server_port, true);
this->network_connection_type = MASTER;
for (i = 0; i < 20; i++)
{
printf("Waiting for connection, try %d of 20\n", i+1);
if (this->peer->WaitForConnection() == true)
break;
}
if (i == 20)
{
printf("No client connected. Bye\n");
delete this->peer;
this->peer = NULL;
}
}
if (fixme_tmp_network_client)
{
strcpy(this->server_hostname, fixme_tmp_network_client);
this->peer = new Network(this->server_hostname, this->server_port, false);
this->network_connection_type = CLIENT;
this->peer->ConnectToPeer();
}
}

View File

@ -496,9 +496,9 @@ bool Network::ReceiveUpdate()
return this->ReceiveUpdate(this->ud, NETWORK_UPDATE_SIZE, &tv);
}
bool Network::ReceiveUpdateBlocking()
bool Network::ReceiveUpdate(struct timeval *tv)
{
return this->ReceiveUpdate(this->ud, NETWORK_UPDATE_SIZE, NULL);
return this->ReceiveUpdate(this->ud, NETWORK_UPDATE_SIZE, tv);
}
bool Network::ReceiveUpdate(NetworkUpdate *dst, size_t total_sz,
@ -749,7 +749,14 @@ bool Network::DecodeUpdate(uint8 *screen, uint8 *js)
bool Network::WaitForConnection()
{
return this->ReceiveUpdateBlocking();
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
if (this->ReceiveUpdate(&tv) == true)
return true;
return false;
}
bool Network::ConnectToPeer()

View File

@ -140,7 +140,7 @@ public:
bool ReceiveUpdate();
bool ReceiveUpdateBlocking();
bool ReceiveUpdate(struct timeval *tv);
static bool StartNetworkServer(int port);