(svn r15079) -Codechange: split tcp 'backend' and in-game handling like it is for UDP.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user