From c11524901b338a53eee2a9f0ae9caa834a5ee76c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 21 Mar 2008 20:24:36 +0000 Subject: single server socket --- src/core/netconnection.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/core/netconnection.cc') 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) { -- cgit v1.2.3