OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
23 enum SendPacketsState {
24 SPS_CLOSED,
25 SPS_NONE_SENT,
26 SPS_PARTLY_SENT,
27 SPS_ALL_SENT,
28 };
29
31 class NetworkTCPSocketHandler : public NetworkSocketHandler {
32 private:
33 Packet *packet_queue;
34 Packet *packet_recv;
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);
60 ~NetworkTCPSocketHandler();
61 };
62
66 class TCPConnecter {
67 private:
68 class ThreadObject *thread;
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:
80 NetworkAddress address;
81
82 public:
83 TCPConnecter(const NetworkAddress &address);
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 */