00001 /* $Id$ */ 00002 00003 /* 00004 * This file is part of OpenTTD. 00005 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. 00006 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00007 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. 00008 */ 00009 00014 #ifndef NETWORK_CORE_TCP_H 00015 #define NETWORK_CORE_TCP_H 00016 00017 #include "address.h" 00018 #include "packet.h" 00019 00020 #ifdef ENABLE_NETWORK 00021 00023 class NetworkTCPSocketHandler : public NetworkSocketHandler { 00024 private: 00025 Packet *packet_queue; 00026 Packet *packet_recv; 00027 public: 00028 SOCKET sock; 00029 bool writable; 00030 00035 bool IsConnected() const { return this->sock != INVALID_SOCKET; } 00036 00037 virtual NetworkRecvStatus CloseConnection(bool error = true); 00038 virtual void SendPacket(Packet *packet); 00039 bool SendPackets(bool closing_down = false); 00040 bool IsPacketQueueEmpty(); 00041 00042 virtual Packet *ReceivePacket(); 00043 00044 bool CanSendReceive(); 00045 00046 NetworkTCPSocketHandler(SOCKET s = INVALID_SOCKET); 00047 ~NetworkTCPSocketHandler(); 00048 }; 00049 00053 class TCPConnecter { 00054 private: 00055 class ThreadObject *thread; 00056 bool connected; 00057 bool aborted; 00058 bool killed; 00059 SOCKET sock; 00060 00061 void Connect(); 00062 00063 static void ThreadEntry(void *param); 00064 00065 protected: 00067 NetworkAddress address; 00068 00069 public: 00070 TCPConnecter(const NetworkAddress &address); 00072 virtual ~TCPConnecter() {} 00073 00078 virtual void OnConnect(SOCKET s) {} 00079 00083 virtual void OnFailure() {} 00084 00085 static void CheckCallbacks(); 00086 static void KillAll(); 00087 }; 00088 00089 #endif /* ENABLE_NETWORK */ 00090 00091 #endif /* NETWORK_CORE_TCP_H */