Mercurial > pidgin
comparison src/protocols/yahoo/ycht.c @ 13200:33bef17125c2
[gaim-migrate @ 15563]
This is the soon-to-be-infamous nonblocking network activity patch that I've been working on. Feel free to yell at me if this makes you unhappy.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Thu, 09 Feb 2006 04:17:56 +0000 |
parents | f4e58e94ced3 |
children | 10e8eb6a4910 |
comparison
equal
deleted
inserted
replaced
13199:d8f238864c88 | 13200:33bef17125c2 |
---|---|
263 } | 263 } |
264 | 264 |
265 return ret; | 265 return ret; |
266 } | 266 } |
267 | 267 |
268 static void ycht_packet_send_write_cb(gpointer data, gint source, GaimInputCondition cond) | |
269 { | |
270 YchtConn *ycht = data; | |
271 int ret, writelen; | |
272 | |
273 writelen = gaim_circ_buffer_get_max_read(ycht->txbuf); | |
274 | |
275 if (writelen == 0) { | |
276 gaim_input_remove(ycht->tx_handler); | |
277 ycht->tx_handler = 0; | |
278 return; | |
279 } | |
280 | |
281 ret = write(ycht->fd, ycht->txbuf->outptr, writelen); | |
282 | |
283 if (ret < 0 && errno == EAGAIN) | |
284 return; | |
285 else if (ret <= 0) { | |
286 /* TODO: error handling */ | |
287 /* | |
288 gaim_connection_error(gaim_account_get_connection(irc->account), | |
289 _("Server has disconnected")); | |
290 */ | |
291 return; | |
292 } | |
293 | |
294 gaim_circ_buffer_mark_read(ycht->txbuf, ret); | |
295 | |
296 } | |
297 | |
268 static void ycht_packet_send(YchtConn *ycht, YchtPkt *pkt) | 298 static void ycht_packet_send(YchtConn *ycht, YchtPkt *pkt) |
269 { | 299 { |
270 int len, pos; | 300 int len, pos, written; |
271 char *buf; | 301 char *buf; |
272 GList *l; | 302 GList *l; |
273 | 303 |
274 g_return_if_fail(ycht != NULL); | 304 g_return_if_fail(ycht != NULL); |
275 g_return_if_fail(pkt != NULL); | 305 g_return_if_fail(pkt != NULL); |
293 memcpy(buf + pos, YCHT_SEP, strlen(YCHT_SEP)); | 323 memcpy(buf + pos, YCHT_SEP, strlen(YCHT_SEP)); |
294 pos += strlen(YCHT_SEP); | 324 pos += strlen(YCHT_SEP); |
295 } | 325 } |
296 } | 326 } |
297 | 327 |
298 write(ycht->fd, buf, len); | 328 if (!ycht->tx_handler) |
329 written = write(ycht->fd, buf, len); | |
330 else { | |
331 written = -1; | |
332 errno = EAGAIN; | |
333 } | |
334 | |
335 if (written < 0 && errno == EAGAIN) | |
336 written = 0; | |
337 else if (written <= 0) { | |
338 /* TODO: Error handling (was none before NBIO changes) */ | |
339 written = 0; | |
340 } | |
341 | |
342 if (written < len) { | |
343 if (!ycht->tx_handler) | |
344 ycht->tx_handler = gaim_input_add(ycht->fd, | |
345 GAIM_INPUT_WRITE, ycht_packet_send_write_cb, | |
346 ycht); | |
347 gaim_circ_buffer_append(ycht->txbuf, buf + written, | |
348 len - written); | |
349 } | |
350 | |
299 g_free(buf); | 351 g_free(buf); |
300 } | 352 } |
301 | 353 |
302 static void ycht_packet_read(YchtPkt *pkt, const char *buf, int len) | 354 static void ycht_packet_read(YchtPkt *pkt, const char *buf, int len) |
303 { | 355 { |
386 if (ycht->fd > 0) | 438 if (ycht->fd > 0) |
387 close(ycht->fd); | 439 close(ycht->fd); |
388 if (ycht->inpa) | 440 if (ycht->inpa) |
389 gaim_input_remove(ycht->inpa); | 441 gaim_input_remove(ycht->inpa); |
390 | 442 |
391 if (ycht->rxqueue) | 443 if (ycht->tx_handler) |
392 g_free(ycht->rxqueue); | 444 gaim_input_remove(ycht->tx_handler); |
445 | |
446 gaim_circ_buffer_destroy(ycht->txbuf); | |
447 | |
448 g_free(ycht->rxqueue); | |
393 | 449 |
394 g_free(ycht); | 450 g_free(ycht); |
395 } | 451 } |
396 | 452 |
397 static void ycht_connection_error(YchtConn *ycht, const gchar *error) | 453 static void ycht_connection_error(YchtConn *ycht, const gchar *error) |
406 YchtConn *ycht = data; | 462 YchtConn *ycht = data; |
407 char buf[1024]; | 463 char buf[1024]; |
408 int len; | 464 int len; |
409 | 465 |
410 len = read(ycht->fd, buf, sizeof(buf)); | 466 len = read(ycht->fd, buf, sizeof(buf)); |
467 | |
468 if (len < 0 && errno == EAGAIN) | |
469 return; | |
411 | 470 |
412 if (len <= 0) { | 471 if (len <= 0) { |
413 ycht_connection_error(ycht, _("Unable to read")); | 472 ycht_connection_error(ycht, _("Unable to read")); |
414 return; | 473 return; |
415 } | 474 } |
527 { | 586 { |
528 YchtPkt *pkt; | 587 YchtPkt *pkt; |
529 char *tmp; | 588 char *tmp; |
530 | 589 |
531 tmp = g_strdup(room); | 590 tmp = g_strdup(room); |
532 if (ycht->room) | 591 g_free(ycht->room); |
533 g_free(ycht->room); | |
534 ycht->room = tmp; | 592 ycht->room = tmp; |
535 | 593 |
536 if (!ycht->logged_in) | 594 if (!ycht->logged_in) |
537 return; | 595 return; |
538 | 596 |