Changeset 5ebff60 for protocols/oscar/txqueue.c
- Timestamp:
- 2015-02-20T22:50:54Z (9 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/oscar/txqueue.c
raf359b4 r5ebff60 32 32 } 33 33 34 if (!(fr = (aim_frame_t *) g_new0(aim_frame_t,1)))34 if (!(fr = (aim_frame_t *) g_new0(aim_frame_t, 1))) { 35 35 return NULL; 36 37 fr->conn = conn; 36 } 37 38 fr->conn = conn; 38 39 39 40 fr->hdrtype = framing; … … 43 44 fr->hdr.flap.type = chan; 44 45 45 } else 46 } else { 46 47 imcb_error(sess->aux_data, "unknown framing"); 48 } 47 49 48 50 if (datalen > 0) { 49 51 guint8 *data; 50 52 51 if (!(data = (unsigned char *) g_malloc(datalen))) {53 if (!(data = (unsigned char *) g_malloc(datalen))) { 52 54 aim_frame_destroy(fr); 53 55 return NULL; … … 90 92 91 93 /* see overhead note in aim_rxqueue counterpart */ 92 if (!sess->queue_outgoing) 94 if (!sess->queue_outgoing) { 93 95 sess->queue_outgoing = fr; 94 else {96 } else { 95 97 aim_frame_t *cur; 96 98 97 for (cur = sess->queue_outgoing; cur->next; cur = cur->next) 99 for (cur = sess->queue_outgoing; cur->next; cur = cur->next) { 98 100 ; 101 } 99 102 cur->next = fr; 100 103 } … … 111 114 * Basically the same as its __queuebased couterpart, however 112 115 * instead of doing a list append, it just calls aim_tx_sendframe() 113 * right here. 114 * 116 * right here. 117 * 115 118 */ 116 119 static int aim_tx_enqueue__immediate(aim_session_t *sess, aim_frame_t *fr) … … 123 126 } 124 127 125 if (fr->hdrtype == AIM_FRAMETYPE_FLAP) 128 if (fr->hdrtype == AIM_FRAMETYPE_FLAP) { 126 129 fr->hdr.flap.seqnum = aim_get_next_txseqnum(fr->conn); 130 } 127 131 128 132 fr->handled = 0; /* not sent yet */ … … 137 141 int aim_tx_setenqueue(aim_session_t *sess, int what, int (*func)(aim_session_t *, aim_frame_t *)) 138 142 { 139 140 if (what == AIM_TX_QUEUED) 143 144 if (what == AIM_TX_QUEUED) { 141 145 sess->tx_enqueue = &aim_tx_enqueue__queuebased; 142 else if (what == AIM_TX_IMMEDIATE)146 } else if (what == AIM_TX_IMMEDIATE) { 143 147 sess->tx_enqueue = &aim_tx_enqueue__immediate; 144 else if (what == AIM_TX_USER) {145 if (!func) 148 } else if (what == AIM_TX_USER) { 149 if (!func) { 146 150 return -EINVAL; 151 } 147 152 sess->tx_enqueue = func; 148 } else 153 } else { 149 154 return -EINVAL; /* unknown action */ 150 155 156 } 151 157 return 0; 152 158 } … … 154 160 int aim_tx_enqueue(aim_session_t *sess, aim_frame_t *fr) 155 161 { 156 162 157 163 /* 158 164 * If we want to send a connection thats inprogress, we have to force … … 160 166 * want. 161 167 */ 162 if (fr && fr->conn && 163 168 if (fr && fr->conn && 169 (fr->conn->status & AIM_CONN_STATUS_INPROGRESS)) { 164 170 return aim_tx_enqueue__queuebased(sess, fr); 165 171 } … … 168 174 } 169 175 170 /* 176 /* 171 177 * aim_get_next_txseqnum() 172 178 * … … 180 186 { 181 187 flap_seqnum_t ret; 182 188 183 189 ret = ++conn->seqnum; 184 190 … … 193 199 int ret; 194 200 195 ret = send(fd, ((unsigned char *) buf)+cur, left, 0);196 if (ret == -1) 201 ret = send(fd, ((unsigned char *) buf) + cur, left, 0); 202 if (ret == -1) { 197 203 return -1; 198 else if (ret == 0)204 } else if (ret == 0) { 199 205 return cur; 206 } 200 207 201 208 cur += ret; … … 209 216 { 210 217 int wrote = 0; 211 if (!bs || !conn || (count < 0)) 218 219 if (!bs || !conn || (count < 0)) { 212 220 return -EINVAL; 213 214 if (count > aim_bstream_empty(bs)) 221 } 222 223 if (count > aim_bstream_empty(bs)) { 215 224 count = aim_bstream_empty(bs); /* truncate to remaining space */ 216 225 226 } 217 227 if (count) { 218 228 if (count - wrote) { 219 229 wrote = wrote + aim_send(conn->fd, bs->data + bs->offset + wrote, count - wrote); 220 230 } 221 222 } 223 231 232 } 233 224 234 bs->offset += wrote; 225 235 226 return wrote; 236 return wrote; 227 237 } 228 238 … … 235 245 payloadlen = aim_bstream_curpos(&fr->data); 236 246 237 if (!(obs_raw = g_malloc(6 + payloadlen))) 247 if (!(obs_raw = g_malloc(6 + payloadlen))) { 238 248 return -ENOMEM; 249 } 239 250 240 251 aim_bstream_init(&obs, obs_raw, 6 + payloadlen); … … 252 263 obslen = aim_bstream_curpos(&obs); 253 264 aim_bstream_rewind(&obs); 254 if (aim_bstream_send(&obs, fr->conn, obslen) != obslen) 265 if (aim_bstream_send(&obs, fr->conn, obslen) != obslen) { 255 266 err = -errno; 256 267 } 268 257 269 g_free(obs_raw); /* XXX aim_bstream_free */ 258 270 … … 265 277 int aim_tx_sendframe(aim_session_t *sess, aim_frame_t *fr) 266 278 { 267 if (fr->hdrtype == AIM_FRAMETYPE_FLAP) 279 if (fr->hdrtype == AIM_FRAMETYPE_FLAP) { 268 280 return sendframe_flap(sess, fr); 281 } 269 282 return -1; 270 283 } … … 276 289 for (cur = sess->queue_outgoing; cur; cur = cur->next) { 277 290 278 if (cur->handled) 279 continue; /* already been sent */ 280 281 if (cur->conn && (cur->conn->status & AIM_CONN_STATUS_INPROGRESS)) 291 if (cur->handled) { 292 continue; /* already been sent */ 293 294 } 295 if (cur->conn && (cur->conn->status & AIM_CONN_STATUS_INPROGRESS)) { 282 296 continue; 297 } 283 298 284 299 /* … … 287 302 */ 288 303 if ((cur->conn->lastactivity + cur->conn->forcedlatency) >= time(NULL)) { 289 /* 290 * XXX should be a break! we dont want to block the 304 /* 305 * XXX should be a break! we dont want to block the 291 306 * upper layers 292 307 * … … 309 324 /* 310 325 * aim_tx_purgequeue() 311 * 312 * This is responsable for removing sent commands from the transmit 326 * 327 * This is responsable for removing sent commands from the transmit 313 328 * queue. This is not a required operation, but it of course helps 314 * reduce memory footprint at run time! 329 * reduce memory footprint at run time! 315 330 * 316 331 */ … … 326 341 aim_frame_destroy(cur); 327 342 328 } else 343 } else { 329 344 prev = &cur->next; 345 } 330 346 } 331 347 … … 347 363 348 364 for (cur = sess->queue_outgoing; cur; cur = cur->next) { 349 if (cur->conn == conn) 365 if (cur->conn == conn) { 350 366 cur->handled = 1; 367 } 351 368 } 352 369
Note: See TracChangeset
for help on using the changeset viewer.