Fixed bad logic inside the timer scheduling.
This commit is contained in:
parent
b04a20c66e
commit
78ad9b8572
@ -226,12 +226,7 @@ void net_con_close(struct net_connection* con_)
|
||||
g_backend->num--;
|
||||
}
|
||||
|
||||
if (timeout_evt_is_scheduled(con->timeout))
|
||||
{
|
||||
timeout_queue_remove(&g_backend->timeout_queue, con->timeout);
|
||||
hub_free(con->timeout);
|
||||
con->timeout = 0;
|
||||
}
|
||||
net_con_clear_timeout(con_);
|
||||
|
||||
if (epoll_ctl(g_backend->epfd, EPOLL_CTL_DEL, con->sd, &con->ev) == -1)
|
||||
{
|
||||
|
@ -195,12 +195,7 @@ void net_con_close(struct net_connection* con)
|
||||
g_backend->num--;
|
||||
}
|
||||
|
||||
if (timeout_evt_is_scheduled(con->timeout))
|
||||
{
|
||||
timeout_queue_remove(&g_backend->timeout_queue, con->timeout);
|
||||
hub_free(con->timeout);
|
||||
con->timeout = 0;
|
||||
}
|
||||
net_con_clear_timeout(con);
|
||||
|
||||
net_con_print("DEL", (struct net_connection_select*) con);
|
||||
net_cleanup_delayed_free(g_backend->cleaner, con);
|
||||
|
@ -41,7 +41,7 @@ void net_con_set_timeout(struct net_connection* con, int seconds)
|
||||
|
||||
void net_con_clear_timeout(struct net_connection* con)
|
||||
{
|
||||
if (timeout_evt_is_scheduled(con->timeout))
|
||||
if (con->timeout && timeout_evt_is_scheduled(con->timeout))
|
||||
{
|
||||
timeout_queue_remove(net_backend_get_timeout_queue(), con->timeout);
|
||||
hub_free(con->timeout);
|
||||
|
@ -36,7 +36,6 @@ void timeout_evt_reset(struct timeout_evt* t)
|
||||
|
||||
int timeout_evt_is_scheduled(struct timeout_evt* t)
|
||||
{
|
||||
if (!t) return 0;
|
||||
return !!t->prev;
|
||||
}
|
||||
|
||||
@ -82,16 +81,18 @@ void timeout_queue_insert(struct timeout_queue* t, struct timeout_evt* evt, size
|
||||
|
||||
first = t->events[pos];
|
||||
|
||||
if (!first)
|
||||
if (first)
|
||||
{
|
||||
first->prev->next = evt;
|
||||
evt->prev = first->prev;
|
||||
first->prev = evt;
|
||||
}
|
||||
else
|
||||
{
|
||||
t->events[pos] = evt;
|
||||
evt->prev = evt;
|
||||
}
|
||||
else
|
||||
{
|
||||
evt->prev = first->prev;
|
||||
first->prev = evt;
|
||||
}
|
||||
evt->next = 0;
|
||||
}
|
||||
|
||||
void timeout_queue_remove(struct timeout_queue* t, struct timeout_evt* evt)
|
||||
@ -99,23 +100,33 @@ void timeout_queue_remove(struct timeout_queue* t, struct timeout_evt* evt)
|
||||
size_t pos = (evt->timestamp % t->max);
|
||||
struct timeout_evt* first = t->events[pos];
|
||||
|
||||
if (!first || !evt)
|
||||
if (!first || !evt->prev)
|
||||
return;
|
||||
|
||||
if (first == evt)
|
||||
{
|
||||
if (first->next)
|
||||
first->next->prev = first->prev;
|
||||
if (first->prev != first)
|
||||
{
|
||||
t->events[pos] = first->next;
|
||||
t->events[pos]->prev = evt->prev;
|
||||
}
|
||||
else
|
||||
{
|
||||
t->events[pos] = 0;
|
||||
}
|
||||
}
|
||||
else if (evt == first->prev)
|
||||
{
|
||||
first->prev = evt->prev;
|
||||
evt->prev->next = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
evt->prev->next = evt->next;
|
||||
if (evt->next)
|
||||
evt->next->prev = evt->prev;
|
||||
else
|
||||
first->prev = evt->prev;
|
||||
}
|
||||
evt->next = 0;
|
||||
evt->prev = 0;
|
||||
}
|
||||
|
||||
void timeout_queue_reschedule(struct timeout_queue* t, struct timeout_evt* evt, size_t seconds)
|
||||
|
Loading…
Reference in New Issue
Block a user