Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-17 18:59:52 +0000
committerStijn Buys <ingar@osirion.org>2008-02-17 18:59:52 +0000
commit982562fa19bb87a3dab352e562f386f61c171b7b (patch)
treeaeade8d5b7d3c68f5c222af1d8ecc6a734e1b43f /src/net
parentd198b7b8d9ff713d891f35ab173d1f428f610e7d (diff)
major rewrite of Cvar, Func and Entity
Diffstat (limited to 'src/net')
-rw-r--r--src/net/tcpclient.cc23
-rw-r--r--src/net/tcpclient.h14
2 files changed, 20 insertions, 17 deletions
diff --git a/src/net/tcpclient.cc b/src/net/tcpclient.cc
index b8aa9dd..c148e90 100644
--- a/src/net/tcpclient.cc
+++ b/src/net/tcpclient.cc
@@ -25,9 +25,10 @@ TCPClient::TCPClient(int tcpclientfd)
TCPClient::~TCPClient()
{
- if (tcpclient_fd != -1)
+ if (tcpclient_fd != -1) {
+ client_disconnect();
close(tcpclient_fd);
- //con_debug << "TCPClient: terminated." << std::endl;
+ }
}
bool TCPClient::error() const
@@ -66,17 +67,16 @@ void TCPClient::receive(std::string &msg)
memset(recvbuf, '\0', sizeof(recvbuf));
bytes_received = ::recv(tcpclient_fd, recvbuf, msglen, 0);
if (bytes_received == 0) {
- // FIXME handle disconnect gracefully
- con_print << "Client " << fd() << " disconnected." << std::endl;
- disconnect();
+ //con_print << "Client " << fd() << " disconnected." << std::endl;
+ client_disconnect();
abort();
return;
} else if (bytes_received < 0) {
- con_warn << "Client " << fd() << " receive() error!" << std::endl;
+ //con_warn << "Client " << fd() << " receive() error!" << std::endl;
// FIXME redirect error message
- perror("recv");
- disconnect();
+ perror("recv");
abort();
+ client_disconnect();
return;
}
msg = recvbuf;
@@ -103,6 +103,7 @@ void TCPClient::send(std::string const &msg)
// FIXME redirect error message
perror("send");
abort();
+ client_disconnect();
return;
}
total_sent += bytes_sent;
@@ -113,7 +114,9 @@ void TCPClient::send(std::string const &msg)
return;
}
-void TCPClient::disconnect()
-{}
+void TCPClient::client_disconnect()
+{
+ /* error() indicates if it was a clean disconnect or not */
+}
}
diff --git a/src/net/tcpclient.h b/src/net/tcpclient.h
index 0fcb4b6..943531e 100644
--- a/src/net/tcpclient.h
+++ b/src/net/tcpclient.h
@@ -39,15 +39,15 @@ public:
void abort();
/// Sends outgoing data
- void send(std::string const &msg);
-
+ virtual void send(std::string const &msg);
+
+ /// receives incoming data
+ virtual void receive(std::string &msg);
+
+protected:
/// Called by receive() when the client has disconnected
/// @see receive
- virtual void disconnect();
-
-protected:
- /// receives incoming data
- void receive(std::string &msg);
+ virtual void client_disconnect();
private:
int tcpclient_fd;