From 982562fa19bb87a3dab352e562f386f61c171b7b Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 17 Feb 2008 18:59:52 +0000 Subject: major rewrite of Cvar, Func and Entity --- src/net/tcpclient.cc | 23 +++++++++++++---------- src/net/tcpclient.h | 14 +++++++------- 2 files changed, 20 insertions(+), 17 deletions(-) (limited to 'src/net') 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; -- cgit v1.2.3