Mercurial > pidgin
diff plugins/icq/timeout.c @ 1912:8ed70631ed15
[gaim-migrate @ 1922]
new icqlib
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 29 May 2001 10:32:53 +0000 |
parents | ba8e6e211af5 |
children | 7b3f1eb1ef7d |
line wrap: on
line diff
--- a/plugins/icq/timeout.c Tue May 29 09:46:05 2001 +0000 +++ b/plugins/icq/timeout.c Tue May 29 10:32:53 2001 +0000 @@ -1,9 +1,31 @@ /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and + * Bill Soudan <soudan@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <stdlib.h> + #include "timeout.h" icq_Timeout *icq_CurrentTimeout = NULL; -list *icq_TimeoutList = NULL; +icq_List *icq_TimeoutList = NULL; void (*icq_SetTimeout)(long length); @@ -27,7 +49,7 @@ t->expire_time = time(NULL) + length; t->single_shot = 1; - list_insert_sorted(icq_TimeoutList, t); + icq_ListInsertSorted(icq_TimeoutList, t); if (count == 0) icq_TimeoutDoNotify(); @@ -38,11 +60,11 @@ void icq_TimeoutDelete(icq_Timeout *timeout) { - list_remove(icq_TimeoutList, timeout); + icq_ListRemove(icq_TimeoutList, timeout); /* if this was the timeout we were currently waiting on, move on * to the next */ - if (icq_CurrentTimeout = timeout) + if (icq_CurrentTimeout == timeout) { icq_CurrentTimeout = NULL; icq_TimeoutDoNotify(); @@ -56,10 +78,11 @@ icq_Timeout *t = p; int complete = 0; time_t current_time = va_arg(data, time_t); - list *expired_timeouts = va_arg(data, list *); + icq_List *expired_timeouts = va_arg(data, icq_List *); + (void)data; if (t->expire_time <= current_time) - list_enqueue(expired_timeouts, t); + icq_ListEnqueue(expired_timeouts, t); else /* traversal is complete when we reach an expire time in the future */ complete = 1; @@ -70,11 +93,14 @@ int _icq_HandleTimeout2(void *p, va_list data) { icq_Timeout *t = p; + (void)data; /* maybe a previously executed timeout caused us to be deleted, so * make sure we're still around */ - if (list_find(icq_TimeoutList, t)) + if (icq_ListFind(icq_TimeoutList, t)) (t->handler)(t->data); + + return 0; /* traverse entire list */ } int _icq_HandleTimeout3(void *p, va_list data) @@ -100,28 +126,31 @@ void icq_HandleTimeout() { time_t current_time = time(NULL); - list *expired_timeouts = list_new(); + icq_List *expired_timeouts = icq_ListNew(); icq_CurrentTimeout = NULL; - /* these three operations must be split up, in the case where a + /* these three operations must be split up for the case where a * timeout function causes timers to be deleted - this ensures * we don't try to free any timers that have already been removed * or corrupt the list traversal process */ /* determine which timeouts that have expired */ - list_traverse(icq_TimeoutList, _icq_HandleTimeout1, current_time, + icq_ListTraverse(icq_TimeoutList, _icq_HandleTimeout1, current_time, expired_timeouts); /* call handler function for expired timeouts */ - list_traverse(expired_timeouts, _icq_HandleTimeout2); + icq_ListTraverse(expired_timeouts, _icq_HandleTimeout2); /* delete any expired timeouts */ - list_traverse(icq_TimeoutList, _icq_HandleTimeout3, current_time); + icq_ListTraverse(icq_TimeoutList, _icq_HandleTimeout3, current_time); + /* if there's any timeouts left, notify the library client */ if (icq_TimeoutList->count) icq_TimeoutDoNotify(); -} + + icq_ListDelete(expired_timeouts, NULL); +} void icq_TimeoutDoNotify() { @@ -134,7 +163,7 @@ return; } - icq_CurrentTimeout = (icq_Timeout *)list_first(icq_TimeoutList); + icq_CurrentTimeout = (icq_Timeout *)icq_ListFirst(icq_TimeoutList); length = icq_CurrentTimeout->expire_time - current_time; if (icq_SetTimeout)