Mercurial > pidgin
annotate src/protocols/icq/queue.c @ 3098:778e4e27c33e
[gaim-migrate @ 3112]
HTTP Proxy now HTTP compliant.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 28 Mar 2002 18:03:14 +0000 |
parents | f0a2a9afdb77 |
children |
rev | line source |
---|---|
2086 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | |
3 /* | |
2496
f0a2a9afdb77
[gaim-migrate @ 2509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
4 * $Id: queue.c 2509 2001-10-13 00:06:18Z warmenhoven $ |
2086 | 5 * |
6 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and | |
7 * Bill Soudan <soudan@kde.org> | |
8 * | |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 * | |
23 */ | |
24 | |
25 #include <stdlib.h> | |
26 | |
27 #include "icqlib.h" | |
28 #include "queue.h" | |
2496
f0a2a9afdb77
[gaim-migrate @ 2509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
29 #include "udp.h" |
2086 | 30 |
31 void icq_UDPQueueNew(icq_Link *icqlink) | |
32 { | |
33 icqlink->d->icq_UDPQueue = icq_ListNew(); | |
34 icqlink->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */ | |
35 } | |
36 | |
37 void icq_UDPQueuePut(icq_Link *icqlink, icq_Packet *p) | |
38 { | |
39 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem)); | |
40 #ifdef QUEUE_DEBUG | |
41 printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p), | |
42 icq_PacketReadUDPOutCmd(p)); | |
43 #endif | |
44 ptr->attempts = 1; | |
45 ptr->timeout = icq_TimeoutNew(icqlink->icq_UDPExpireInterval, | |
46 (icq_TimeoutHandler)icq_UDPQueueItemResend, ptr); | |
47 ptr->timeout->single_shot = 0; | |
48 ptr->pack = p; | |
49 ptr->icqlink = icqlink; | |
50 #ifdef QUEUE_DEBUG | |
51 printf("enqueuing queueitem %p\n", ptr); | |
52 #endif | |
53 icq_ListEnqueue(icqlink->d->icq_UDPQueue, ptr); | |
54 } | |
55 | |
56 void _icq_UDPQueueItemFree(void *p) | |
57 { | |
58 icq_UDPQueueItem *pitem=(icq_UDPQueueItem *)p; | |
59 | |
60 #ifdef QUEUE_DEBUG | |
61 printf("_icq_UDPQueueItemFree(%p)\n", p); | |
62 #endif | |
63 | |
64 if (pitem->pack) | |
65 icq_PacketDelete(pitem->pack); | |
66 | |
67 if (pitem->timeout) | |
68 icq_TimeoutDelete(pitem->timeout); | |
69 | |
70 free(p); | |
71 } | |
72 | |
73 /* Frees the queue and dispose it */ | |
74 void icq_UDPQueueDelete(icq_Link *icqlink) | |
75 { | |
76 #ifdef QUEUE_DEBUG | |
77 printf("icq_UDPQueueDelete\n"); | |
78 #endif | |
79 if(icqlink->d->icq_UDPQueue) | |
80 { | |
81 icq_ListDelete(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree); | |
82 icqlink->d->icq_UDPQueue = 0; | |
83 } | |
84 } | |
85 | |
86 /* Only frees the queue */ | |
87 void icq_UDPQueueFree(icq_Link *icqlink) | |
88 { | |
89 #ifdef QUEUE_DEBUG | |
90 printf("icq_UDPQueueFree\n"); | |
91 #endif | |
92 if(icqlink->d->icq_UDPQueue) | |
93 icq_ListFree(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree); | |
94 } | |
95 | |
96 int icq_UDPQueueFindSeq(void *p, va_list data) | |
97 { | |
98 WORD seq=va_arg(data, int); | |
99 return icq_PacketReadUDPOutSeq1(((icq_UDPQueueItem *)p)->pack) == seq; | |
100 } | |
101 | |
102 void icq_UDPQueueDelSeq(icq_Link *icqlink, WORD seq) | |
103 { | |
104 icq_UDPQueueItem *ptr; | |
105 #ifdef QUEUE_DEBUG | |
106 printf("icq_UDPQueueDelSeq(seq=0x%04X", seq); | |
107 #endif | |
108 ptr = icq_ListTraverse(icqlink->d->icq_UDPQueue, icq_UDPQueueFindSeq, seq); | |
109 if(ptr) | |
110 { | |
111 #ifdef QUEUE_DEBUG | |
112 printf(", cmd=0x%04X",icq_PacketReadUDPOutCmd(ptr->pack)); | |
113 #endif | |
114 icq_ListRemove(icqlink->d->icq_UDPQueue, ptr); | |
115 _icq_UDPQueueItemFree(ptr); | |
116 } | |
117 #ifdef QUEUE_DEBUG | |
118 printf(")\n"); | |
119 #endif | |
120 } | |
121 | |
122 void icq_UDPQueueItemResend(icq_UDPQueueItem *p) | |
123 { | |
124 p->attempts++; | |
125 if (p->attempts > 6) | |
126 { | |
127 icq_Disconnect(p->icqlink); | |
128 invoke_callback(p->icqlink, icq_Disconnected)(p->icqlink); | |
129 return; | |
130 } | |
131 | |
132 icq_UDPSockWriteDirect(p->icqlink, p->pack); | |
133 } | |
134 |