Mercurial > pidgin
comparison plugins/icq/queue.c @ 1498:0ef6603d986e
[gaim-migrate @ 1508]
updating icqlib
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Thu, 22 Feb 2001 23:07:34 +0000 |
| parents | 4c510ca3563f |
| children | 8ed70631ed15 |
comparison
equal
deleted
inserted
replaced
| 1497:c3a40af2b0c4 | 1498:0ef6603d986e |
|---|---|
| 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 $Id: queue.c 1442 2001-01-28 01:52:27Z warmenhoven $ | 3 $Id: queue.c 1508 2001-02-22 23:07:34Z warmenhoven $ |
| 4 $Log$ | 4 $Log$ |
| 5 Revision 1.4 2001/01/28 01:52:27 warmenhoven | 5 Revision 1.5 2001/02/22 23:07:34 warmenhoven |
| 6 icqlib 1.1.5 | 6 updating icqlib |
| 7 | |
| 8 Revision 1.13 2001/02/22 05:40:04 bills | |
| 9 port tcp connect timeout code and UDP queue to new timeout manager | |
| 7 | 10 |
| 8 Revision 1.12 2000/12/19 06:00:07 bills | 11 Revision 1.12 2000/12/19 06:00:07 bills |
| 9 moved members from ICQLINK to ICQLINK_private struct | 12 moved members from ICQLINK to ICQLINK_private struct |
| 10 | 13 |
| 11 Revision 1.11 2000/12/06 05:15:45 denis | 14 Revision 1.11 2000/12/06 05:15:45 denis |
| 59 { | 62 { |
| 60 link->d->icq_UDPQueue = list_new(); | 63 link->d->icq_UDPQueue = list_new(); |
| 61 link->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */ | 64 link->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */ |
| 62 } | 65 } |
| 63 | 66 |
| 64 void icq_UDPQueuePut(ICQLINK *link, icq_Packet *p, int attempt) | 67 void icq_UDPQueuePut(ICQLINK *link, icq_Packet *p) |
| 65 { | 68 { |
| 66 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem)); | 69 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem)); |
| 67 #ifdef QUEUE_DEBUG | 70 #ifdef QUEUE_DEBUG |
| 68 printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p), | 71 printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p), |
| 69 icq_PacketReadUDPOutCmd(p)); | 72 icq_PacketReadUDPOutCmd(p)); |
| 70 #endif | 73 #endif |
| 71 ptr->attempts = attempt; | 74 ptr->attempts = 1; |
| 72 ptr->expire = time(0L)+link->icq_UDPExpireInterval; | 75 ptr->timeout = icq_TimeoutNew(link->icq_UDPExpireInterval, |
| 76 (icq_TimeoutHandler)icq_UDPQueueItemResend, ptr); | |
| 77 ptr->timeout->single_shot = 0; | |
| 73 ptr->pack = p; | 78 ptr->pack = p; |
| 79 ptr->icqlink = link; | |
| 74 #ifdef QUEUE_DEBUG | 80 #ifdef QUEUE_DEBUG |
| 75 printf("enqueuing queueitem %p\n", ptr); | 81 printf("enqueuing queueitem %p\n", ptr); |
| 76 #endif | 82 #endif |
| 77 list_enqueue(link->d->icq_UDPQueue, ptr); | 83 list_enqueue(link->d->icq_UDPQueue, ptr); |
| 78 } | |
| 79 | |
| 80 icq_Packet *icq_UDPQueueGet(ICQLINK *link) | |
| 81 { | |
| 82 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)list_first(link->d->icq_UDPQueue); | |
| 83 icq_Packet *pack = 0L; | |
| 84 if(ptr) | |
| 85 { | |
| 86 pack = ptr->pack; | |
| 87 list_remove(link->d->icq_UDPQueue, (list_node*)ptr); | |
| 88 } | |
| 89 #ifdef QUEUE_DEBUG | |
| 90 if(pack) | |
| 91 printf("icq_UDPQueueGet(cmd=0x%04X)\n", icq_PacketReadUDPOutCmd(pack)); | |
| 92 #endif | |
| 93 return pack; | |
| 94 } | |
| 95 | |
| 96 icq_Packet *icq_UDPQueuePeek(ICQLINK *link) | |
| 97 { | |
| 98 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)list_first(link->d->icq_UDPQueue); | |
| 99 if(ptr) | |
| 100 return ptr->pack; | |
| 101 else | |
| 102 return 0L; | |
| 103 } | 84 } |
| 104 | 85 |
| 105 void _icq_UDPQueueItemFree(void *p) | 86 void _icq_UDPQueueItemFree(void *p) |
| 106 { | 87 { |
| 107 icq_UDPQueueItem *pitem=(icq_UDPQueueItem *)p; | 88 icq_UDPQueueItem *pitem=(icq_UDPQueueItem *)p; |
| 110 printf("_icq_UDPQueueItemFree(%p)\n", p); | 91 printf("_icq_UDPQueueItemFree(%p)\n", p); |
| 111 #endif | 92 #endif |
| 112 | 93 |
| 113 if (pitem->pack) | 94 if (pitem->pack) |
| 114 icq_PacketDelete(pitem->pack); | 95 icq_PacketDelete(pitem->pack); |
| 96 | |
| 97 if (pitem->timeout) | |
| 98 icq_TimeoutDelete(pitem->timeout); | |
| 115 | 99 |
| 116 free(p); | 100 free(p); |
| 117 } | 101 } |
| 118 | 102 |
| 119 /* Frees the queue and dispose it */ | 103 /* Frees the queue and dispose it */ |
| 163 #ifdef QUEUE_DEBUG | 147 #ifdef QUEUE_DEBUG |
| 164 printf(")\n"); | 148 printf(")\n"); |
| 165 #endif | 149 #endif |
| 166 } | 150 } |
| 167 | 151 |
| 168 long icq_UDPQueueInterval(ICQLINK *link) | 152 void icq_UDPQueueItemResend(icq_UDPQueueItem *p) |
| 169 { | 153 { |
| 170 long interval; | 154 p->attempts++; |
| 171 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)list_first(link->d->icq_UDPQueue); | 155 if (p->attempts > 6) |
| 172 if(ptr) | |
| 173 { | 156 { |
| 174 interval = ptr->expire - time(0L); | 157 icq_Disconnect(p->icqlink); |
| 175 return interval>=0?interval:0; | 158 invoke_callback(p->icqlink, icq_Disconnected)(p->icqlink); |
| 159 return; | |
| 176 } | 160 } |
| 177 return -1; | 161 |
| 162 icq_UDPSockWriteDirect(p->icqlink, p->pack); | |
| 178 } | 163 } |
| 164 |
