author | rubidium |
Tue, 22 Jan 2008 21:00:30 +0000 | |
branch | NewGRF_ports |
changeset 6872 | 1c4a4a609f85 |
parent 6447 | 3b71e57fd22b |
child 10242 | 52b4a9006029 |
permissions | -rw-r--r-- |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
2 |
|
6447
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6153
diff
changeset
|
3 |
/** |
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6153
diff
changeset
|
4 |
* @file tcp.cpp Basic functions to receive and send TCP packets. |
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6153
diff
changeset
|
5 |
*/ |
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6153
diff
changeset
|
6 |
|
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
7 |
#ifdef ENABLE_NETWORK |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
8 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
9 |
#include "../../stdafx.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
10 |
#include "../../debug.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
11 |
#include "../../openttd.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
12 |
#include "../../variables.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
13 |
|
5778
c1454e0c03bf
(svn r7834) -Codechange: cleanup the includes of network/core a little; include headers in headers when the header needs types/constants defined in them.
rubidium
parents:
5726
diff
changeset
|
14 |
#include "../network_data.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
15 |
#include "packet.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
16 |
#include "tcp.h" |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6447
diff
changeset
|
17 |
|
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6447
diff
changeset
|
18 |
#include "table/strings.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
19 |
|
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
20 |
/** Very ugly temporary hack !!! */ |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
21 |
void NetworkTCPSocketHandler::Initialize() |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
22 |
{ |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
23 |
this->sock = INVALID_SOCKET; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
24 |
|
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
25 |
this->index = 0; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
26 |
this->last_frame = 0; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
27 |
this->last_frame_server = 0; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
28 |
this->lag_test = 0; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
29 |
|
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
30 |
this->status = STATUS_INACTIVE; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
31 |
this->has_quit = false; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
32 |
this->writable = false; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
33 |
|
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
34 |
this->packet_queue = NULL; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
35 |
this->packet_recv = NULL; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
36 |
|
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
37 |
this->command_queue = NULL; |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
38 |
} |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
39 |
|
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
40 |
void NetworkTCPSocketHandler::Destroy() |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
41 |
{ |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
42 |
closesocket(this->sock); |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
43 |
this->writable = false; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
44 |
this->has_quit = true; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
45 |
|
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
46 |
/* Free all pending and partially received packets */ |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
47 |
while (this->packet_queue != NULL) { |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
48 |
Packet *p = this->packet_queue->next; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
49 |
delete this->packet_queue; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
50 |
this->packet_queue = p; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
51 |
} |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
52 |
delete this->packet_recv; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
53 |
this->packet_recv = NULL; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
54 |
|
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
55 |
while (this->command_queue != NULL) { |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
56 |
CommandPacket *p = this->command_queue->next; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
57 |
free(this->command_queue); |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
58 |
this->command_queue = p; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
59 |
} |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
60 |
} |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
61 |
|
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
62 |
/** |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
63 |
* Functions to help NetworkRecv_Packet/NetworkSend_Packet a bit |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
64 |
* A socket can make errors. When that happens this handles what to do. |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
65 |
* For clients: close connection and drop back to main-menu |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
66 |
* For servers: close connection and that is it |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
67 |
* @return the new status |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
68 |
* TODO: needs to be splitted when using client and server socket packets |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
69 |
*/ |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
70 |
NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection() |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
71 |
{ |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
72 |
NetworkCloseClient(this); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
73 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
74 |
/* Clients drop back to the main menu */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
75 |
if (!_network_server && _networking) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
76 |
_switch_mode = SM_MENU; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
77 |
_networking = false; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
78 |
_switch_mode_errorstr = STR_NETWORK_ERR_LOSTCONNECTION; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
79 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
80 |
return NETWORK_RECV_STATUS_CONN_LOST; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
81 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
82 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
83 |
return NETWORK_RECV_STATUS_OKAY; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
84 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
85 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
86 |
/** |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
87 |
* This function puts the packet in the send-queue and it is send as |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
88 |
* soon as possible. This is the next tick, or maybe one tick later |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
89 |
* if the OS-network-buffer is full) |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
90 |
* @param packet the packet to send |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
91 |
*/ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
92 |
void NetworkTCPSocketHandler::Send_Packet(Packet *packet) |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
93 |
{ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
94 |
Packet *p; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
95 |
assert(packet != NULL); |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
96 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6115
diff
changeset
|
97 |
packet->PrepareToSend(); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
98 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
99 |
/* Locate last packet buffered for the client */ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
100 |
p = this->packet_queue; |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
101 |
if (p == NULL) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
102 |
/* No packets yet */ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
103 |
this->packet_queue = packet; |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
104 |
} else { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
105 |
/* Skip to the last packet */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
106 |
while (p->next != NULL) p = p->next; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
107 |
p->next = packet; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
108 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
109 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
110 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
111 |
/** |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
112 |
* Sends all the buffered packets out for this client. It stops when: |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
113 |
* 1) all packets are send (queue is empty) |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
114 |
* 2) the OS reports back that it can not send any more |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
115 |
* data right now (full network-buffer, it happens ;)) |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
116 |
* 3) sending took too long |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
117 |
*/ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
118 |
bool NetworkTCPSocketHandler::Send_Packets() |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
119 |
{ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
120 |
ssize_t res; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
121 |
Packet *p; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
122 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
123 |
/* We can not write to this socket!! */ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
124 |
if (!this->writable) return false; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
125 |
if (!this->IsConnected()) return false; |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
126 |
|
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
127 |
p = this->packet_queue; |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
128 |
while (p != NULL) { |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
129 |
res = send(this->sock, (const char*)p->buffer + p->pos, p->size - p->pos, 0); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
130 |
if (res == -1) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
131 |
int err = GET_LAST_ERROR(); |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
132 |
if (err != EWOULDBLOCK) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
133 |
/* Something went wrong.. close client! */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
134 |
DEBUG(net, 0, "send failed with error %d", err); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
135 |
this->CloseConnection(); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
136 |
return false; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
137 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
138 |
return true; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
139 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
140 |
if (res == 0) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
141 |
/* Client/server has left us :( */ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
142 |
this->CloseConnection(); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
143 |
return false; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
144 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
145 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
146 |
p->pos += res; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
147 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
148 |
/* Is this packet sent? */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
149 |
if (p->pos == p->size) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
150 |
/* Go to the next packet */ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
151 |
this->packet_queue = p->next; |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6115
diff
changeset
|
152 |
delete p; |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
153 |
p = this->packet_queue; |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
154 |
} else { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
155 |
return true; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
156 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
157 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
158 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
159 |
return true; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
160 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
161 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
162 |
/** |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
163 |
* Receives a packet for the given client |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
164 |
* @param status the variable to store the status into |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
165 |
* @return the received packet (or NULL when it didn't receive one) |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
166 |
*/ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
167 |
Packet *NetworkTCPSocketHandler::Recv_Packet(NetworkRecvStatus *status) |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
168 |
{ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
169 |
ssize_t res; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
170 |
Packet *p; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
171 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
172 |
*status = NETWORK_RECV_STATUS_OKAY; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
173 |
|
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
174 |
if (!this->IsConnected()) return NULL; |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
175 |
|
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
176 |
if (this->packet_recv == NULL) { |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
177 |
this->packet_recv = new Packet(this); |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
178 |
if (this->packet_recv == NULL) error("Failed to allocate packet"); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
179 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
180 |
|
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
181 |
p = this->packet_recv; |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
182 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
183 |
/* Read packet size */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
184 |
if (p->pos < sizeof(PacketSize)) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
185 |
while (p->pos < sizeof(PacketSize)) { |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
186 |
/* Read the size of the packet */ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
187 |
res = recv(this->sock, (char*)p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
188 |
if (res == -1) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
189 |
int err = GET_LAST_ERROR(); |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
190 |
if (err != EWOULDBLOCK) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
191 |
/* Something went wrong... (104 is connection reset by peer) */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
192 |
if (err != 104) DEBUG(net, 0, "recv failed with error %d", err); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
193 |
*status = this->CloseConnection(); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
194 |
return NULL; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
195 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
196 |
/* Connection would block, so stop for now */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
197 |
return NULL; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
198 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
199 |
if (res == 0) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
200 |
/* Client/server has left */ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
201 |
*status = this->CloseConnection(); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
202 |
return NULL; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
203 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
204 |
p->pos += res; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
205 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
206 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6115
diff
changeset
|
207 |
/* Read the packet size from the received packet */ |
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6115
diff
changeset
|
208 |
p->ReadRawPacketSize(); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
209 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
210 |
if (p->size > SEND_MTU) { |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
211 |
*status = this->CloseConnection(); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
212 |
return NULL; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
213 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
214 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
215 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
216 |
/* Read rest of packet */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
217 |
while (p->pos < p->size) { |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
218 |
res = recv(this->sock, (char*)p->buffer + p->pos, p->size - p->pos, 0); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
219 |
if (res == -1) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
220 |
int err = GET_LAST_ERROR(); |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
221 |
if (err != EWOULDBLOCK) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
222 |
/* Something went wrong... (104 is connection reset by peer) */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
223 |
if (err != 104) DEBUG(net, 0, "recv failed with error %d", err); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
224 |
*status = this->CloseConnection(); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
225 |
return NULL; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
226 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
227 |
/* Connection would block */ |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
228 |
return NULL; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
229 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
230 |
if (res == 0) { |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
231 |
/* Client/server has left */ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
232 |
*status = this->CloseConnection(); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
233 |
return NULL; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
234 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
235 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
236 |
p->pos += res; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
237 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
238 |
|
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
239 |
/* Prepare for receiving a new packet */ |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
240 |
this->packet_recv = NULL; |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
241 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6115
diff
changeset
|
242 |
p->PrepareToRead(); |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
243 |
return p; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
244 |
} |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
245 |
|
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
246 |
bool NetworkTCPSocketHandler::IsPacketQueueEmpty() |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
247 |
{ |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
248 |
return this->packet_queue == NULL; |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
249 |
} |
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
250 |
|
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6149
diff
changeset
|
251 |
|
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
diff
changeset
|
252 |
#endif /* ENABLE_NETWORK */ |