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--;
|
g_backend->num--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout_evt_is_scheduled(con->timeout))
|
net_con_clear_timeout(con_);
|
||||||
{
|
|
||||||
timeout_queue_remove(&g_backend->timeout_queue, con->timeout);
|
|
||||||
hub_free(con->timeout);
|
|
||||||
con->timeout = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (epoll_ctl(g_backend->epfd, EPOLL_CTL_DEL, con->sd, &con->ev) == -1)
|
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--;
|
g_backend->num--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout_evt_is_scheduled(con->timeout))
|
net_con_clear_timeout(con);
|
||||||
{
|
|
||||||
timeout_queue_remove(&g_backend->timeout_queue, con->timeout);
|
|
||||||
hub_free(con->timeout);
|
|
||||||
con->timeout = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
net_con_print("DEL", (struct net_connection_select*) con);
|
net_con_print("DEL", (struct net_connection_select*) con);
|
||||||
net_cleanup_delayed_free(g_backend->cleaner, 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)
|
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);
|
timeout_queue_remove(net_backend_get_timeout_queue(), con->timeout);
|
||||||
hub_free(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)
|
int timeout_evt_is_scheduled(struct timeout_evt* t)
|
||||||
{
|
{
|
||||||
if (!t) return 0;
|
|
||||||
return !!t->prev;
|
return !!t->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,16 +81,18 @@ void timeout_queue_insert(struct timeout_queue* t, struct timeout_evt* evt, size
|
|||||||
|
|
||||||
first = t->events[pos];
|
first = t->events[pos];
|
||||||
|
|
||||||
if (!first)
|
if (first)
|
||||||
|
{
|
||||||
|
first->prev->next = evt;
|
||||||
|
evt->prev = first->prev;
|
||||||
|
first->prev = evt;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
t->events[pos] = evt;
|
t->events[pos] = evt;
|
||||||
evt->prev = evt;
|
evt->prev = evt;
|
||||||
}
|
}
|
||||||
else
|
evt->next = 0;
|
||||||
{
|
|
||||||
evt->prev = first->prev;
|
|
||||||
first->prev = evt;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void timeout_queue_remove(struct timeout_queue* t, struct timeout_evt* evt)
|
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);
|
size_t pos = (evt->timestamp % t->max);
|
||||||
struct timeout_evt* first = t->events[pos];
|
struct timeout_evt* first = t->events[pos];
|
||||||
|
|
||||||
if (!first || !evt)
|
if (!first || !evt->prev)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (first == evt)
|
if (first == evt)
|
||||||
{
|
{
|
||||||
if (first->next)
|
if (first->prev != first)
|
||||||
first->next->prev = first->prev;
|
{
|
||||||
t->events[pos] = first->next;
|
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
|
else
|
||||||
{
|
{
|
||||||
evt->prev->next = evt->next;
|
evt->prev->next = evt->next;
|
||||||
if (evt->next)
|
evt->next->prev = evt->prev;
|
||||||
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)
|
void timeout_queue_reschedule(struct timeout_queue* t, struct timeout_evt* evt, size_t seconds)
|
||||||
|
Loading…
Reference in New Issue
Block a user