tcp.h

Go to the documentation of this file.
00001 /* $Id: tcp.h 18809 2010-01-15 16:41:15Z rubidium $ */
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   void Send_Packet(Packet *packet);
00039   bool Send_Packets(bool closing_down = false);
00040   bool IsPacketQueueEmpty();
00041 
00042   Packet *Recv_Packet();
00043 
00044   NetworkTCPSocketHandler(SOCKET s = INVALID_SOCKET);
00045   ~NetworkTCPSocketHandler();
00046 };
00047 
00051 class TCPConnecter {
00052 private:
00053   class ThreadObject *thread; 
00054   bool connected;             
00055   bool aborted;               
00056   bool killed;                
00057   SOCKET sock;                
00058 
00060   void Connect();
00061 
00066   static void ThreadEntry(void *param);
00067 
00068 protected:
00070   NetworkAddress address;
00071 
00072 public:
00077   TCPConnecter(const NetworkAddress &address);
00079   virtual ~TCPConnecter() {}
00080 
00085   virtual void OnConnect(SOCKET s) {}
00086 
00090   virtual void OnFailure() {}
00091 
00098   static void CheckCallbacks();
00099 
00101   static void KillAll();
00102 };
00103 
00104 #endif /* ENABLE_NETWORK */
00105 
00106 #endif /* NETWORK_CORE_TCP_H */

Generated on Sat Nov 20 20:59:04 2010 for OpenTTD by  doxygen 1.6.1