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: 28 30 93.3 %
Date: 2011-12-24 Functions: 3 3 100.0 %
Branches: 3 6 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :   Liquid War 6 is a unique multiplayer wargame.
       3                 :            :   Copyright (C)  2005, 2006, 2007, 2008, 2009, 2010, 2011  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                 :         22 : _mod_udpd_open (_udpd_context_t * udpd_context, lw6srv_listener_t * listener,
      32                 :            :                 char *local_url, char *remote_url, char *remote_ip,
      33                 :            :                 int remote_port, char *password, u_int64_t local_id,
      34                 :            :                 u_int64_t remote_id, int dns_ok, int network_reliability,
      35                 :            :                 lw6cnx_recv_callback_t recv_callback_func,
      36                 :            :                 void *recv_callback_data)
      37                 :            : {
      38                 :         22 :   lw6cnx_connection_t *ret = NULL;
      39                 :         22 :   _udpd_specific_data_t *specific_data = NULL;
      40                 :            : 
      41                 :         22 :   lw6sys_log (LW6SYS_LOG_DEBUG, _x_ ("_mod_udpd_open \"%s\""), remote_url);
      42                 :         22 :   ret =
      43                 :            :     lw6cnx_connection_new (local_url, remote_url, remote_ip, remote_port,
      44                 :            :                            password, local_id, remote_id, dns_ok,
      45                 :            :                            network_reliability, recv_callback_func,
      46                 :            :                            recv_callback_data);
      47         [ +  - ]:         22 :   if (ret)
      48                 :            :     {
      49                 :         22 :       ret->backend_specific_data =
      50                 :         22 :         LW6SYS_CALLOC (sizeof (_udpd_specific_data_t));
      51                 :         22 :       specific_data = (_udpd_specific_data_t *) ret->backend_specific_data;
      52         [ +  - ]:         22 :       if (ret->backend_specific_data)
      53                 :            :         {
      54                 :         22 :           specific_data->sock = listener->udp_sock;
      55                 :         22 :           specific_data->remote_port = remote_port;
      56                 :         22 :           lw6sys_log (LW6SYS_LOG_DEBUG,
      57                 :            :                       _x_ ("open udpd connection with \"%s\""), remote_url);
      58                 :            :         }
      59                 :            :       else
      60                 :            :         {
      61                 :          0 :           _mod_udpd_close (udpd_context, ret);
      62                 :          0 :           ret = NULL;
      63                 :            :         }
      64                 :            :     }
      65                 :            : 
      66                 :         22 :   return ret;
      67                 :            : }
      68                 :            : 
      69                 :            : void
      70                 :         22 : _mod_udpd_close (_udpd_context_t * udpd_context,
      71                 :            :                  lw6cnx_connection_t * connection)
      72                 :            : {
      73                 :         22 :   _udpd_specific_data_t *specific_data =
      74                 :            :     (_udpd_specific_data_t *) connection->backend_specific_data;;
      75                 :            : 
      76         [ +  - ]:         22 :   if (specific_data)
      77                 :            :     {
      78                 :         22 :       LW6SYS_FREE (specific_data);
      79                 :            :     }
      80                 :         22 :   lw6cnx_connection_free (connection);
      81                 :         22 : }
      82                 :            : 
      83                 :            : int
      84                 :         17 : _mod_udpd_timeout_ok (_udpd_context_t * udpd_context,
      85                 :            :                       int64_t origin_timestamp)
      86                 :            : {
      87                 :         17 :   int ret = 0;
      88                 :         17 :   int d = 0;
      89                 :            : 
      90                 :         34 :   d =
      91                 :         17 :     origin_timestamp + (udpd_context->data.consts.error_timeout * 1000) -
      92                 :         17 :     lw6sys_get_timestamp ();
      93                 :         17 :   ret = (d > 0);
      94                 :            : 
      95                 :         17 :   return ret;
      96                 :            : }

Generated by: LCOV version 1.9