comparison plugins/icq/queue.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 0ef6603d986e
children 7b3f1eb1ef7d
comparison
equal deleted inserted replaced
1911:db3104dda736 1912:8ed70631ed15
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
2 /* 3 /*
3 $Id: queue.c 1508 2001-02-22 23:07:34Z warmenhoven $ 4 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
4 $Log$ 5 * Bill Soudan <soudan@kde.org>
5 Revision 1.5 2001/02/22 23:07:34 warmenhoven 6 *
6 updating icqlib 7 * This program is free software; you can redistribute it and/or modify
7 8 * it under the terms of the GNU General Public License as published by
8 Revision 1.13 2001/02/22 05:40:04 bills 9 * the Free Software Foundation; either version 2 of the License, or
9 port tcp connect timeout code and UDP queue to new timeout manager 10 * (at your option) any later version.
10 11 *
11 Revision 1.12 2000/12/19 06:00:07 bills 12 * This program is distributed in the hope that it will be useful,
12 moved members from ICQLINK to ICQLINK_private struct 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 Revision 1.11 2000/12/06 05:15:45 denis 15 * GNU General Public License for more details.
15 Handling for mass TCP messages has been added based on patch by 16 *
16 Konstantin Klyagin <konst@konst.org.ua> 17 * You should have received a copy of the GNU General Public License
17 18 * along with this program; if not, write to the Free Software
18 Revision 1.10 2000/12/03 21:56:38 bills 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 fixed compilation with gcc-2.96 20 *
20 21 */
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 22
54 #include <stdlib.h> 23 #include <stdlib.h>
55 #include <time.h>
56 24
57 #include "icqlib.h" 25 #include "icqlib.h"
58 #include "queue.h" 26 #include "queue.h"
59 #include "list.h"
60 27
61 void icq_UDPQueueNew(ICQLINK *link) 28 void icq_UDPQueueNew(icq_Link *icqlink)
62 { 29 {
63 link->d->icq_UDPQueue = list_new(); 30 icqlink->d->icq_UDPQueue = icq_ListNew();
64 link->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */ 31 icqlink->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */
65 } 32 }
66 33
67 void icq_UDPQueuePut(ICQLINK *link, icq_Packet *p) 34 void icq_UDPQueuePut(icq_Link *icqlink, icq_Packet *p)
68 { 35 {
69 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem)); 36 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem));
70 #ifdef QUEUE_DEBUG 37 #ifdef QUEUE_DEBUG
71 printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p), 38 printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p),
72 icq_PacketReadUDPOutCmd(p)); 39 icq_PacketReadUDPOutCmd(p));
73 #endif 40 #endif
74 ptr->attempts = 1; 41 ptr->attempts = 1;
75 ptr->timeout = icq_TimeoutNew(link->icq_UDPExpireInterval, 42 ptr->timeout = icq_TimeoutNew(icqlink->icq_UDPExpireInterval,
76 (icq_TimeoutHandler)icq_UDPQueueItemResend, ptr); 43 (icq_TimeoutHandler)icq_UDPQueueItemResend, ptr);
77 ptr->timeout->single_shot = 0; 44 ptr->timeout->single_shot = 0;
78 ptr->pack = p; 45 ptr->pack = p;
79 ptr->icqlink = link; 46 ptr->icqlink = icqlink;
80 #ifdef QUEUE_DEBUG 47 #ifdef QUEUE_DEBUG
81 printf("enqueuing queueitem %p\n", ptr); 48 printf("enqueuing queueitem %p\n", ptr);
82 #endif 49 #endif
83 list_enqueue(link->d->icq_UDPQueue, ptr); 50 icq_ListEnqueue(icqlink->d->icq_UDPQueue, ptr);
84 } 51 }
85 52
86 void _icq_UDPQueueItemFree(void *p) 53 void _icq_UDPQueueItemFree(void *p)
87 { 54 {
88 icq_UDPQueueItem *pitem=(icq_UDPQueueItem *)p; 55 icq_UDPQueueItem *pitem=(icq_UDPQueueItem *)p;
99 66
100 free(p); 67 free(p);
101 } 68 }
102 69
103 /* Frees the queue and dispose it */ 70 /* Frees the queue and dispose it */
104 void icq_UDPQueueDelete(ICQLINK *link) 71 void icq_UDPQueueDelete(icq_Link *icqlink)
105 { 72 {
106 #ifdef QUEUE_DEBUG 73 #ifdef QUEUE_DEBUG
107 printf("icq_UDPQueueDelete\n"); 74 printf("icq_UDPQueueDelete\n");
108 #endif 75 #endif
109 if(link->d->icq_UDPQueue) 76 if(icqlink->d->icq_UDPQueue)
110 { 77 {
111 list_delete(link->d->icq_UDPQueue, _icq_UDPQueueItemFree); 78 icq_ListDelete(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree);
112 link->d->icq_UDPQueue = 0; 79 icqlink->d->icq_UDPQueue = 0;
113 } 80 }
114 } 81 }
115 82
116 /* Only frees the queue */ 83 /* Only frees the queue */
117 void icq_UDPQueueFree(ICQLINK *link) 84 void icq_UDPQueueFree(icq_Link *icqlink)
118 { 85 {
119 #ifdef QUEUE_DEBUG 86 #ifdef QUEUE_DEBUG
120 printf("icq_UDPQueueFree\n"); 87 printf("icq_UDPQueueFree\n");
121 #endif 88 #endif
122 if(link->d->icq_UDPQueue) 89 if(icqlink->d->icq_UDPQueue)
123 list_free(link->d->icq_UDPQueue, _icq_UDPQueueItemFree); 90 icq_ListFree(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree);
124 } 91 }
125 92
126 int icq_UDPQueueFindSeq(void *p, va_list data) 93 int icq_UDPQueueFindSeq(void *p, va_list data)
127 { 94 {
128 WORD seq=va_arg(data, int); 95 WORD seq=va_arg(data, int);
129 return icq_PacketReadUDPOutSeq1(((icq_UDPQueueItem *)p)->pack) == seq; 96 return icq_PacketReadUDPOutSeq1(((icq_UDPQueueItem *)p)->pack) == seq;
130 } 97 }
131 98
132 void icq_UDPQueueDelSeq(ICQLINK *link, WORD seq) 99 void icq_UDPQueueDelSeq(icq_Link *icqlink, WORD seq)
133 { 100 {
134 icq_UDPQueueItem *ptr; 101 icq_UDPQueueItem *ptr;
135 #ifdef QUEUE_DEBUG 102 #ifdef QUEUE_DEBUG
136 printf("icq_UDPQueueDelSeq(seq=0x%04X", seq); 103 printf("icq_UDPQueueDelSeq(seq=0x%04X", seq);
137 #endif 104 #endif
138 ptr = list_traverse(link->d->icq_UDPQueue, icq_UDPQueueFindSeq, seq); 105 ptr = icq_ListTraverse(icqlink->d->icq_UDPQueue, icq_UDPQueueFindSeq, seq);
139 if(ptr) 106 if(ptr)
140 { 107 {
141 #ifdef QUEUE_DEBUG 108 #ifdef QUEUE_DEBUG
142 printf(", cmd=0x%04X",icq_PacketReadUDPOutCmd(ptr->pack)); 109 printf(", cmd=0x%04X",icq_PacketReadUDPOutCmd(ptr->pack));
143 #endif 110 #endif
144 list_remove(link->d->icq_UDPQueue, ptr); 111 icq_ListRemove(icqlink->d->icq_UDPQueue, ptr);
145 _icq_UDPQueueItemFree(ptr); 112 _icq_UDPQueueItemFree(ptr);
146 } 113 }
147 #ifdef QUEUE_DEBUG 114 #ifdef QUEUE_DEBUG
148 printf(")\n"); 115 printf(")\n");
149 #endif 116 #endif