Mercurial > pidgin
annotate libfaim/aim_txqueue.c @ 1044:77b6bc7288d3
[gaim-migrate @ 1054]
Thanks to Ryan C. Gordon for the Away message patch!
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Wed, 01 Nov 2000 11:22:04 +0000 |
parents | fa681641643d |
children | efcacae6acdb |
rev | line source |
---|---|
2 | 1 /* |
237 | 2 * aim_txqueue.c |
3 * | |
4 * Herein lies all the mangement routines for the transmit (Tx) queue. | |
5 * | |
2 | 6 */ |
7 | |
283
0f14e6d8a51b
[gaim-migrate @ 293]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
281
diff
changeset
|
8 #include <faim/aim.h> |
237 | 9 |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
10 #ifndef _WIN32 |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
11 #include <sys/socket.h> |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
12 #endif |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
13 |
237 | 14 /* |
15 * Allocate a new tx frame. | |
16 * | |
17 * This is more for looks than anything else. | |
18 * | |
19 * Right now, that is. If/when we implement a pool of transmit | |
20 * frames, this will become the request-an-unused-frame part. | |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
21 * |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
22 * framing = AIM_FRAMETYPE_OFT/OSCAR |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
23 * chan = channel for OSCAR, hdrtype for OFT |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
24 * |
237 | 25 */ |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
26 faim_internal struct command_tx_struct *aim_tx_new(unsigned char framing, int chan, struct aim_conn_t *conn, int datalen) |
2 | 27 { |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
28 struct command_tx_struct *newtx; |
2 | 29 |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
30 if (!conn) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
31 printf("aim_tx_new: ERROR: no connection specified\n"); |
237 | 32 return NULL; |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
33 } |
237 | 34 |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
35 newtx = (struct command_tx_struct *)malloc(sizeof(struct command_tx_struct)); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
36 if (!newtx) |
237 | 37 return NULL; |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
38 memset(newtx, 0, sizeof(struct command_tx_struct)); |
2 | 39 |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
40 newtx->conn = conn; |
237 | 41 |
42 if(datalen) { | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
43 newtx->data = (unsigned char *)malloc(datalen); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
44 newtx->commandlen = datalen; |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
45 } else |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
46 newtx->data = NULL; |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
47 |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
48 newtx->hdrtype = framing; |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
49 if (newtx->hdrtype == AIM_FRAMETYPE_OSCAR) { |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
50 newtx->hdr.oscar.type = chan; |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
51 } else if (newtx->hdrtype == AIM_FRAMETYPE_OFT) { |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
52 newtx->hdr.oft.type = chan; |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
53 newtx->hdr.oft.hdr2len = 0; /* this will get setup by caller */ |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
54 } else { |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
55 printf("tx_new: unknown framing\n"); |
237 | 56 } |
57 | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
58 return newtx; |
237 | 59 } |
2 | 60 |
237 | 61 /* |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
62 * aim_tx_enqeue__queuebased() |
237 | 63 * |
64 * The overall purpose here is to enqueue the passed in command struct | |
65 * into the outgoing (tx) queue. Basically... | |
66 * 1) Make a scope-irrelevent copy of the struct | |
67 * 2) Lock the struct | |
68 * 3) Mark as not-sent-yet | |
69 * 4) Enqueue the struct into the list | |
70 * 5) Unlock the struct once it's linked in | |
71 * 6) Return | |
72 * | |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
73 * Note that this is only used when doing queue-based transmitting; |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
74 * that is, when sess->tx_enqueue is set to &aim_tx_enqueue__queuebased. |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
75 * |
237 | 76 */ |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
77 faim_internal int aim_tx_enqueue__queuebased(struct aim_session_t *sess, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
78 struct command_tx_struct *newpacket) |
237 | 79 { |
80 struct command_tx_struct *cur; | |
2 | 81 |
237 | 82 if (newpacket->conn == NULL) { |
83 faimdprintf(1, "aim_tx_enqueue: WARNING: enqueueing packet with no connecetion\n"); | |
84 newpacket->conn = aim_getconn_type(sess, AIM_CONN_TYPE_BOS); | |
85 } | |
86 | |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
87 if (newpacket->hdrtype == AIM_FRAMETYPE_OSCAR) { |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
88 /* assign seqnum */ |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
89 newpacket->hdr.oscar.seqnum = aim_get_next_txseqnum(newpacket->conn); |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
90 } |
237 | 91 /* set some more fields */ |
92 newpacket->lock = 1; /* lock */ | |
93 newpacket->sent = 0; /* not sent yet */ | |
94 newpacket->next = NULL; /* always last */ | |
2 | 95 |
237 | 96 /* see overhead note in aim_rxqueue counterpart */ |
97 if (sess->queue_outgoing == NULL) { | |
98 sess->queue_outgoing = newpacket; | |
99 } else { | |
100 for (cur = sess->queue_outgoing; | |
101 cur->next; | |
102 cur = cur->next) | |
103 ; | |
104 cur->next = newpacket; | |
105 } | |
106 | |
107 newpacket->lock = 0; /* unlock so it can be sent */ | |
108 | |
109 #if debug == 2 | |
110 faimdprintf(2, "calling aim_tx_printqueue()\n"); | |
111 aim_tx_printqueue(sess); | |
112 faimdprintf(2, "back from aim_tx_printqueue()\n"); | |
2 | 113 #endif |
114 | |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
115 return 0; |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
116 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
117 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
118 /* |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
119 * aim_tx_enqueue__immediate() |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
120 * |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
121 * Parallel to aim_tx_enqueue__queuebased, however, this bypasses |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
122 * the whole queue mess when you want immediate writes to happen. |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
123 * |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
124 * Basically the same as its __queuebased couterpart, however |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
125 * instead of doing a list append, it just calls aim_tx_sendframe() |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
126 * right here. |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
127 * |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
128 */ |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
129 faim_internal int aim_tx_enqueue__immediate(struct aim_session_t *sess, struct command_tx_struct *newpacket) |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
130 { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
131 if (newpacket->conn == NULL) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
132 faimdprintf(1, "aim_tx_enqueue: ERROR: packet has no connection\n"); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
133 if (newpacket->data) |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
134 free(newpacket->data); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
135 free(newpacket); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
136 return -1; |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
137 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
138 |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
139 if (newpacket->hdrtype == AIM_FRAMETYPE_OSCAR) |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
140 newpacket->hdr.oscar.seqnum = aim_get_next_txseqnum(newpacket->conn); |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
141 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
142 newpacket->lock = 1; /* lock */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
143 newpacket->sent = 0; /* not sent yet */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
144 |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
145 aim_tx_sendframe(sess, newpacket); |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
146 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
147 if (newpacket->data) |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
148 free(newpacket->data); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
149 free(newpacket); |
270
cfa39d39dec6
[gaim-migrate @ 280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
150 |
2 | 151 return 0; |
152 } | |
153 | |
154 /* | |
237 | 155 * aim_get_next_txseqnum() |
156 * | |
157 * This increments the tx command count, and returns the seqnum | |
158 * that should be stamped on the next FLAP packet sent. This is | |
159 * normally called during the final step of packet preparation | |
160 * before enqueuement (in aim_tx_enqueue()). | |
161 * | |
2 | 162 */ |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
163 faim_internal unsigned int aim_get_next_txseqnum(struct aim_conn_t *conn) |
2 | 164 { |
281
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
165 u_int ret; |
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
166 |
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
167 faim_mutex_lock(&conn->seqnum_lock); |
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
168 ret = ++conn->seqnum; |
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
169 faim_mutex_unlock(&conn->seqnum_lock); |
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
170 return ret; |
2 | 171 } |
172 | |
173 /* | |
237 | 174 * aim_tx_printqueue() |
175 * | |
176 * This is basically for debuging purposes only. It dumps all the | |
177 * records in the tx queue and their current status. Very helpful | |
178 * if the queue isn't working quite right. | |
179 * | |
2 | 180 */ |
237 | 181 #if debug == 2 |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
182 faim_internal int aim_tx_printqueue(struct aim_session_t *sess) |
2 | 183 { |
237 | 184 struct command_tx_struct *cur; |
2 | 185 |
237 | 186 faimdprintf(2, "\ncurrent aim_queue_outgoing...\n"); |
187 faimdprintf(2, "\ttype seqnum len lock sent\n"); | |
2 | 188 |
237 | 189 if (sess->queue_outgoing == NULL) |
190 faimdprintf(2, "aim_tx_flushqueue(): queue empty"); | |
191 else { | |
192 for (cur = sess->queue_outgoing; cur; cur = cur->next) { | |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
193 faimdprintf(2, "\t %2x %2x %4x %4x %1d %1d\n", |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
194 cur->hdrtype, |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
195 (cur->hdrtype==AIM_FRAMETYPE_OFT)?cur->hdr.oft.type:cur->hdr.oscar.type, |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
196 (cur->hdrtype==AIM_FRAMETYPE_OSCAR)?cur->seqnum:0, |
237 | 197 cur->commandlen, cur->lock, |
198 cur->sent); | |
199 } | |
200 } | |
201 | |
202 faimdprintf(2, "\n(done printing queue)\n"); | |
2 | 203 |
204 return 0; | |
205 } | |
206 #endif | |
207 | |
208 /* | |
237 | 209 * aim_tx_flushqueue() |
210 * | |
211 * This the function is responsable for putting the queued commands | |
212 * onto the wire. This function is critical to the operation of | |
213 * the queue and therefore is the most prone to brokenness. It | |
214 * seems to be working quite well at this point. | |
215 * | |
216 * Procedure: | |
217 * 1) Traverse the list, only operate on commands that are unlocked | |
218 * and haven't been sent yet. | |
219 * 2) Lock the struct | |
220 * 3) Allocate a temporary buffer to store the finished, fully | |
221 * processed packet in. | |
222 * 4) Build the packet from the command_tx_struct data. | |
223 * 5) Write the packet to the socket. | |
224 * 6) If success, mark the packet sent, if fail report failure, do NOT | |
225 * mark the packet sent (so it will not get purged and therefore | |
226 * be attempted again on next call). | |
227 * 7) Unlock the struct. | |
228 * 8) Free the temp buffer | |
229 * 9) Step to next struct in list and go back to 1. | |
230 * | |
2 | 231 */ |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
232 faim_internal int aim_tx_sendframe(struct aim_session_t *sess, struct command_tx_struct *cur) |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
233 { |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
234 int buflen = 0; |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
235 unsigned char *curPacket; |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
236 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
237 if (!cur) |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
238 return -1; /* fatal */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
239 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
240 cur->lock = 1; /* lock the struct */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
241 |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
242 if (cur->hdrtype == AIM_FRAMETYPE_OSCAR) |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
243 buflen = cur->commandlen + 6; |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
244 else if (cur->hdrtype == AIM_FRAMETYPE_OFT) |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
245 buflen = cur->hdr.oft.hdr2len + 8; |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
246 else { |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
247 cur->lock = 0; |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
248 return -1; |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
249 } |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
250 |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
251 /* allocate full-packet buffer */ |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
252 if (!(curPacket = (unsigned char *) malloc(buflen))) { |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
253 cur->lock = 0; |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
254 return -1; |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
255 } |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
256 |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
257 if (cur->hdrtype == AIM_FRAMETYPE_OSCAR) { |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
258 /* command byte */ |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
259 curPacket[0] = 0x2a; |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
260 |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
261 /* type/family byte */ |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
262 curPacket[1] = cur->hdr.oscar.type; |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
263 |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
264 /* bytes 3+4: word: FLAP sequence number */ |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
265 aimutil_put16(curPacket+2, cur->hdr.oscar.seqnum); |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
266 |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
267 /* bytes 5+6: word: SNAC len */ |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
268 aimutil_put16(curPacket+4, cur->commandlen); |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
269 |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
270 /* bytes 7 and on: raw: SNAC data */ /* XXX: ye gods! get rid of this! */ |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
271 memcpy(&(curPacket[6]), cur->data, cur->commandlen); |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
272 |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
273 } else if (cur->hdrtype == AIM_FRAMETYPE_OFT) { |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
274 int z = 0; |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
275 |
960
fa681641643d
[gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
276 z += aimutil_put8(curPacket+z, cur->hdr.oft.magic[0]); |
fa681641643d
[gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
277 z += aimutil_put8(curPacket+z, cur->hdr.oft.magic[1]); |
fa681641643d
[gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
278 z += aimutil_put8(curPacket+z, cur->hdr.oft.magic[2]); |
fa681641643d
[gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
279 z += aimutil_put8(curPacket+z, cur->hdr.oft.magic[3]); |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
280 |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
281 z += aimutil_put16(curPacket+z, cur->hdr.oft.hdr2len + 8); |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
282 z += aimutil_put16(curPacket+z, cur->hdr.oft.type); |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
283 |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
284 memcpy(curPacket+z, cur->hdr.oft.hdr2, cur->hdr.oft.hdr2len); |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
285 } |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
286 |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
287 /* |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
288 * For OSCAR, a full image of the raw packet data now in curPacket. |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
289 * For OFT, an image of just the bloated header is in curPacket, |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
290 * since OFT allows us to do the data in a different write (yay!). |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
291 */ |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
292 faim_mutex_lock(&cur->conn->active); |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
293 if (send(cur->conn->fd, curPacket, buflen, 0) != buflen) { |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
294 faim_mutex_unlock(&cur->conn->active); |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
295 cur->sent = 1; |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
296 aim_conn_kill(sess, &cur->conn); |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
297 return 0; /* bail out */ |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
298 } |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
299 |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
300 if ((cur->hdrtype == AIM_FRAMETYPE_OFT) && cur->commandlen) { |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
301 if (send(cur->conn->fd, cur->data, cur->commandlen, 0) != (int)cur->commandlen) { |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
302 /* |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
303 * Theres nothing we can do about this since we've already sent the |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
304 * header! The connection is unstable. |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
305 */ |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
306 } |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
307 } |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
308 |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
309 cur->sent = 1; /* mark the struct as sent */ |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
310 cur->conn->lastactivity = time(NULL); |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
311 |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
312 faim_mutex_unlock(&cur->conn->active); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
313 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
314 #if debug > 2 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
315 faimdprintf(2, "\nPacket:"); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
316 for (i = 0; i < (cur->commandlen + 6); i++) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
317 if ((i % 8) == 0) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
318 faimdprintf(2, "\n\t"); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
319 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
320 if (curPacket[i] >= ' ' && curPacket[i]<127) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
321 faimdprintf(2, "%c=%02x ", curPacket[i], curPacket[i]); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
322 } else { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
323 faimdprintf(2, "0x%2x ", curPacket[i]); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
324 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
325 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
326 faimdprintf(2, "\n"); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
327 #endif |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
328 cur->lock = 0; /* unlock the struct */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
329 free(curPacket); /* free up full-packet buffer */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
330 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
331 return 1; /* success */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
332 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
333 |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
334 faim_export int aim_tx_flushqueue(struct aim_session_t *sess) |
2 | 335 { |
237 | 336 struct command_tx_struct *cur; |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
337 |
2 | 338 #if debug > 1 |
339 int i = 0; | |
340 #endif | |
341 | |
237 | 342 if (sess->queue_outgoing == NULL) |
343 return 0; | |
344 | |
345 faimdprintf(2, "beginning txflush...\n"); | |
346 for (cur = sess->queue_outgoing; cur; cur = cur->next) { | |
347 /* only process if its unlocked and unsent */ | |
348 if (!cur->lock && !cur->sent) { | |
349 | |
350 /* | |
351 * And now for the meager attempt to force transmit | |
352 * latency and avoid missed messages. | |
353 */ | |
354 if ((cur->conn->lastactivity + cur->conn->forcedlatency) >= time(NULL)) { | |
355 /* FIXME FIXME -- should be a break! we dont want to block the upper layers */ | |
356 sleep((cur->conn->lastactivity + cur->conn->forcedlatency) - time(NULL)); | |
357 } | |
2 | 358 |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
359 if (aim_tx_sendframe(sess, cur) == -1) |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
360 break; |
2 | 361 } |
237 | 362 } |
2 | 363 |
364 /* purge sent commands from queue */ | |
237 | 365 aim_tx_purgequeue(sess); |
2 | 366 |
367 return 0; | |
368 } | |
369 | |
370 /* | |
237 | 371 * aim_tx_purgequeue() |
372 * | |
373 * This is responsable for removing sent commands from the transmit | |
374 * queue. This is not a required operation, but it of course helps | |
375 * reduce memory footprint at run time! | |
376 * | |
2 | 377 */ |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
378 faim_export void aim_tx_purgequeue(struct aim_session_t *sess) |
2 | 379 { |
237 | 380 struct command_tx_struct *cur = NULL; |
381 struct command_tx_struct *tmp; | |
382 | |
383 if (sess->queue_outgoing == NULL) | |
384 return; | |
385 | |
386 if (sess->queue_outgoing->next == NULL) { | |
387 if (!sess->queue_outgoing->lock && sess->queue_outgoing->sent) { | |
388 tmp = sess->queue_outgoing; | |
389 sess->queue_outgoing = NULL; | |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
390 if (tmp->hdrtype == AIM_FRAMETYPE_OFT) |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
391 free(tmp->hdr.oft.hdr2); |
237 | 392 free(tmp->data); |
393 free(tmp); | |
2 | 394 } |
237 | 395 return; |
396 } | |
397 | |
398 for(cur = sess->queue_outgoing; cur->next != NULL; ) { | |
399 if (!cur->next->lock && cur->next->sent) { | |
400 tmp = cur->next; | |
401 cur->next = tmp->next; | |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
402 if (tmp->hdrtype == AIM_FRAMETYPE_OFT) |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
403 free(tmp->hdr.oft.hdr2); |
237 | 404 free(tmp->data); |
405 free(tmp); | |
406 } | |
407 cur = cur->next; | |
2 | 408 |
237 | 409 /* |
410 * Be careful here. Because of the way we just | |
411 * manipulated the pointer, cur may be NULL and | |
412 * the for() will segfault doing the check unless | |
413 * we find this case first. | |
414 */ | |
415 if (cur == NULL) | |
416 break; | |
417 } | |
418 return; | |
2 | 419 } |