OpenTTD
tcp.h
Go to the documentation of this file.
1 /* $Id: tcp.h 24900 2013-01-08 22:46:42Z planetmaker $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
14 #ifndef NETWORK_CORE_TCP_H
15 #define NETWORK_CORE_TCP_H
16 
17 #include "address.h"
18 #include "packet.h"
19 
20 #ifdef ENABLE_NETWORK
21 
28 };
29 
32 private:
35 public:
36  SOCKET sock;
37  bool writable;
38 
43  bool IsConnected() const { return this->sock != INVALID_SOCKET; }
44 
45  virtual NetworkRecvStatus CloseConnection(bool error = true);
46  virtual void SendPacket(Packet *packet);
47  SendPacketsState SendPackets(bool closing_down = false);
48 
49  virtual Packet *ReceivePacket();
50 
51  bool CanSendReceive();
52 
57  bool HasSendQueue() { return this->packet_queue != NULL; }
58 
59  NetworkTCPSocketHandler(SOCKET s = INVALID_SOCKET);
61 };
62 
66 class TCPConnecter {
67 private:
69  bool connected;
70  bool aborted;
71  bool killed;
72  SOCKET sock;
73 
74  void Connect();
75 
76  static void ThreadEntry(void *param);
77 
78 protected:
81 
82 public:
85  virtual ~TCPConnecter() {}
86 
91  virtual void OnConnect(SOCKET s) {}
92 
96  virtual void OnFailure() {}
97 
98  static void CheckCallbacks();
99  static void KillAll();
100 };
101 
102 #endif /* ENABLE_NETWORK */
103 
104 #endif /* NETWORK_CORE_TCP_H */