LCOV - code coverage report
Current view: top level - src/lib/srv/mod-udpd - mod-udpd-state.c (source / functions) Hit Total Coverage
Test: liquidwar6.info Lines: 26 28 92.9 %
Date: 2014-03-26 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :   Liquid War 6 is a unique multiplayer wargame.
       3             :   Copyright (C)  2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014  Christian Mauduit <ufoot@ufoot.org>
       4             : 
       5             :   This program is free software; you can redistribute it and/or modify
       6             :   it under the terms of the GNU General Public License as published by
       7             :   the Free Software Foundation, either version 3 of the License, or
       8             :   (at your option) any later version.
       9             : 
      10             :   This program is distributed in the hope that it will be useful,
      11             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :   GNU General Public License for more details.
      14             : 
      15             :   You should have received a copy of the GNU General Public License
      16             :   along with this program.  If not, see <http://www.gnu.org/licenses/>.
      17             : 
      18             : 
      19             :   Liquid War 6 homepage : http://www.gnu.org/software/liquidwar6/
      20             :   Contact author        : ufoot@ufoot.org
      21             : */
      22             : 
      23             : #ifdef HAVE_CONFIG_H
      24             : #include "config.h"
      25             : #endif
      26             : 
      27             : #include "../srv.h"
      28             : #include "mod-udpd-internal.h"
      29             : 
      30             : lw6cnx_connection_t *
      31          33 : _mod_udpd_open (_mod_udpd_context_t * udpd_context,
      32             :                 lw6srv_listener_t * listener, const char *local_url,
      33             :                 const char *remote_url, const char *remote_ip,
      34             :                 int remote_port, const char *password, u_int64_t local_id,
      35             :                 u_int64_t remote_id, int dns_ok, int network_reliability,
      36             :                 lw6cnx_recv_callback_t recv_callback_func,
      37             :                 void *recv_callback_data)
      38             : {
      39          33 :   lw6cnx_connection_t *ret = NULL;
      40          33 :   _mod_udpd_specific_data_t *specific_data = NULL;
      41             : 
      42          33 :   lw6sys_log (LW6SYS_LOG_DEBUG, _x_ ("_mod_udpd_open \"%s\""), remote_url);
      43          33 :   ret =
      44             :     lw6cnx_connection_new (local_url, remote_url, remote_ip, remote_port,
      45             :                            password, local_id, remote_id, dns_ok,
      46             :                            network_reliability, recv_callback_func,
      47             :                            recv_callback_data);
      48          33 :   if (ret)
      49             :     {
      50          33 :       ret->backend_specific_data =
      51          33 :         LW6SYS_CALLOC (sizeof (_mod_udpd_specific_data_t));
      52          33 :       specific_data =
      53             :         (_mod_udpd_specific_data_t *) ret->backend_specific_data;
      54          33 :       if (ret->backend_specific_data)
      55             :         {
      56          33 :           specific_data->sock = listener->udp_sock;
      57          33 :           specific_data->remote_port = remote_port;
      58          33 :           lw6sys_log (LW6SYS_LOG_DEBUG,
      59             :                       _x_ ("open udpd connection with \"%s\""), remote_url);
      60             :         }
      61             :       else
      62             :         {
      63           0 :           _mod_udpd_close (udpd_context, ret);
      64           0 :           ret = NULL;
      65             :         }
      66             :     }
      67             : 
      68          33 :   return ret;
      69             : }
      70             : 
      71             : void
      72          33 : _mod_udpd_close (_mod_udpd_context_t * udpd_context,
      73             :                  lw6cnx_connection_t * connection)
      74             : {
      75          33 :   _mod_udpd_specific_data_t *specific_data =
      76             :     (_mod_udpd_specific_data_t *) connection->backend_specific_data;;
      77             : 
      78          33 :   if (specific_data)
      79             :     {
      80          33 :       LW6SYS_FREE (specific_data);
      81             :     }
      82          33 :   lw6cnx_connection_free (connection);
      83          33 : }
      84             : 
      85             : int
      86         289 : _mod_udpd_timeout_ok (_mod_udpd_context_t * udpd_context,
      87             :                       int64_t origin_timestamp)
      88             : {
      89         289 :   int ret = 0;
      90         289 :   int d = 0;
      91             : 
      92             :   /*
      93             :    * We check the time difference against the absolute delta, this
      94             :    * way should we have any inconsistency, time difference in the
      95             :    * wrong way because origin_timestamp is wrecked, then after
      96             :    * some time assumed to be reasonnable (depends on settings)
      97             :    * it will be over.
      98             :    */
      99         289 :   d = abs (lw6sys_get_timestamp () - origin_timestamp);
     100         289 :   ret = (d < (udpd_context->data.consts.error_timeout * 1000));
     101             : 
     102         289 :   return ret;
     103             : }

Generated by: LCOV version 1.10