Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-21 20:24:36 +0000
committerStijn Buys <ingar@osirion.org>2008-03-21 20:24:36 +0000
commitc11524901b338a53eee2a9f0ae9caa834a5ee76c (patch)
tree99082d805d4293706c3c0a7c67b6ee6b58a6e21a /src/core/netconnection.cc
parent549f90727d321cd6cf8850e8b510beba36925a82 (diff)
single server socket
Diffstat (limited to 'src/core/netconnection.cc')
-rw-r--r--src/core/netconnection.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index 379df14..e3b4c69 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -17,6 +17,7 @@ namespace core
NetConnection::NetConnection()
{
+ timeout = core::application()->time();
}
NetConnection::~NetConnection()
@@ -61,20 +62,13 @@ void NetConnection::connect(std::string const &to_host, int to_port)
server_addr.sin_port = htons(to_port);
// FIXME inet_addr can still fail
server_addr.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *)serverhostent->h_addr)));
+ memset(server_addr.sin_zero, '\0', sizeof server_addr.sin_zero);
if (server_addr.sin_addr.s_addr == INADDR_NONE) {
con_error << "Network invalid address " << to_host << "!" << std::endl;
abort();
return;
}
- memset(server_addr.sin_zero, '\0', sizeof server_addr.sin_zero);
- /*
- if (::connect(connection_fd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) != 0) {
- //con_error << "Network connect() failed!" << std::endl;
- abort();
- return;
- }
- */
connection_host = to_host;
connection_port = to_port;
@@ -83,6 +77,7 @@ void NetConnection::connect(std::string const &to_host, int to_port)
FD_ZERO(&clientset);
FD_SET(fd(), &clientset);
+ timeout = core::application()->time();
game()->localplayer()->player_dirty = true;
}
@@ -129,6 +124,7 @@ void NetConnection::receive()
memset(recvbuf, '\0', BLOCKSIZE);
bytes_received = ::recv(connection_fd, recvbuf, BLOCKSIZE-1, 0);
+ timeout = core::application()->time();
if (bytes_received == 0) {
con_print << "Disconnected.";
@@ -172,6 +168,12 @@ void NetConnection::frame(float seconds)
int nb = select(fd()+1, &readset, NULL, NULL, &timeout);
if (nb == 0) {
+ /*
+ if (timout + TIMEOUT < core::application()->time()) {
+ con_error << "Connection time out\n";
+ abort();
+ }
+ */
return;
}
if (nb == -1) {