summaryrefslogtreecommitdiff
path: root/src/network/core/tcp.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-14 12:50:13 +0000
committerrubidium <rubidium@openttd.org>2009-01-14 12:50:13 +0000
commite18c24cdb5c2031cad7813c7de5f2554428ada43 (patch)
tree7bf6232afadc77f8198fdad1571c68a85647afbf /src/network/core/tcp.cpp
parent6fe54a2d1a06b1d55cd649919785af6f4890f9da (diff)
downloadopenttd-e18c24cdb5c2031cad7813c7de5f2554428ada43.tar.xz
(svn r15079) -Codechange: split tcp 'backend' and in-game handling like it is for UDP.
Diffstat (limited to 'src/network/core/tcp.cpp')
-rw-r--r--src/network/core/tcp.cpp62
1 files changed, 8 insertions, 54 deletions
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index 96b6dfbb0..08609ff20 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -8,31 +8,17 @@
#include "../../stdafx.h"
#include "../../debug.h"
-#include "../../openttd.h"
-#include "../../variables.h"
-#include "../network_internal.h"
#include "packet.h"
#include "tcp.h"
-#include "table/strings.h"
-#include "../../oldpool_func.h"
-
-/** Make very sure the preconditions given in network_type.h are actually followed */
-assert_compile(MAX_CLIENT_SLOTS == (MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK) << NCI_BITS_PER_POOL_BLOCK);
-assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS);
-
-typedef ClientIndex NetworkClientSocketID;
-DEFINE_OLD_POOL_GENERIC(NetworkClientSocket, NetworkClientSocket);
-
-NetworkClientSocket::NetworkClientSocket(ClientID client_id)
+NetworkTCPSocketHandler::NetworkTCPSocketHandler(SOCKET s) :
+ NetworkSocketHandler(s),
+ packet_queue(NULL), packet_recv(NULL), writable(false)
{
- this->sock = INVALID_SOCKET;
- this->client_id = client_id;
- this->status = STATUS_INACTIVE;
}
-NetworkClientSocket::~NetworkClientSocket()
+NetworkTCPSocketHandler::~NetworkTCPSocketHandler()
{
if (this->sock != INVALID_SOCKET) closesocket(this->sock);
this->writable = false;
@@ -47,39 +33,7 @@ NetworkClientSocket::~NetworkClientSocket()
delete this->packet_recv;
this->packet_recv = NULL;
- while (this->command_queue != NULL) {
- CommandPacket *p = this->command_queue->next;
- free(this->command_queue);
- this->command_queue = p;
- }
-
this->sock = INVALID_SOCKET;
- this->client_id = INVALID_CLIENT_ID;
- this->status = STATUS_INACTIVE;
-}
-
-/**
- * Functions to help NetworkRecv_Packet/NetworkSend_Packet a bit
- * A socket can make errors. When that happens this handles what to do.
- * For clients: close connection and drop back to main-menu
- * For servers: close connection and that is it
- * @return the new status
- * TODO: needs to be splitted when using client and server socket packets
- */
-NetworkRecvStatus NetworkClientSocket::CloseConnection()
-{
- /* Clients drop back to the main menu */
- if (!_network_server && _networking) {
- _switch_mode = SM_MENU;
- _networking = false;
- extern StringID _switch_mode_errorstr;
- _switch_mode_errorstr = STR_NETWORK_ERR_LOSTCONNECTION;
-
- return NETWORK_RECV_STATUS_CONN_LOST;
- }
-
- NetworkCloseClient(this);
- return NETWORK_RECV_STATUS_OKAY;
}
/**
@@ -88,7 +42,7 @@ NetworkRecvStatus NetworkClientSocket::CloseConnection()
* if the OS-network-buffer is full)
* @param packet the packet to send
*/
-void NetworkClientSocket::Send_Packet(Packet *packet)
+void NetworkTCPSocketHandler::Send_Packet(Packet *packet)
{
Packet *p;
assert(packet != NULL);
@@ -114,7 +68,7 @@ void NetworkClientSocket::Send_Packet(Packet *packet)
* data right now (full network-buffer, it happens ;))
* 3) sending took too long
*/
-bool NetworkClientSocket::Send_Packets()
+bool NetworkTCPSocketHandler::Send_Packets()
{
ssize_t res;
Packet *p;
@@ -163,7 +117,7 @@ bool NetworkClientSocket::Send_Packets()
* @param status the variable to store the status into
* @return the received packet (or NULL when it didn't receive one)
*/
-Packet *NetworkClientSocket::Recv_Packet(NetworkRecvStatus *status)
+Packet *NetworkTCPSocketHandler::Recv_Packet(NetworkRecvStatus *status)
{
ssize_t res;
Packet *p;
@@ -242,7 +196,7 @@ Packet *NetworkClientSocket::Recv_Packet(NetworkRecvStatus *status)
return p;
}
-bool NetworkClientSocket::IsPacketQueueEmpty()
+bool NetworkTCPSocketHandler::IsPacketQueueEmpty()
{
return this->packet_queue == NULL;
}