summaryrefslogtreecommitdiff
path: root/src/network/core/tcp.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-02-01 22:30:35 +0000
committerrubidium <rubidium@openttd.org>2007-02-01 22:30:35 +0000
commit99f860e68615b011b959ac9edb45660a0396dc1b (patch)
treed1732ff5833da9103bce694429be7bf8317b2f50 /src/network/core/tcp.cpp
parent15980fc023c9fffa1af1ab71a446d0154d7962ca (diff)
downloadopenttd-99f860e68615b011b959ac9edb45660a0396dc1b.tar.xz
(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.
Diffstat (limited to 'src/network/core/tcp.cpp')
-rw-r--r--src/network/core/tcp.cpp20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index 8a7da433d..c79f5f14c 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -74,10 +74,7 @@ void NetworkSend_Packet(Packet *packet, NetworkTCPSocketHandler *cs)
Packet *p;
assert(packet != NULL);
- packet->pos = 0;
- packet->next = NULL;
-
- NetworkSend_FillPacketSize(packet);
+ packet->PrepareToSend();
/* Locate last packet buffered for the client */
p = cs->packet_queue;
@@ -133,7 +130,7 @@ bool NetworkSend_Packets(NetworkTCPSocketHandler *cs)
if (p->pos == p->size) {
/* Go to the next packet */
cs->packet_queue = p->next;
- free(p);
+ delete p;
p = cs->packet_queue;
} else {
return true;
@@ -159,11 +156,8 @@ Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *statu
if (!cs->IsConnected()) return NULL;
if (cs->packet_recv == NULL) {
- cs->packet_recv = MallocT<Packet>(1);
+ cs->packet_recv = new Packet(cs);
if (cs->packet_recv == NULL) error("Failed to allocate packet");
- /* Set pos to zero! */
- cs->packet_recv->pos = 0;
- cs->packet_recv->size = 0; // Can be ommited, just for safety reasons
}
p = cs->packet_recv;
@@ -192,7 +186,8 @@ Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *statu
p->pos += res;
}
- NetworkRecv_ReadPacketSize(p);
+ /* Read the packet size from the received packet */
+ p->ReadRawPacketSize();
if (p->size > SEND_MTU) {
*status = cs->CloseConnection();
@@ -223,13 +218,10 @@ Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *statu
p->pos += res;
}
- /* We have a complete packet, return it! */
- p->pos = 2;
- p->next = NULL; // Should not be needed, but who knows...
-
/* Prepare for receiving a new packet */
cs->packet_recv = NULL;
+ p->PrepareToRead();
return p;
}