# 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 "address.h"
    00018 #include "packet.h"
    00019
    00020 #ifdef ENABLE_NETWORK
    00021
    00023 enum SendPacketsState {
    00024   SPS_CLOSED,
    00025   SPS_NONE_SENT,
    00026   SPS_PARTLY_SENT,
    00027   SPS_ALL_SENT,
    00028 };
    00029
    00031 class NetworkTCPSocketHandler : public NetworkSocketHandler {
    00032 private:
    00033   Packet *packet_queue;
    00034   Packet *packet_recv;
    00035 public:
    00036   SOCKET sock;
    00037   bool writable;
    00038
    00043   bool IsConnected() const { return this->sock != INVALID_SOCKET; }
    00044
    00045   virtual NetworkRecvStatus CloseConnection(bool error = true);
    00046   virtual void SendPacket(Packet *packet);
    00047   SendPacketsState SendPackets(bool closing_down = false);
    00048
    00049   virtual Packet *ReceivePacket();
    00050
    00051   bool CanSendReceive();
    00052
    00053   NetworkTCPSocketHandler(SOCKET s = INVALID_SOCKET);
    00054   ~NetworkTCPSocketHandler();
    00055 };
    00056
    00060 class TCPConnecter {
    00061 private:
    00062   class ThreadObject *thread;
    00063   bool connected;
    00064   bool aborted;
    00065   bool killed;
    00066   SOCKET sock;
    00067
    00068   void Connect();
    00069
    00070   static void ThreadEntry(void *param);
    00071
    00072 protected:
    00074   NetworkAddress address;
    00075
    00076 public:
    00077   TCPConnecter(const NetworkAddress &address);
    00079   virtual ~TCPConnecter() {}
    00080
    00085   virtual void OnConnect(SOCKET s) {}
    00086
    00090   virtual void OnFailure() {}
    00091
    00092   static void CheckCallbacks();
    00093   static void KillAll();
    00094 };
    00095
    00096 #endif /* ENABLE_NETWORK */
    00097
    00098 #endif /* NETWORK_CORE_TCP_H */