Changeset 11656


Ignore:
Timestamp:
Jan 9, 2011, 9:48:43 PM (11 years ago)
Author:
jch
Message:

Use the dht-0.16 API in tr-dht.c.
Recvfrom is now done outside the dht code, which makes it possible to share
the socket with UTP.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tr-dht.c

    r11654 r11656  
    596596    struct event *event;
    597597    time_t tosleep;
     598    struct sockaddr_storage from;
     599    socklen_t fromlen;
     600    unsigned char *buf = NULL;
     601    int rc;
    598602
    599603    if (s == session->udp_socket)
     
    606610    }
    607611
    608     if( dht_periodic( type == EV_READ, &tosleep, callback, NULL) < 0 ) {
     612    if( type == EV_READ ) {
     613        buf = malloc(4096);
     614        if(buf != NULL) {
     615            fromlen = sizeof(from);
     616            rc = recvfrom(s, buf, 4096 - 1, 0,
     617                          (struct sockaddr*)&from, &fromlen);
     618            if(rc < 0)
     619                rc = 0;
     620            else
     621                buf[rc] = 0;
     622        }
     623    } else {
     624        rc = 0;
     625        fromlen = 0;
     626    }
     627
     628    if( dht_periodic( buf, rc, (struct sockaddr*)&from, fromlen,
     629                      &tosleep, callback, NULL) < 0 ) {
    609630        if(errno == EINTR) {
    610631            tosleep = 0;
     
    617638    }
    618639
     640    if(buf) {
     641        free(buf);
     642        buf = NULL;
     643    }
     644
    619645#ifdef NOTYET
    620646    /* Only do this once in a while.  Counting rather than measuring time
Note: See TracChangeset for help on using the changeset viewer.