summaryrefslogtreecommitdiff
path: root/network.c
diff options
context:
space:
mode:
authorludde <ludde@openttd.org>2005-07-16 14:29:36 +0000
committerludde <ludde@openttd.org>2005-07-16 14:29:36 +0000
commitbd974bb4431a7b130bb233fc40f9b0ef3b8c86d3 (patch)
tree4818760ed5ee4b8bba1e79fc5ed2b1967f43ec79 /network.c
parent8ff1f8c5262c6804cd1a9ed57e94ddcce3fecc54 (diff)
downloadopenttd-bd974bb4431a7b130bb233fc40f9b0ef3b8c86d3.tar.xz
(svn r2590) Fix: [network] Fixed NetworkHandleLocalQueue
Diffstat (limited to 'network.c')
-rw-r--r--network.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/network.c b/network.c
index 9a8ee08fc..938a73544 100644
--- a/network.c
+++ b/network.c
@@ -1101,37 +1101,38 @@ static void NetworkSend(void)
// Handle the local-command-queue
static void NetworkHandleLocalQueue(void)
{
- if (_local_command_queue != NULL) {
- CommandPacket *cp;
- CommandPacket *cp_prev;
-
- cp = _local_command_queue;
- cp_prev = NULL;
-
- while (cp != NULL) {
- if (_frame_counter > cp->frame) {
- // We can execute this command
- NetworkExecuteCommand(cp);
-
- if (cp_prev != NULL) {
- cp_prev->next = cp->next;
- free(cp);
- cp = cp_prev->next;
- } else {
- // This means we are at our first packet
- _local_command_queue = cp->next;
- free(cp);
- cp = _local_command_queue;
- }
+ CommandPacket *cp, **cp_prev;
- } else {
- // Command is in the future, skip to next
- // (commands don't have to be in order in the queue!!)
- cp_prev = cp;
- cp = cp->next;
- }
+ cp_prev = &_local_command_queue;
+
+ while ( (cp = *cp_prev) != NULL) {
+
+ // The queue is always in order, which means
+ // that the first element will be executed first.
+ if (_frame_counter < cp->frame)
+ break;
+
+ if (_frame_counter > cp->frame) {
+ // If we reach here, it means for whatever reason, we've already executed
+ // past the command we need to execute.
+ DEBUG(net, 0)("[NET] Trying to execute a packet in the past!");
+ assert(0);
}
+
+ // We can execute this command
+ NetworkExecuteCommand(cp);
+
+ *cp_prev = cp->next;
+ free(cp);
}
+
+ // Just a safety check, to be removed in the future.
+ // Make sure that no older command appears towards the end of the queue
+ // In that case we missed executing it. This will never happen.
+ for(cp = _local_command_queue; cp; cp = cp->next) {
+ assert(_frame_counter < cp->frame);
+ }
+
}
static bool NetworkDoClientLoop(void)