00001 #ifndef CLIENT_COMMON_H 00002 #define CLIENT_COMMON_H 00003 #include <string> 00004 #include "engine/mutex.h" 00005 #include "packet.h" 00006 00007 class ClientCommon : protected Mutex 00008 { 00009 protected: 00010 int fd; 00011 00012 char* buffer; 00013 unsigned int buffer_len; 00014 00015 std::string client_host; 00016 int client_port; 00017 00018 protected: 00019 bool reconnect; 00020 bool Send(const char* buf, unsigned int len); 00021 bool Send(const std::string & str); 00022 bool Send(Packet* p); 00023 virtual void Reconnect() {} 00024 00025 public: 00026 ClientCommon(int _fd = -1); 00027 virtual ~ClientCommon(); 00028 00029 virtual void Disconnect(); 00030 virtual bool Receive(unsigned int len = 4096); // Blockant call 00031 std::string ReceiveToEOL(); // Blockant call 00032 Packet* ReceivePacket(); // Blockant call 00033 int BytesReceived(); 00034 virtual bool IsConnected() = 0; 00035 virtual const std::string GetAddress() = 0; // Returns the address in form host:port 00036 const std::string GetIp(); 00037 int GetPort(); 00038 virtual void OnDisconnect() {} 00039 }; 00040 00041 #endif
1.5.8