Move uTP timer to session struct

This commit is contained in:
Mike Gelfand 2017-07-02 13:31:33 +03:00
parent 87c9596305
commit 27b6884408
2 changed files with 10 additions and 10 deletions

View File

@ -155,6 +155,8 @@ struct tr_session
struct event* udp_event;
struct event* udp6_event;
struct event* utp_timer;
/* The open port on the local machine for incoming peer requests */
tr_port private_peer_port;

View File

@ -92,8 +92,6 @@ void tr_utpSendTo(void* closure UNUSED, unsigned char const* buf UNUSED, size_t
#define UTP_INTERVAL_US 50000
static struct event* utp_timer = NULL;
static void incoming(void* closure, struct UTPSocket* s)
{
tr_session* ss = closure;
@ -156,7 +154,7 @@ static void reset_timer(tr_session* ss)
usec = tr_rand_int_weak(1000000);
}
tr_timerAdd(utp_timer, sec, usec);
tr_timerAdd(ss->utp_timer, sec, usec);
}
static void timer_callback(evutil_socket_t s UNUSED, short type UNUSED, void* closure)
@ -168,11 +166,11 @@ static void timer_callback(evutil_socket_t s UNUSED, short type UNUSED, void* cl
int tr_utpPacket(unsigned char const* buf, size_t buflen, struct sockaddr const* from, socklen_t fromlen, tr_session* ss)
{
if (!ss->isClosed && utp_timer == NULL)
if (!ss->isClosed && ss->utp_timer == NULL)
{
utp_timer = evtimer_new(ss->event_base, timer_callback, ss);
ss->utp_timer = evtimer_new(ss->event_base, timer_callback, ss);
if (utp_timer == NULL)
if (ss->utp_timer == NULL)
{
return -1;
}
@ -183,12 +181,12 @@ int tr_utpPacket(unsigned char const* buf, size_t buflen, struct sockaddr const*
return UTP_IsIncomingUTP(incoming, tr_utpSendTo, ss, buf, buflen, from, fromlen);
}
void tr_utpClose(tr_session* session UNUSED)
void tr_utpClose(tr_session* session)
{
if (utp_timer != NULL)
if (session->utp_timer != NULL)
{
evtimer_del(utp_timer);
utp_timer = NULL;
evtimer_del(session->utp_timer);
session->utp_timer = NULL;
}
}