Mercurial > pidgin.yaz
annotate plugins/icq/queue.c @ 1649:3fe5799b7823
[gaim-migrate @ 1659]
Update libfaim.
committer: Tailor Script <tailor@pidgin.im>
author | Adam Fritzler <mid@auk.cx> |
---|---|
date | Tue, 27 Mar 2001 00:51:09 +0000 |
parents | 0ef6603d986e |
children | 8ed70631ed15 |
rev | line source |
---|---|
1152 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* | |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
3 $Id: queue.c 1508 2001-02-22 23:07:34Z warmenhoven $ |
1152 | 4 $Log$ |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
5 Revision 1.5 2001/02/22 23:07:34 warmenhoven |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
6 updating icqlib |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
7 |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
8 Revision 1.13 2001/02/22 05:40:04 bills |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
9 port tcp connect timeout code and UDP queue to new timeout manager |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
10 |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
11 Revision 1.12 2000/12/19 06:00:07 bills |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
12 moved members from ICQLINK to ICQLINK_private struct |
1192 | 13 |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
14 Revision 1.11 2000/12/06 05:15:45 denis |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
15 Handling for mass TCP messages has been added based on patch by |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
16 Konstantin Klyagin <konst@konst.org.ua> |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
17 |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
18 Revision 1.10 2000/12/03 21:56:38 bills |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
19 fixed compilation with gcc-2.96 |
1152 | 20 |
21 Revision 1.9 2000/07/10 01:31:17 bills | |
22 oops - removed #define LIST_TRACE and #define QUEUE_DEBUG | |
23 | |
24 Revision 1.8 2000/07/10 01:26:56 bills | |
25 added more trace messages, reworked packet delete handling: now happens | |
26 during _icq_UDEQueueItemFree rather than during icq_UDPQueueDelSeq - fixes | |
27 memory leak | |
28 | |
29 Revision 1.7 2000/07/09 22:07:37 bills | |
30 use new list_free | |
31 | |
32 Revision 1.6 2000/06/25 16:30:05 denis | |
33 Some sanity checks were added to icq_UDPQueueDelete() and | |
34 icq_UDPQueueFree() | |
35 | |
36 Revision 1.5 2000/05/10 19:06:59 denis | |
37 UDP outgoing packet queue was implemented. | |
38 | |
39 Revision 1.4 2000/03/30 14:15:28 denis | |
40 Fixed FreeBSD warning about obsolete malloc.h header. | |
41 | |
42 Revision 1.3 2000/01/16 03:59:10 bills | |
43 reworked list code so list_nodes don't need to be inside item structures, | |
44 removed strlist code and replaced with generic list calls | |
45 | |
46 Revision 1.2 1999/09/29 17:06:47 denis | |
47 ICQLINK compatibility added. | |
48 | |
49 Revision 1.1 1999/07/16 12:12:13 denis | |
50 Initial support for outgoing packet queue added. | |
51 | |
52 */ | |
53 | |
54 #include <stdlib.h> | |
55 #include <time.h> | |
56 | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
57 #include "icqlib.h" |
1152 | 58 #include "queue.h" |
59 #include "list.h" | |
60 | |
61 void icq_UDPQueueNew(ICQLINK *link) | |
62 { | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
63 link->d->icq_UDPQueue = list_new(); |
1152 | 64 link->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */ |
65 } | |
66 | |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
67 void icq_UDPQueuePut(ICQLINK *link, icq_Packet *p) |
1152 | 68 { |
69 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem)); | |
70 #ifdef QUEUE_DEBUG | |
71 printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p), | |
72 icq_PacketReadUDPOutCmd(p)); | |
73 #endif | |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
74 ptr->attempts = 1; |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
75 ptr->timeout = icq_TimeoutNew(link->icq_UDPExpireInterval, |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
76 (icq_TimeoutHandler)icq_UDPQueueItemResend, ptr); |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
77 ptr->timeout->single_shot = 0; |
1152 | 78 ptr->pack = p; |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
79 ptr->icqlink = link; |
1152 | 80 #ifdef QUEUE_DEBUG |
81 printf("enqueuing queueitem %p\n", ptr); | |
82 #endif | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
83 list_enqueue(link->d->icq_UDPQueue, ptr); |
1152 | 84 } |
85 | |
86 void _icq_UDPQueueItemFree(void *p) | |
87 { | |
88 icq_UDPQueueItem *pitem=(icq_UDPQueueItem *)p; | |
89 | |
90 #ifdef QUEUE_DEBUG | |
91 printf("_icq_UDPQueueItemFree(%p)\n", p); | |
92 #endif | |
93 | |
94 if (pitem->pack) | |
95 icq_PacketDelete(pitem->pack); | |
96 | |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
97 if (pitem->timeout) |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
98 icq_TimeoutDelete(pitem->timeout); |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
99 |
1152 | 100 free(p); |
101 } | |
102 | |
103 /* Frees the queue and dispose it */ | |
104 void icq_UDPQueueDelete(ICQLINK *link) | |
105 { | |
106 #ifdef QUEUE_DEBUG | |
107 printf("icq_UDPQueueDelete\n"); | |
108 #endif | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
109 if(link->d->icq_UDPQueue) |
1152 | 110 { |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
111 list_delete(link->d->icq_UDPQueue, _icq_UDPQueueItemFree); |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
112 link->d->icq_UDPQueue = 0; |
1152 | 113 } |
114 } | |
115 | |
116 /* Only frees the queue */ | |
117 void icq_UDPQueueFree(ICQLINK *link) | |
118 { | |
119 #ifdef QUEUE_DEBUG | |
120 printf("icq_UDPQueueFree\n"); | |
121 #endif | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
122 if(link->d->icq_UDPQueue) |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
123 list_free(link->d->icq_UDPQueue, _icq_UDPQueueItemFree); |
1152 | 124 } |
125 | |
126 int icq_UDPQueueFindSeq(void *p, va_list data) | |
127 { | |
1192 | 128 WORD seq=va_arg(data, int); |
1152 | 129 return icq_PacketReadUDPOutSeq1(((icq_UDPQueueItem *)p)->pack) == seq; |
130 } | |
131 | |
132 void icq_UDPQueueDelSeq(ICQLINK *link, WORD seq) | |
133 { | |
134 icq_UDPQueueItem *ptr; | |
135 #ifdef QUEUE_DEBUG | |
136 printf("icq_UDPQueueDelSeq(seq=0x%04X", seq); | |
137 #endif | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
138 ptr = list_traverse(link->d->icq_UDPQueue, icq_UDPQueueFindSeq, seq); |
1152 | 139 if(ptr) |
140 { | |
141 #ifdef QUEUE_DEBUG | |
142 printf(", cmd=0x%04X",icq_PacketReadUDPOutCmd(ptr->pack)); | |
143 #endif | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
144 list_remove(link->d->icq_UDPQueue, ptr); |
1152 | 145 _icq_UDPQueueItemFree(ptr); |
146 } | |
147 #ifdef QUEUE_DEBUG | |
148 printf(")\n"); | |
149 #endif | |
150 } | |
151 | |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
152 void icq_UDPQueueItemResend(icq_UDPQueueItem *p) |
1152 | 153 { |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
154 p->attempts++; |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
155 if (p->attempts > 6) |
1152 | 156 { |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
157 icq_Disconnect(p->icqlink); |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
158 invoke_callback(p->icqlink, icq_Disconnected)(p->icqlink); |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
159 return; |
1152 | 160 } |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
161 |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
162 icq_UDPSockWriteDirect(p->icqlink, p->pack); |
1152 | 163 } |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
164 |