annotate src/protocols/oscar/txqueue.c @ 13221:cc85a78191cc

[gaim-migrate @ 15585] SF Patch #1428104 from Sadrul Fixes SF Bug #1424843 "This resizes an icon for display when the appropriate flags are set." committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sat, 11 Feb 2006 05:29:12 +0000
parents 9a0a6e74aafd
children f2431a7e33aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /*
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
2 * txqueue.c
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 *
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 7945
diff changeset
4 * Herein lies all the management routines for the transmit (Tx) queue.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 #define FAIM_INTERNAL
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 #include <aim.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 #ifndef _WIN32
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 #include <sys/socket.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3048
diff changeset
13 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3048
diff changeset
14 #include "win32dep.h"
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 #endif
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 * Allocate a new tx frame.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 * This is more for looks than anything else.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 * Right now, that is. If/when we implement a pool of transmit
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 * frames, this will become the request-an-unused-frame part.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 *
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
25 * framing = AIM_FRAMETYPE_OFT/FLAP
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
26 * chan = channel for FLAP, hdrtype for OFT
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 */
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3048
diff changeset
29 faim_internal aim_frame_t *aim_tx_new(aim_session_t *sess, aim_conn_t *conn, fu8_t framing, fu16_t chan, int datalen)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
31 aim_frame_t *fr;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
32
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
33 if (!sess || !conn) {
11253
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11162
diff changeset
34 gaim_debug_misc("oscar", "aim_tx_new: No session or no connection specified!\n");
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
35 return NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
36 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
38 /* For sanity... */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
39 if ((conn->type == AIM_CONN_TYPE_RENDEZVOUS) || (conn->type == AIM_CONN_TYPE_LISTENER)) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
40 if (framing != AIM_FRAMETYPE_OFT) {
11253
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11162
diff changeset
41 gaim_debug_misc("oscar", "aim_tx_new: attempted to allocate inappropriate frame type for rendezvous connection\n");
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
42 return NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
43 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
44 } else {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
45 if (framing != AIM_FRAMETYPE_FLAP) {
11253
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11162
diff changeset
46 gaim_debug_misc("oscar", "aim_tx_new: attempted to allocate inappropriate frame type for FLAP connection\n");
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
47 return NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
48 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
49 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
50
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
51 if (!(fr = (aim_frame_t *)calloc(1, sizeof(aim_frame_t))))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
52 return NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53
10267
9cafe038c95e [gaim-migrate @ 11413]
Mark Doliner <mark@kingant.net>
parents: 9457
diff changeset
54 fr->conn = conn;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
55 fr->hdrtype = framing;
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
56 if (fr->hdrtype == AIM_FRAMETYPE_FLAP)
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
57 fr->hdr.flap.channel = chan;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
58 else if (fr->hdrtype == AIM_FRAMETYPE_OFT)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
59 fr->hdr.rend.type = chan;
10267
9cafe038c95e [gaim-migrate @ 11413]
Mark Doliner <mark@kingant.net>
parents: 9457
diff changeset
60 else
11253
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11162
diff changeset
61 gaim_debug_misc("oscar", "tx_new: unknown framing\n");
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
63 if (datalen > 0) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
64 fu8_t *data;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
66 if (!(data = (unsigned char *)malloc(datalen))) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
67 aim_frame_destroy(fr);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
68 return NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
69 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
71 aim_bstream_init(&fr->data, data, datalen);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
72 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
73
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
74 return fr;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
77 /*
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
78 * This increments the tx command count, and returns the seqnum
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
79 * that should be stamped on the next FLAP packet sent. This is
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
80 * normally called during the final step of packet preparation
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
81 * before enqueuement (in aim_tx_enqueue()).
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
82 */
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
83 static flap_seqnum_t aim_get_next_txseqnum(aim_conn_t *conn)
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
84 {
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
85 flap_seqnum_t ret;
10267
9cafe038c95e [gaim-migrate @ 11413]
Mark Doliner <mark@kingant.net>
parents: 9457
diff changeset
86
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
87 ret = ++conn->seqnum;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
88
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
89 return ret;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
90 }
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
91
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 * The overall purpose here is to enqueue the passed in command struct
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 * into the outgoing (tx) queue. Basically...
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 7945
diff changeset
95 * 1) Make a scope-irrelevant copy of the struct
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 * 3) Mark as not-sent-yet
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 * 4) Enqueue the struct into the list
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 * 6) Return
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 * Note that this is only used when doing queue-based transmitting;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 * that is, when sess->tx_enqueue is set to &aim_tx_enqueue__queuebased.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
104 static int aim_tx_enqueue__queuebased(aim_session_t *sess, aim_frame_t *fr)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
106
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
107 if (!fr->conn) {
11253
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11162
diff changeset
108 gaim_debug_warning("oscar", "aim_tx_enqueue: enqueueing packet with no connecetion\n");
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
109 fr->conn = aim_getconn_type(sess, AIM_CONN_TYPE_BOS);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
110 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
111
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
112 if (fr->hdrtype == AIM_FRAMETYPE_FLAP) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
113 /* assign seqnum -- XXX should really not assign until hardxmit */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
114 fr->hdr.flap.seqnum = aim_get_next_txseqnum(fr->conn);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
115 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
117 fr->handled = 0; /* not sent yet */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
119 /* see overhead note in aim_rxqueue counterpart */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
120 if (!sess->queue_outgoing)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
121 sess->queue_outgoing = fr;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
122 else {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
123 aim_frame_t *cur;
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
124 for (cur = sess->queue_outgoing; cur->next; cur = cur->next);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
125 cur->next = fr;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
126 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
128 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 * Parallel to aim_tx_enqueue__queuebased, however, this bypasses
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133 * the whole queue mess when you want immediate writes to happen.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 * Basically the same as its __queuebased couterpart, however
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 * instead of doing a list append, it just calls aim_tx_sendframe()
11253
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11162
diff changeset
137 * right here.
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11162
diff changeset
138 *
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
140 static int aim_tx_enqueue__immediate(aim_session_t *sess, aim_frame_t *fr)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 {
9457
14bffb758b34 [gaim-migrate @ 10281]
Tim Ringenbach <marv@pidgin.im>
parents: 8971
diff changeset
142 int ret;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
143
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
144 if (!fr->conn) {
11253
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11162
diff changeset
145 gaim_debug_error("oscar", "aim_tx_enqueue: packet has no connection\n");
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
146 aim_frame_destroy(fr);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
147 return 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
148 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
150 if (fr->hdrtype == AIM_FRAMETYPE_FLAP)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
151 fr->hdr.flap.seqnum = aim_get_next_txseqnum(fr->conn);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
153 fr->handled = 0; /* not sent yet */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154
9457
14bffb758b34 [gaim-migrate @ 10281]
Tim Ringenbach <marv@pidgin.im>
parents: 8971
diff changeset
155 ret = aim_tx_sendframe(sess, fr);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
157 aim_frame_destroy(fr);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158
9457
14bffb758b34 [gaim-migrate @ 10281]
Tim Ringenbach <marv@pidgin.im>
parents: 8971
diff changeset
159 return ret;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
162 faim_export int aim_tx_setenqueue(aim_session_t *sess, int what, int (*func)(aim_session_t *, aim_frame_t *))
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 {
10267
9cafe038c95e [gaim-migrate @ 11413]
Mark Doliner <mark@kingant.net>
parents: 9457
diff changeset
164
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
165 if (what == AIM_TX_QUEUED)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
166 sess->tx_enqueue = &aim_tx_enqueue__queuebased;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
167 else if (what == AIM_TX_IMMEDIATE)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
168 sess->tx_enqueue = &aim_tx_enqueue__immediate;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
169 else if (what == AIM_TX_USER) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
170 if (!func)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
171 return -EINVAL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
172 sess->tx_enqueue = func;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
173 } else
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
174 return -EINVAL; /* unknown action */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
176 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
179 faim_internal int aim_tx_enqueue(aim_session_t *sess, aim_frame_t *fr)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 {
10267
9cafe038c95e [gaim-migrate @ 11413]
Mark Doliner <mark@kingant.net>
parents: 9457
diff changeset
181
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
182 /*
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 7945
diff changeset
183 * If we want to send on a connection that is in progress, we have to force
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
184 * them to use the queue based version. Otherwise, use whatever they
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
185 * want.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
186 */
9457
14bffb758b34 [gaim-migrate @ 10281]
Tim Ringenbach <marv@pidgin.im>
parents: 8971
diff changeset
187 if (fr && fr->conn &&
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
188 (fr->conn->status & AIM_CONN_STATUS_INPROGRESS)) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
189 return aim_tx_enqueue__queuebased(sess, fr);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
190 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
191
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
192 return (*sess->tx_enqueue)(sess, fr);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
195 static int aim_send(int fd, const void *buf, size_t count)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
197 int left, cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
198
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
199 for (cur = 0, left = count; left; ) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
200 int ret;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
201
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
202 ret = send(fd, ((unsigned char *)buf)+cur, left, 0);
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
203
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
204 if (ret == -1)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
205 return -1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
206 else if (ret == 0)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
207 return cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
208
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
209 cur += ret;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
210 left -= ret;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
211 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
212
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
213 return cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
214 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
215
12428
9a0a6e74aafd [gaim-migrate @ 14735]
Richard Laager <rlaager@wiktel.com>
parents: 12427
diff changeset
216 faim_internal int aim_bstream_send(aim_bstream_t *bs, aim_conn_t *conn, size_t count)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
217 {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
218 int wrote = 0;
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
219
12427
c5c0f714d8bc [gaim-migrate @ 14734]
Richard Laager <rlaager@wiktel.com>
parents: 11369
diff changeset
220 if (!bs || !conn)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
221 return -EINVAL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
222
7945
0a0be07f066a [gaim-migrate @ 8619]
Mark Doliner <mark@kingant.net>
parents: 7806
diff changeset
223 /* Make sure we don't send past the end of the bs */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
224 if (count > aim_bstream_empty(bs))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
225 count = aim_bstream_empty(bs); /* truncate to remaining space */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
226
3044
e68e2ba82310 [gaim-migrate @ 3057]
Sean Egan <seanegan@gmail.com>
parents: 2270
diff changeset
227 if (count) {
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
228 /*
9457
14bffb758b34 [gaim-migrate @ 10281]
Tim Ringenbach <marv@pidgin.im>
parents: 8971
diff changeset
229 * I need to rewrite this. "Updating the UI" doesn't make sense. The program is
14bffb758b34 [gaim-migrate @ 10281]
Tim Ringenbach <marv@pidgin.im>
parents: 8971
diff changeset
230 * blocked and the UI can't redraw. We're blocking all of Gaim. We need to set
14bffb758b34 [gaim-migrate @ 10281]
Tim Ringenbach <marv@pidgin.im>
parents: 8971
diff changeset
231 * up an actual txqueue and a GAIM_INPUT_WRITE callback and only write when we
14bffb758b34 [gaim-migrate @ 10281]
Tim Ringenbach <marv@pidgin.im>
parents: 8971
diff changeset
232 * can. Why is this file called txqueue anyway? Lets rename it to txblock.
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
233 */
10267
9cafe038c95e [gaim-migrate @ 11413]
Mark Doliner <mark@kingant.net>
parents: 9457
diff changeset
234 if ((conn->type == AIM_CONN_TYPE_RENDEZVOUS) &&
3044
e68e2ba82310 [gaim-migrate @ 3057]
Sean Egan <seanegan@gmail.com>
parents: 2270
diff changeset
235 (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM)) {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
236 const char *sn = aim_odc_getsn(conn);
3044
e68e2ba82310 [gaim-migrate @ 3057]
Sean Egan <seanegan@gmail.com>
parents: 2270
diff changeset
237 aim_rxcallback_t userfunc;
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
238
3044
e68e2ba82310 [gaim-migrate @ 3057]
Sean Egan <seanegan@gmail.com>
parents: 2270
diff changeset
239 while (count - wrote > 1024) {
8971
f831a38eb6ba [gaim-migrate @ 9745]
Mark Doliner <mark@kingant.net>
parents: 8735
diff changeset
240 int ret;
f831a38eb6ba [gaim-migrate @ 9745]
Mark Doliner <mark@kingant.net>
parents: 8735
diff changeset
241
f831a38eb6ba [gaim-migrate @ 9745]
Mark Doliner <mark@kingant.net>
parents: 8735
diff changeset
242 ret = aim_send(conn->fd, bs->data + bs->offset + wrote, 1024);
f831a38eb6ba [gaim-migrate @ 9745]
Mark Doliner <mark@kingant.net>
parents: 8735
diff changeset
243 if (ret > 0)
f831a38eb6ba [gaim-migrate @ 9745]
Mark Doliner <mark@kingant.net>
parents: 8735
diff changeset
244 wrote += ret;
9457
14bffb758b34 [gaim-migrate @ 10281]
Tim Ringenbach <marv@pidgin.im>
parents: 8971
diff changeset
245 if (ret < 0)
14bffb758b34 [gaim-migrate @ 10281]
Tim Ringenbach <marv@pidgin.im>
parents: 8971
diff changeset
246 return -1;
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
247 if ((userfunc=aim_callhandler(conn->sessv, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_IMAGETRANSFER)))
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
248 userfunc(conn->sessv, NULL, sn, count-wrote>1024 ? ((double)wrote / count) : 1);
3044
e68e2ba82310 [gaim-migrate @ 3057]
Sean Egan <seanegan@gmail.com>
parents: 2270
diff changeset
249 }
e68e2ba82310 [gaim-migrate @ 3057]
Sean Egan <seanegan@gmail.com>
parents: 2270
diff changeset
250 }
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
251
3044
e68e2ba82310 [gaim-migrate @ 3057]
Sean Egan <seanegan@gmail.com>
parents: 2270
diff changeset
252 if (count - wrote) {
e68e2ba82310 [gaim-migrate @ 3057]
Sean Egan <seanegan@gmail.com>
parents: 2270
diff changeset
253 wrote = wrote + aim_send(conn->fd, bs->data + bs->offset + wrote, count - wrote);
e68e2ba82310 [gaim-migrate @ 3057]
Sean Egan <seanegan@gmail.com>
parents: 2270
diff changeset
254 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
255 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
256
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
257 bs->offset += wrote;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
258
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
259 return wrote;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
260 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
261
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
262 static int sendframe_flap(aim_session_t *sess, aim_frame_t *fr)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
263 {
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
264 aim_bstream_t bs;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
265 fu8_t *bs_raw;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
266 int payloadlen, err = 0, bslen;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
267
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
268 payloadlen = aim_bstream_curpos(&fr->data);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
269
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
270 if (!(bs_raw = malloc(6 + payloadlen)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
271 return -ENOMEM;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
272
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
273 aim_bstream_init(&bs, bs_raw, 6 + payloadlen);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
274
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
275 /* FLAP header */
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
276 aimbs_put8(&bs, 0x2a);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
277 aimbs_put8(&bs, fr->hdr.flap.channel);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
278 aimbs_put16(&bs, fr->hdr.flap.seqnum);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
279 aimbs_put16(&bs, payloadlen);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
280
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
281 /* payload */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
282 aim_bstream_rewind(&fr->data);
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
283 aimbs_putbs(&bs, &fr->data, payloadlen);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
284
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
285 bslen = aim_bstream_curpos(&bs);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
286 aim_bstream_rewind(&bs);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
287 if (aim_bstream_send(&bs, fr->conn, bslen) != bslen)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
288 err = -errno;
10267
9cafe038c95e [gaim-migrate @ 11413]
Mark Doliner <mark@kingant.net>
parents: 9457
diff changeset
289
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
290 free(bs_raw); /* XXX aim_bstream_free */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
291
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
292 fr->handled = 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
293 fr->conn->lastactivity = time(NULL);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
294
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
295 return err;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
296 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
297
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
298 static int sendframe_rendezvous(aim_session_t *sess, aim_frame_t *fr)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
299 {
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
300 aim_bstream_t bs;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
301 fu8_t *bs_raw;
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
302 int payloadlen, err = 0, bslen;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
303
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
304 payloadlen = aim_bstream_curpos(&fr->data);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
305
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
306 if (!(bs_raw = malloc(8 + payloadlen)))
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
307 return -ENOMEM;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
308
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
309 aim_bstream_init(&bs, bs_raw, 8 + payloadlen);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
310
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
311 /* Rendezvous header */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
312 aimbs_putraw(&bs, fr->hdr.rend.magic, 4);
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
313 aimbs_put16(&bs, fr->hdr.rend.hdrlen);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
314 aimbs_put16(&bs, fr->hdr.rend.type);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
315
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
316 /* payload */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
317 aim_bstream_rewind(&fr->data);
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
318 aimbs_putbs(&bs, &fr->data, payloadlen);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
319
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
320 bslen = aim_bstream_curpos(&bs);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
321 aim_bstream_rewind(&bs);
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
322 if (aim_bstream_send(&bs, fr->conn, bslen) != bslen)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
323 err = -errno;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
324
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
325 free(bs_raw); /* XXX aim_bstream_free */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
326
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
327 fr->handled = 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
328 fr->conn->lastactivity = time(NULL);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
329
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
330 return err;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
331 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
332
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
333 faim_internal int aim_tx_sendframe(aim_session_t *sess, aim_frame_t *fr)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
334 {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
335 if (fr->hdrtype == AIM_FRAMETYPE_FLAP)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
336 return sendframe_flap(sess, fr);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
337 else if (fr->hdrtype == AIM_FRAMETYPE_OFT)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
338 return sendframe_rendezvous(sess, fr);
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
339
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
340 return -1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
341 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
342
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
343 faim_export int aim_tx_flushqueue(aim_session_t *sess)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
344 {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
345 aim_frame_t *cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
346
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
347 for (cur = sess->queue_outgoing; cur; cur = cur->next) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
348
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
349 if (cur->handled)
11162
ccb38cf22483 [gaim-migrate @ 13263]
Mark Doliner <mark@kingant.net>
parents: 10267
diff changeset
350 continue; /* already been sent */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
351
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
352 if (cur->conn && (cur->conn->status & AIM_CONN_STATUS_INPROGRESS))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
353 continue;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
354
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
355 /*
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
356 * And now for the meager attempt to force transmit
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
357 * latency and avoid missed messages.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
358 */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
359 if ((cur->conn->lastactivity + cur->conn->forcedlatency) >= time(NULL)) {
11162
ccb38cf22483 [gaim-migrate @ 13263]
Mark Doliner <mark@kingant.net>
parents: 10267
diff changeset
360 /*
ccb38cf22483 [gaim-migrate @ 13263]
Mark Doliner <mark@kingant.net>
parents: 10267
diff changeset
361 * XXX should be a break! we don't want to block the
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
362 * upper layers
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
363 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
364 * XXX or better, just do this right.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
365 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
366 */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
367 sleep((cur->conn->lastactivity + cur->conn->forcedlatency) - time(NULL));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
368 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
369
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
370 /* XXX this should call the custom "queuing" function!! */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
371 aim_tx_sendframe(sess, cur);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
372 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
373
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
374 /* purge sent commands from queue */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
375 aim_tx_purgequeue(sess);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
376
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
377 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
378 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
379
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
380 /*
7945
0a0be07f066a [gaim-migrate @ 8619]
Mark Doliner <mark@kingant.net>
parents: 7806
diff changeset
381 * This is responsible for removing sent commands from the transmit
0a0be07f066a [gaim-migrate @ 8619]
Mark Doliner <mark@kingant.net>
parents: 7806
diff changeset
382 * queue. This is not a required operation, but it of course helps
0a0be07f066a [gaim-migrate @ 8619]
Mark Doliner <mark@kingant.net>
parents: 7806
diff changeset
383 * reduce memory footprint at run time!
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
384 */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
385 faim_export void aim_tx_purgequeue(aim_session_t *sess)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
386 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
387 aim_frame_t *cur, **prev;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
388
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
389 for (prev = &sess->queue_outgoing; (cur = *prev); ) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
390 if (cur->handled) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
391 *prev = cur->next;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
392 aim_frame_destroy(cur);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
393 } else
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
394 prev = &cur->next;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
395 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
396
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
397 return;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
398 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
399
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
400 /**
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
401 * Get rid of packets waiting for tx on a dying conn. For now this
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
402 * simply marks all packets as sent and lets them disappear without
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
403 * warning.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
404 *
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
405 * @param sess A session.
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
406 * @param conn Connection that's dying.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
407 */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3630
diff changeset
408 faim_internal void aim_tx_cleanqueue(aim_session_t *sess, aim_conn_t *conn)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
409 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
410 aim_frame_t *cur;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
411
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
412 for (cur = sess->queue_outgoing; cur; cur = cur->next) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
413 if (cur->conn == conn)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
414 cur->handled = 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
415 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
416
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
417 return;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
418 }