mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
Update tr-{dht,udp} to libevent2.
This commit is contained in:
parent
6ba4ab0b21
commit
7af100fa7e
2 changed files with 18 additions and 27 deletions
|
@ -59,7 +59,7 @@ THE SOFTWARE.
|
|||
#include "trevent.h" /* tr_runInEventThread() */
|
||||
#include "utils.h"
|
||||
|
||||
static struct event dht_timer;
|
||||
static struct event *dht_timer = NULL;
|
||||
static unsigned char myid[20];
|
||||
static tr_session *session = NULL;
|
||||
|
||||
|
@ -315,8 +315,8 @@ tr_dhtInit(tr_session *ss)
|
|||
cl->len6 = len6;
|
||||
tr_threadNew( dht_bootstrap, cl );
|
||||
|
||||
evtimer_set( &dht_timer, timer_callback, session );
|
||||
tr_timerAdd( &dht_timer, 0, tr_cryptoWeakRandInt( 1000000 ) );
|
||||
dht_timer = evtimer_new( NULL, timer_callback, session );
|
||||
tr_timerAdd( dht_timer, 0, tr_cryptoWeakRandInt( 1000000 ) );
|
||||
|
||||
tr_ndbg( "DHT", "DHT initialized" );
|
||||
|
||||
|
@ -336,7 +336,8 @@ tr_dhtUninit(tr_session *ss)
|
|||
|
||||
tr_ndbg( "DHT", "Uninitializing DHT" );
|
||||
|
||||
event_del( &dht_timer );
|
||||
event_free( dht_timer );
|
||||
dht_timer = NULL;
|
||||
|
||||
/* Since we only save known good nodes, avoid erasing older data if we
|
||||
don't know enough nodes. */
|
||||
|
@ -611,7 +612,7 @@ tr_dhtCallback(unsigned char *buf, int buflen,
|
|||
|
||||
/* Being slightly late is fine,
|
||||
and has the added benefit of adding some jitter. */
|
||||
tr_timerAdd( &dht_timer, tosleep, tr_cryptoWeakRandInt( 1000000 ) );
|
||||
tr_timerAdd( dht_timer, tosleep, tr_cryptoWeakRandInt( 1000000 ) );
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -24,7 +24,7 @@ THE SOFTWARE.
|
|||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <event.h>
|
||||
#include <event2/event.h>
|
||||
|
||||
#include "transmission.h"
|
||||
#include "net.h"
|
||||
|
@ -160,14 +160,6 @@ tr_udpInit(tr_session *ss, const tr_address * addr)
|
|||
goto ipv6;
|
||||
}
|
||||
|
||||
ss->udp_event = tr_new0(struct event, 1);
|
||||
if(ss->udp_event == NULL) {
|
||||
tr_nerr("UDP", "Couldn't allocate IPv4 event");
|
||||
close(ss->udp_socket);
|
||||
ss->udp_socket = -1;
|
||||
goto ipv6;
|
||||
}
|
||||
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
memcpy(&sin.sin_addr, &addr->addr.addr4, sizeof (struct in_addr));
|
||||
|
@ -179,21 +171,21 @@ tr_udpInit(tr_session *ss, const tr_address * addr)
|
|||
ss->udp_socket = -1;
|
||||
goto ipv6;
|
||||
}
|
||||
|
||||
event_set(ss->udp_event, ss->udp_socket, EV_READ | EV_PERSIST,
|
||||
event_callback, ss);
|
||||
ss->udp_event =
|
||||
event_new(NULL, ss->udp_socket, EV_READ | EV_PERSIST,
|
||||
event_callback, ss);
|
||||
tr_nerr("UDP", "Couldn't allocate IPv4 event");
|
||||
/* Don't bother recovering for now. */
|
||||
|
||||
ipv6:
|
||||
if(tr_globalIPv6())
|
||||
rebind_ipv6(ss, TRUE);
|
||||
if(ss->udp6_socket >= 0) {
|
||||
ss->udp6_event = tr_new0(struct event, 1);
|
||||
if(ss->udp6_event == NULL) {
|
||||
tr_nerr("UDP", "Couldn't allocate IPv6 event");
|
||||
} else {
|
||||
event_set(ss->udp6_event, ss->udp6_socket, EV_READ | EV_PERSIST,
|
||||
ss->udp6_event =
|
||||
event_new(NULL, ss->udp6_socket, EV_READ | EV_PERSIST,
|
||||
event_callback, ss);
|
||||
}
|
||||
if(ss->udp6_event == NULL)
|
||||
tr_nerr("UDP", "Couldn't allocate IPv6 event");
|
||||
}
|
||||
|
||||
if(ss->isDHTEnabled)
|
||||
|
@ -216,8 +208,7 @@ tr_udpUninit(tr_session *ss)
|
|||
}
|
||||
|
||||
if(ss->udp_event) {
|
||||
event_del(ss->udp_event);
|
||||
free(ss->udp_event);
|
||||
event_free(ss->udp_event);
|
||||
ss->udp_event = NULL;
|
||||
}
|
||||
|
||||
|
@ -227,8 +218,7 @@ tr_udpUninit(tr_session *ss)
|
|||
}
|
||||
|
||||
if(ss->udp6_event) {
|
||||
event_del(ss->udp6_event);
|
||||
free(ss->udp6_event);
|
||||
event_free(ss->udp6_event);
|
||||
ss->udp6_event = NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue