# tcp.h

Go to the documentation of this file.

    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 "os_abstraction.h"
    00018 #include "address.h"
    00019 #include "core.h"
    00020 #include "packet.h"
    00021
    00022 #ifdef ENABLE_NETWORK
    00023
    00025 class NetworkTCPSocketHandler : public NetworkSocketHandler {
    00026 private:
    00027   Packet *packet_queue;
    00028   Packet *packet_recv;
    00029 public:
    00030   SOCKET sock;
    00031   bool writable;
    00032
    00037   bool IsConnected() const { return this->sock != INVALID_SOCKET; }
    00038
    00039   virtual NetworkRecvStatus CloseConnection(bool error = true);
    00040   void Send_Packet(Packet *packet);
    00041   bool Send_Packets();
    00042   bool IsPacketQueueEmpty();
    00043
    00044   Packet *Recv_Packet();
    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
    00062   void Connect();
    00063
    00068   static void ThreadEntry(void *param);
    00069
    00070 protected:
    00072   NetworkAddress address;
    00073
    00074 public:
    00079   TCPConnecter(const NetworkAddress &address);
    00081   virtual ~TCPConnecter() {}
    00082
    00087   virtual void OnConnect(SOCKET s) {}
    00088
    00092   virtual void OnFailure() {}
    00093
    00100   static void CheckCallbacks();
    00101
    00103   static void KillAll();
    00104 };
    00105
    00106 #endif /* ENABLE_NETWORK */
    00107
    00108 #endif /* NETWORK_CORE_TCP_H */