Mercurial > pidgin
comparison libpurple/protocols/msn/servconn.c @ 24447:d72c185d0be3
Separate the parsing of data into a separate function from the reading of
data, to remove a big chunk of duplicate code in the read_cb callbacks
for servconn and httpconn
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 15 Nov 2008 16:15:33 +0000 |
parents | ae66b7b3086a |
children | 3d6fe79753c3 |
comparison
equal
deleted
inserted
replaced
24446:ae66b7b3086a | 24447:d72c185d0be3 |
---|---|
364 | 364 |
365 static void | 365 static void |
366 read_cb(gpointer data, gint source, PurpleInputCondition cond) | 366 read_cb(gpointer data, gint source, PurpleInputCondition cond) |
367 { | 367 { |
368 MsnServConn *servconn; | 368 MsnServConn *servconn; |
369 MsnSession *session; | |
370 char buf[MSN_BUF_LEN]; | 369 char buf[MSN_BUF_LEN]; |
371 char *cur, *end, *old_rx_buf; | |
372 gssize len; | 370 gssize len; |
373 int cur_len; | |
374 | 371 |
375 servconn = data; | 372 servconn = data; |
376 session = servconn->session; | |
377 | 373 |
378 if (servconn->type == MSN_SERVCONN_NS) | 374 if (servconn->type == MSN_SERVCONN_NS) |
379 session->account->gc->last_received = time(NULL); | 375 servconn->session->account->gc->last_received = time(NULL); |
380 | 376 |
381 len = read(servconn->fd, buf, sizeof(buf) - 1); | 377 len = read(servconn->fd, buf, sizeof(buf) - 1); |
382 if (len < 0 && errno == EAGAIN) | 378 if (len < 0 && errno == EAGAIN) |
383 return; | 379 return; |
384 if (len <= 0) { | 380 if (len <= 0) { |
393 buf[len] = '\0'; | 389 buf[len] = '\0'; |
394 | 390 |
395 servconn->rx_buf = g_realloc(servconn->rx_buf, len + servconn->rx_len + 1); | 391 servconn->rx_buf = g_realloc(servconn->rx_buf, len + servconn->rx_len + 1); |
396 memcpy(servconn->rx_buf + servconn->rx_len, buf, len + 1); | 392 memcpy(servconn->rx_buf + servconn->rx_len, buf, len + 1); |
397 servconn->rx_len += len; | 393 servconn->rx_len += len; |
394 | |
395 msn_servconn_process_data(servconn); | |
396 } | |
397 | |
398 void msn_servconn_process_data(MsnServConn *servconn) | |
399 { | |
400 char *cur, *end, *old_rx_buf; | |
401 int cur_len; | |
398 | 402 |
399 end = old_rx_buf = servconn->rx_buf; | 403 end = old_rx_buf = servconn->rx_buf; |
400 | 404 |
401 servconn->processing = TRUE; | 405 servconn->processing = TRUE; |
402 | 406 |