1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
4 * $Id: queue.c 2509 2001-10-13 00:06:18Z warmenhoven $
6 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
7 * Bill Soudan <soudan@kde.org>
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.
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.
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.
31 void icq_UDPQueueNew(icq_Link
*icqlink
)
33 icqlink
->d
->icq_UDPQueue
= icq_ListNew();
34 icqlink
->icq_UDPExpireInterval
= 15; /* expire interval = 15 sec */
37 void icq_UDPQueuePut(icq_Link
*icqlink
, icq_Packet
*p
)
39 icq_UDPQueueItem
*ptr
= (icq_UDPQueueItem
*)malloc(sizeof(icq_UDPQueueItem
));
41 printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p
),
42 icq_PacketReadUDPOutCmd(p
));
45 ptr
->timeout
= icq_TimeoutNew(icqlink
->icq_UDPExpireInterval
,
46 (icq_TimeoutHandler
)icq_UDPQueueItemResend
, ptr
);
47 ptr
->timeout
->single_shot
= 0;
49 ptr
->icqlink
= icqlink
;
51 printf("enqueuing queueitem %p\n", ptr
);
53 icq_ListEnqueue(icqlink
->d
->icq_UDPQueue
, ptr
);
56 void _icq_UDPQueueItemFree(void *p
)
58 icq_UDPQueueItem
*pitem
=(icq_UDPQueueItem
*)p
;
61 printf("_icq_UDPQueueItemFree(%p)\n", p
);
65 icq_PacketDelete(pitem
->pack
);
68 icq_TimeoutDelete(pitem
->timeout
);
73 /* Frees the queue and dispose it */
74 void icq_UDPQueueDelete(icq_Link
*icqlink
)
77 printf("icq_UDPQueueDelete\n");
79 if(icqlink
->d
->icq_UDPQueue
)
81 icq_ListDelete(icqlink
->d
->icq_UDPQueue
, _icq_UDPQueueItemFree
);
82 icqlink
->d
->icq_UDPQueue
= 0;
86 /* Only frees the queue */
87 void icq_UDPQueueFree(icq_Link
*icqlink
)
90 printf("icq_UDPQueueFree\n");
92 if(icqlink
->d
->icq_UDPQueue
)
93 icq_ListFree(icqlink
->d
->icq_UDPQueue
, _icq_UDPQueueItemFree
);
96 int icq_UDPQueueFindSeq(void *p
, va_list data
)
98 WORD seq
=va_arg(data
, int);
99 return icq_PacketReadUDPOutSeq1(((icq_UDPQueueItem
*)p
)->pack
) == seq
;
102 void icq_UDPQueueDelSeq(icq_Link
*icqlink
, WORD seq
)
104 icq_UDPQueueItem
*ptr
;
106 printf("icq_UDPQueueDelSeq(seq=0x%04X", seq
);
108 ptr
= icq_ListTraverse(icqlink
->d
->icq_UDPQueue
, icq_UDPQueueFindSeq
, seq
);
112 printf(", cmd=0x%04X",icq_PacketReadUDPOutCmd(ptr
->pack
));
114 icq_ListRemove(icqlink
->d
->icq_UDPQueue
, ptr
);
115 _icq_UDPQueueItemFree(ptr
);
122 void icq_UDPQueueItemResend(icq_UDPQueueItem
*p
)
127 icq_Disconnect(p
->icqlink
);
128 invoke_callback(p
->icqlink
, icq_Disconnected
)(p
->icqlink
);
132 icq_UDPSockWriteDirect(p
->icqlink
, p
->pack
);