| 1 | /* |
| 2 | * Copyright (C) 1999,2000 Ross Combs ([email protected]) |
| 3 | * Copyright (C) 2004 Dizzy |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (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, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | #define TIMER_INTERNAL_ACCESScxx . . $ `src/bnetd/timer.cpp:19:9`! |
| 20 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 21 | #include "timer.h"cxx . . $ `<file>/src/bnetd/timer.h`/ |
| 22 | #include <cstdlib> |
| 23 | #include "common/elist.h"cxx . . $ `<file>/src/common/elist.h`/ |
| 24 | #include "connection.h"cxx . . $ `<file>/src/bnetd/connection.h`/ |
| 25 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 26 | #include "common/xalloc.h"cxx . . $ `<file>/src/common/xalloc.h`/ |
| 27 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 28 | |
| 29 | namespace pvpgncxx . . $ pvpgn/ |
| 30 | { |
| 31 | |
| 32 | namespace bnetdcxx . . $ pvpgn/bnetd/ |
| 33 | { |
| 34 | |
| 35 | static t_elistcxx . . $ pvpgn/t_elist# timerlist_headcxx . . $ pvpgn/bnetd/timerlist_head.; |
| 36 | |
| 37 | |
| 38 | extern int timerlist_add_timercxx . . $ pvpgn/bnetd/timerlist_add_timer(f16dcbfb825fabda).(t_connection * owner, stdcxx . . $ std/::time_tcxx . . $ std/time_t# when, t_timer_cbcxx . . $ pvpgn/bnetd/t_timer_cb# cb, t_timer_datacxx . . $ pvpgn/bnetd/t_timer_data# data) |
| 39 | { |
| 40 | t_timercxx . . $ pvpgn/bnetd/t_timer# * timer, *ctimer; |
| 41 | t_elistcxx . . $ pvpgn/t_elist# * curr; |
| 42 | |
| 43 | if (!owner) |
| 44 | { |
| 45 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL owner"); |
| 46 | return -1; |
| 47 | } |
| 48 | |
| 49 | timer = (t_timercxx . . $ pvpgn/bnetd/t_timer#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_timer)); |
| 50 | timer->ownercxx . . $ pvpgn/bnetd/timer_struct#owner. = owner; |
| 51 | timer->whencxx . . $ pvpgn/bnetd/timer_struct#when. = when; |
| 52 | timer->cbcxx . . $ pvpgn/bnetd/timer_struct#cb. = cb; |
| 53 | timer->datacxx . . $ pvpgn/bnetd/timer_struct#data. =cxx . . $ pvpgn/bnetd/$anonymous_type_64e82d6b10ad28f9_0#`operator=`(c85313a214c70e67). data; |
| 54 | |
| 55 | /* try to preserve a when based order */ |
| 56 | elist_for_eachcxx . . $ `src/common/elist.h:231:9`!(curr, &timerlist_head) |
| 57 | { |
| 58 | ctimer = elist_entrycxx . . $ `src/common/elist.h:228:9`!(curr, t_timer, timers); |
| 59 | if (ctimer->whencxx . . $ pvpgn/bnetd/timer_struct#when. > when) break; |
| 60 | } |
| 61 | elist_add_tailcxx . . $ pvpgn/elist_add_tail(3e860e19053b2cfa).(curr, &timer->timerscxx . . $ pvpgn/bnetd/timer_struct#timers.); |
| 62 | |
| 63 | /* add it to the t_conn timers list */ |
| 64 | elist_add_tailcxx . . $ pvpgn/elist_add_tail(3e860e19053b2cfa).(conn_get_timercxx . . $ pvpgn/bnetd/conn_get_timer(cb0e979634baad06).(owner), &timer->ownerscxx . . $ pvpgn/bnetd/timer_struct#owners.); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | extern int timerlist_del_all_timerscxx . . $ pvpgn/bnetd/timerlist_del_all_timers(c4dfbc2386fe4fc3).(t_connection * owner) |
| 71 | { |
| 72 | t_elistcxx . . $ pvpgn/t_elist# * curr, *save; |
| 73 | t_timercxx . . $ pvpgn/bnetd/t_timer# * timer; |
| 74 | |
| 75 | if (!owner) |
| 76 | { |
| 77 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL owner"); |
| 78 | return -1; |
| 79 | } |
| 80 | |
| 81 | elist_for_each_safecxx . . $ `src/common/elist.h:238:9`!(curr, conn_get_timer(owner), save) |
| 82 | { |
| 83 | timer = elist_entrycxx . . $ `src/common/elist.h:228:9`!(curr, t_timer, owners); |
| 84 | if (timer->cbcxx . . $ pvpgn/bnetd/timer_struct#cb.) |
| 85 | timer->cbcxx . . $ pvpgn/bnetd/timer_struct#cb.(timer->ownercxx . . $ pvpgn/bnetd/timer_struct#owner., (stdcxx . . $ std/::time_tcxx . . $ std/time_t#)0, timer->datacxx . . $ pvpgn/bnetd/timer_struct#data.); |
| 86 | elist_delcxx . . $ pvpgn/elist_del(c14d3311d3358512).(&timer->ownerscxx . . $ pvpgn/bnetd/timer_struct#owners.); |
| 87 | elist_delcxx . . $ pvpgn/elist_del(c14d3311d3358512).(&timer->timerscxx . . $ pvpgn/bnetd/timer_struct#timers.); |
| 88 | xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)timer); |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | extern int timerlist_check_timerscxx . . $ pvpgn/bnetd/timerlist_check_timers(a9e4e82268fd7bfa).(stdcxx . . $ std/::time_tcxx . . $ std/time_t# when) |
| 96 | { |
| 97 | t_elistcxx . . $ pvpgn/t_elist# * curr, *save; |
| 98 | t_timercxx . . $ pvpgn/bnetd/t_timer# * timer; |
| 99 | |
| 100 | elist_for_each_safecxx . . $ `src/common/elist.h:238:9`!(curr, &timerlist_head, save) |
| 101 | { |
| 102 | timer = elist_entrycxx . . $ `src/common/elist.h:228:9`!(curr, t_timer, timers); |
| 103 | if (timer->ownercxx . . $ pvpgn/bnetd/timer_struct#owner. && timer->whencxx . . $ pvpgn/bnetd/timer_struct#when. < when) |
| 104 | { |
| 105 | if (timer->cbcxx . . $ pvpgn/bnetd/timer_struct#cb.) |
| 106 | timer->cbcxx . . $ pvpgn/bnetd/timer_struct#cb.(timer->ownercxx . . $ pvpgn/bnetd/timer_struct#owner., timer->whencxx . . $ pvpgn/bnetd/timer_struct#when., timer->datacxx . . $ pvpgn/bnetd/timer_struct#data.); |
| 107 | elist_delcxx . . $ pvpgn/elist_del(c14d3311d3358512).(&timer->ownerscxx . . $ pvpgn/bnetd/timer_struct#owners.); |
| 108 | elist_delcxx . . $ pvpgn/elist_del(c14d3311d3358512).(&timer->timerscxx . . $ pvpgn/bnetd/timer_struct#timers.); |
| 109 | xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)timer); |
| 110 | } |
| 111 | else break; /* beeing sorted there is no need to go beyond this point */ |
| 112 | } |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | extern int timerlist_createcxx . . $ pvpgn/bnetd/timerlist_create(b126dc7c1de90089).(void) |
| 118 | { |
| 119 | elist_initcxx . . $ `src/common/elist.h:193:9`!(&timerlist_head); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | extern int timerlist_destroycxx . . $ pvpgn/bnetd/timerlist_destroy(b126dc7c1de90089).(void) |
| 125 | { |
| 126 | t_elistcxx . . $ pvpgn/t_elist# * curr, *save; |
| 127 | t_timercxx . . $ pvpgn/bnetd/t_timer# * timer; |
| 128 | |
| 129 | elist_for_each_safecxx . . $ `src/common/elist.h:238:9`!(curr, &timerlist_head, save) |
| 130 | { |
| 131 | timer = elist_entrycxx . . $ `src/common/elist.h:228:9`!(curr, t_timer, timers); |
| 132 | elist_delcxx . . $ pvpgn/elist_del(c14d3311d3358512).(&timer->ownerscxx . . $ pvpgn/bnetd/timer_struct#owners.); |
| 133 | elist_delcxx . . $ pvpgn/elist_del(c14d3311d3358512).(&timer->timerscxx . . $ pvpgn/bnetd/timer_struct#timers.); |
| 134 | xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)timer); |
| 135 | } |
| 136 | elist_initcxx . . $ `src/common/elist.h:193:9`!(&timerlist_head); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | } |
| 142 | |
| 143 | } |