Mercurial > pidgin
annotate libfaim/aim_txqueue.c @ 412:ad08e67ec874
[gaim-migrate @ 422]
A woman went to her doctor for advice. She told him that her husband had
developed a penchant for anal sex, and she was not sure that it was such
a good idea.
The doctor asked, "Do you enjoy it?"
She said that she did.
He asked, "Does it hurt you?"
She said that it didn't.
The doctor then told her, "Well, then, there's no reason that you
shouldn't practice anal sex, if that's what you like, so long as you
take care not to get pregnant."
The woman was mystified. She asked "You can get pregnant from anal sex?"
The doctor replied, "Of course. Where do you think attorneys come from?"
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 16 Jun 2000 09:29:36 +0000 |
parents | 0f14e6d8a51b |
children | e4c34ca88d9b |
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 |
10 /* | |
11 * Allocate a new tx frame. | |
12 * | |
13 * This is more for looks than anything else. | |
14 * | |
15 * Right now, that is. If/when we implement a pool of transmit | |
16 * frames, this will become the request-an-unused-frame part. | |
17 */ | |
18 struct command_tx_struct *aim_tx_new(int chan, struct aim_conn_t *conn, int datalen) | |
2 | 19 { |
237 | 20 struct command_tx_struct *new; |
2 | 21 |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
22 if (!conn) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
23 printf("aim_tx_new: ERROR: no connection specified\n"); |
237 | 24 return NULL; |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
25 } |
237 | 26 |
27 new = (struct command_tx_struct *)malloc(sizeof(struct command_tx_struct)); | |
28 if (!new) | |
29 return NULL; | |
30 memset(new, 0, sizeof(struct command_tx_struct)); | |
2 | 31 |
237 | 32 new->conn = conn; |
33 new->type = chan; | |
34 | |
35 if(datalen) { | |
36 new->data = (u_char *)malloc(datalen); | |
37 new->commandlen = datalen; | |
38 } | |
39 | |
40 return new; | |
41 } | |
2 | 42 |
237 | 43 /* |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
44 * aim_tx_enqeue__queuebased() |
237 | 45 * |
46 * The overall purpose here is to enqueue the passed in command struct | |
47 * into the outgoing (tx) queue. Basically... | |
48 * 1) Make a scope-irrelevent copy of the struct | |
49 * 2) Lock the struct | |
50 * 3) Mark as not-sent-yet | |
51 * 4) Enqueue the struct into the list | |
52 * 5) Unlock the struct once it's linked in | |
53 * 6) Return | |
54 * | |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
55 * Note that this is only used when doing queue-based transmitting; |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
56 * 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
|
57 * |
237 | 58 */ |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
59 int aim_tx_enqueue__queuebased(struct aim_session_t *sess, |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
60 struct command_tx_struct *newpacket) |
237 | 61 { |
62 struct command_tx_struct *cur; | |
2 | 63 |
237 | 64 if (newpacket->conn == NULL) { |
65 faimdprintf(1, "aim_tx_enqueue: WARNING: enqueueing packet with no connecetion\n"); | |
66 newpacket->conn = aim_getconn_type(sess, AIM_CONN_TYPE_BOS); | |
67 } | |
68 | |
69 /* assign seqnum */ | |
70 newpacket->seqnum = aim_get_next_txseqnum(newpacket->conn); | |
71 /* set some more fields */ | |
72 newpacket->lock = 1; /* lock */ | |
73 newpacket->sent = 0; /* not sent yet */ | |
74 newpacket->next = NULL; /* always last */ | |
2 | 75 |
237 | 76 /* see overhead note in aim_rxqueue counterpart */ |
77 if (sess->queue_outgoing == NULL) { | |
78 sess->queue_outgoing = newpacket; | |
79 } else { | |
80 for (cur = sess->queue_outgoing; | |
81 cur->next; | |
82 cur = cur->next) | |
83 ; | |
84 cur->next = newpacket; | |
85 } | |
86 | |
87 newpacket->lock = 0; /* unlock so it can be sent */ | |
88 | |
89 #if debug == 2 | |
90 faimdprintf(2, "calling aim_tx_printqueue()\n"); | |
91 aim_tx_printqueue(sess); | |
92 faimdprintf(2, "back from aim_tx_printqueue()\n"); | |
2 | 93 #endif |
94 | |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
95 return 0; |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
96 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
97 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
98 /* |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
99 * aim_tx_enqueue__immediate() |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
100 * |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
101 * Parallel to aim_tx_enqueue__queuebased, however, this bypasses |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
102 * the whole queue mess when you want immediate writes to happen. |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
103 * |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
104 * Basically the same as its __queuebased couterpart, however |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
105 * 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
|
106 * right here. |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
107 * |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
108 */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
109 int aim_tx_enqueue__immediate(struct aim_session_t *sess, struct command_tx_struct *newpacket) |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
110 { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
111 if (newpacket->conn == NULL) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
112 faimdprintf(1, "aim_tx_enqueue: ERROR: packet has no connection\n"); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
113 if (newpacket->data) |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
114 free(newpacket->data); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
115 free(newpacket); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
116 return -1; |
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 newpacket->seqnum = aim_get_next_txseqnum(newpacket->conn); |
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 newpacket->lock = 1; /* lock */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
122 newpacket->sent = 0; /* not sent yet */ |
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 aim_tx_sendframe(newpacket); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
125 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
126 if (newpacket->data) |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
127 free(newpacket->data); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
128 free(newpacket); |
270
cfa39d39dec6
[gaim-migrate @ 280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
129 |
2 | 130 return 0; |
131 } | |
132 | |
133 /* | |
237 | 134 * aim_get_next_txseqnum() |
135 * | |
136 * This increments the tx command count, and returns the seqnum | |
137 * that should be stamped on the next FLAP packet sent. This is | |
138 * normally called during the final step of packet preparation | |
139 * before enqueuement (in aim_tx_enqueue()). | |
140 * | |
2 | 141 */ |
237 | 142 u_int aim_get_next_txseqnum(struct aim_conn_t *conn) |
2 | 143 { |
281
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
144 u_int ret; |
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
145 |
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
146 faim_mutex_lock(&conn->seqnum_lock); |
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
147 ret = ++conn->seqnum; |
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
148 faim_mutex_unlock(&conn->seqnum_lock); |
7b06ba09ffe2
[gaim-migrate @ 291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
279
diff
changeset
|
149 return ret; |
2 | 150 } |
151 | |
152 /* | |
237 | 153 * aim_tx_printqueue() |
154 * | |
155 * This is basically for debuging purposes only. It dumps all the | |
156 * records in the tx queue and their current status. Very helpful | |
157 * if the queue isn't working quite right. | |
158 * | |
2 | 159 */ |
237 | 160 #if debug == 2 |
161 int aim_tx_printqueue(struct aim_session_t *sess) | |
2 | 162 { |
237 | 163 struct command_tx_struct *cur; |
2 | 164 |
237 | 165 faimdprintf(2, "\ncurrent aim_queue_outgoing...\n"); |
166 faimdprintf(2, "\ttype seqnum len lock sent\n"); | |
2 | 167 |
237 | 168 if (sess->queue_outgoing == NULL) |
169 faimdprintf(2, "aim_tx_flushqueue(): queue empty"); | |
170 else { | |
171 for (cur = sess->queue_outgoing; cur; cur = cur->next) { | |
172 faimdprintf(2, "\t %2x %4x %4x %1d %1d\n", | |
173 cur->type, cur->seqnum, | |
174 cur->commandlen, cur->lock, | |
175 cur->sent); | |
176 } | |
177 } | |
178 | |
179 faimdprintf(2, "\n(done printing queue)\n"); | |
2 | 180 |
181 return 0; | |
182 } | |
183 #endif | |
184 | |
185 /* | |
237 | 186 * aim_tx_flushqueue() |
187 * | |
188 * This the function is responsable for putting the queued commands | |
189 * onto the wire. This function is critical to the operation of | |
190 * the queue and therefore is the most prone to brokenness. It | |
191 * seems to be working quite well at this point. | |
192 * | |
193 * Procedure: | |
194 * 1) Traverse the list, only operate on commands that are unlocked | |
195 * and haven't been sent yet. | |
196 * 2) Lock the struct | |
197 * 3) Allocate a temporary buffer to store the finished, fully | |
198 * processed packet in. | |
199 * 4) Build the packet from the command_tx_struct data. | |
200 * 5) Write the packet to the socket. | |
201 * 6) If success, mark the packet sent, if fail report failure, do NOT | |
202 * mark the packet sent (so it will not get purged and therefore | |
203 * be attempted again on next call). | |
204 * 7) Unlock the struct. | |
205 * 8) Free the temp buffer | |
206 * 9) Step to next struct in list and go back to 1. | |
207 * | |
2 | 208 */ |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
209 int aim_tx_sendframe(struct command_tx_struct *cur) |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
210 { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
211 u_char *curPacket; |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
212 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
213 if (!cur) |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
214 return -1; /* fatal */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
215 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
216 cur->lock = 1; /* lock the struct */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
217 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
218 /* allocate full-packet buffer */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
219 curPacket = (char *) malloc(cur->commandlen + 6); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
220 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
221 /* command byte */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
222 curPacket[0] = 0x2a; |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
223 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
224 /* type/family byte */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
225 curPacket[1] = cur->type; |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
226 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
227 /* bytes 3+4: word: FLAP sequence number */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
228 aimutil_put16(curPacket+2, cur->seqnum); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
229 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
230 /* bytes 5+6: word: SNAC len */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
231 aimutil_put16(curPacket+4, cur->commandlen); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
232 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
233 /* bytes 7 and on: raw: SNAC data */ /* XXX: ye gods! get rid of this! */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
234 memcpy(&(curPacket[6]), cur->data, cur->commandlen); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
235 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
236 /* full image of raw packet data now in curPacket */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
237 faim_mutex_lock(&cur->conn->active); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
238 if ( (u_int)write(cur->conn->fd, curPacket, (cur->commandlen + 6)) != (cur->commandlen + 6)) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
239 faim_mutex_unlock(&cur->conn->active); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
240 printf("\nWARNING: Error in sending packet 0x%4x -- will try again next time\n\n", cur->seqnum); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
241 cur->sent = 0; /* mark it unsent */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
242 return 0; /* bail out -- continuable error */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
243 } else { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
244 faimdprintf(2, "\nSENT 0x%4x\n\n", cur->seqnum); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
245 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
246 cur->sent = 1; /* mark the struct as sent */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
247 cur->conn->lastactivity = time(NULL); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
248 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
249 faim_mutex_unlock(&cur->conn->active); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
250 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
251 #if debug > 2 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
252 faimdprintf(2, "\nPacket:"); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
253 for (i = 0; i < (cur->commandlen + 6); i++) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
254 if ((i % 8) == 0) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
255 faimdprintf(2, "\n\t"); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
256 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
257 if (curPacket[i] >= ' ' && curPacket[i]<127) { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
258 faimdprintf(2, "%c=%02x ", curPacket[i], curPacket[i]); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
259 } else { |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
260 faimdprintf(2, "0x%2x ", curPacket[i]); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
261 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
262 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
263 faimdprintf(2, "\n"); |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
264 #endif |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
265 cur->lock = 0; /* unlock the struct */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
266 free(curPacket); /* free up full-packet buffer */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
267 |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
268 return 1; /* success */ |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
269 } |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
270 |
237 | 271 int aim_tx_flushqueue(struct aim_session_t *sess) |
2 | 272 { |
237 | 273 struct command_tx_struct *cur; |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
274 |
2 | 275 #if debug > 1 |
276 int i = 0; | |
277 #endif | |
278 | |
237 | 279 if (sess->queue_outgoing == NULL) |
280 return 0; | |
281 | |
282 faimdprintf(2, "beginning txflush...\n"); | |
283 for (cur = sess->queue_outgoing; cur; cur = cur->next) { | |
284 /* only process if its unlocked and unsent */ | |
285 if (!cur->lock && !cur->sent) { | |
286 | |
287 /* | |
288 * And now for the meager attempt to force transmit | |
289 * latency and avoid missed messages. | |
290 */ | |
291 if ((cur->conn->lastactivity + cur->conn->forcedlatency) >= time(NULL)) { | |
292 /* FIXME FIXME -- should be a break! we dont want to block the upper layers */ | |
293 sleep((cur->conn->lastactivity + cur->conn->forcedlatency) - time(NULL)); | |
294 } | |
2 | 295 |
279
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
296 if (aim_tx_sendframe(cur) == -1) |
501e09c51cbc
[gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
270
diff
changeset
|
297 break; |
2 | 298 } |
237 | 299 } |
2 | 300 |
301 /* purge sent commands from queue */ | |
237 | 302 aim_tx_purgequeue(sess); |
2 | 303 |
304 return 0; | |
305 } | |
306 | |
307 /* | |
237 | 308 * aim_tx_purgequeue() |
309 * | |
310 * This is responsable for removing sent commands from the transmit | |
311 * queue. This is not a required operation, but it of course helps | |
312 * reduce memory footprint at run time! | |
313 * | |
2 | 314 */ |
237 | 315 void aim_tx_purgequeue(struct aim_session_t *sess) |
2 | 316 { |
237 | 317 struct command_tx_struct *cur = NULL; |
318 struct command_tx_struct *tmp; | |
319 | |
320 if (sess->queue_outgoing == NULL) | |
321 return; | |
322 | |
323 if (sess->queue_outgoing->next == NULL) { | |
324 if (!sess->queue_outgoing->lock && sess->queue_outgoing->sent) { | |
325 tmp = sess->queue_outgoing; | |
326 sess->queue_outgoing = NULL; | |
327 free(tmp->data); | |
328 free(tmp); | |
2 | 329 } |
237 | 330 return; |
331 } | |
332 | |
333 for(cur = sess->queue_outgoing; cur->next != NULL; ) { | |
334 if (!cur->next->lock && cur->next->sent) { | |
335 tmp = cur->next; | |
336 cur->next = tmp->next; | |
337 free(tmp->data); | |
338 free(tmp); | |
339 } | |
340 cur = cur->next; | |
2 | 341 |
237 | 342 /* |
343 * Be careful here. Because of the way we just | |
344 * manipulated the pointer, cur may be NULL and | |
345 * the for() will segfault doing the check unless | |
346 * we find this case first. | |
347 */ | |
348 if (cur == NULL) | |
349 break; | |
350 } | |
351 return; | |
2 | 352 } |