--- deliantra/server/socket/loop.C 2006/12/16 12:23:52 1.22 +++ deliantra/server/socket/loop.C 2006/12/17 19:07:23 1.27 @@ -28,8 +28,7 @@ * \date 2003-12-02 * * loop.c mainly deals with initialization and higher level socket - * maintenance (checking for lost connections and if data has arrived.) - * The reading of data is handled in ericserver.c + * maintanance (checking for lost connections and if data has arrived.) */ @@ -49,7 +48,7 @@ #include #define MAX_QUEUE_DEPTH 500 //TODO -#define MAX_QUEUE_BACKLOG 2 //TODO +#define MAX_QUEUE_BACKLOG 5. //TODO void client::reset_state () @@ -72,40 +71,47 @@ reset_state (); send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); } - else if (!cmd_queue.empty () && cmd_queue.front ().stamp + MAX_QUEUE_BACKLOG < stamp) + else { - reset_state (); - send_packet_printf ("drawinfo %d too many commands in queue, ignoring.", NDI_RED); + cmd_queue.push_back (command ()); + command &cmd = cmd_queue.back (); + cmd.stamp = stamp; + cmd.handler = handler; + cmd.data = salloc (datalen + 1, data); + cmd.datalen = datalen; } - else - cmd_queue.push_back (command ( - stamp, handler, (char *)salloc (datalen + 1, data), datalen - )); } bool client::handle_command () { - if (pl && pl->state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0) - return false; + bool skipping = false; - if (cmd_queue.empty ()) - return false; + while (!cmd_queue.empty () + && !(pl && pl->state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0)) + { + command &cmd = cmd_queue.front (); - command &cmd = cmd_queue.front (); + if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) + { + if (!skipping) + { + skipping = true; + reset_state (); + send_packet_printf ("drawinfo %d ignoring delayed commands.", NDI_RED); + } - if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) - { - reset_state (); - send_packet_printf ("drawinfo %d ignoring delayed command.", NDI_RED); + cmd_queue.pop_front (); + } + else + { + execute (cmd.handler, cmd.data, cmd.datalen); + cmd_queue.pop_front (); + return true; + } } - else - execute (cmd.handler, cmd.data, cmd.datalen); - sfree (cmd.data, cmd.datalen); - cmd_queue.pop_front (); - - return true; + return false; } void @@ -179,7 +185,11 @@ player *pl = s->pl; s->handle_packet (); - s->handle_command (); + + for (int i = 16; --i; ) //D + if (!//D + s->handle_command () + ) break;//D //TODO: should not be done here, either if (s->status != Ns_Dead && pl)