mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
make event_add not change any state if it fails; repoted by Ian Bell
svn:r923
This commit is contained in:
parent
1aa6826f62
commit
cca2f8fa0e
@ -120,6 +120,7 @@ Changes in current version:
|
|||||||
o Support multiple events listening on the same signal; make signals regular events that go on the same event queue; problem report by Alexander Drozdov.
|
o Support multiple events listening on the same signal; make signals regular events that go on the same event queue; problem report by Alexander Drozdov.
|
||||||
o Fix a problem with epoll() and reinit; problem report by Alexander Drozdov.
|
o Fix a problem with epoll() and reinit; problem report by Alexander Drozdov.
|
||||||
o Fix off-by-one errors in devpoll; from Ian Bell
|
o Fix off-by-one errors in devpoll; from Ian Bell
|
||||||
|
o Make event_add not change any state if it fails; reported by Ian Bell.
|
||||||
|
|
||||||
Changes in 1.4.0:
|
Changes in 1.4.0:
|
||||||
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
|
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
|
||||||
|
41
event.c
41
event.c
@ -1027,14 +1027,36 @@ event_add_internal(struct event *ev, const struct timeval *tv)
|
|||||||
|
|
||||||
assert(!(ev->ev_flags & ~EVLIST_ALL));
|
assert(!(ev->ev_flags & ~EVLIST_ALL));
|
||||||
|
|
||||||
if (tv != NULL) {
|
/*
|
||||||
struct timeval now;
|
* prepare for timeout insertion further below, if we get a
|
||||||
|
* failure on any step, we should not change any state.
|
||||||
if (ev->ev_flags & EVLIST_TIMEOUT)
|
*/
|
||||||
event_queue_remove(base, ev, EVLIST_TIMEOUT);
|
if (tv != NULL && !(ev->ev_flags & EVLIST_TIMEOUT)) {
|
||||||
else if (min_heap_reserve(&base->timeheap,
|
if (min_heap_reserve(&base->timeheap,
|
||||||
1 + min_heap_size(&base->timeheap)) == -1)
|
1 + min_heap_size(&base->timeheap)) == -1)
|
||||||
return (-1); /* ENOMEM == errno */
|
return (-1); /* ENOMEM == errno */
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ev->ev_events & (EV_READ|EV_WRITE|EV_SIGNAL)) &&
|
||||||
|
!(ev->ev_flags & (EVLIST_INSERTED|EVLIST_ACTIVE))) {
|
||||||
|
res = evsel->add(evbase, ev);
|
||||||
|
if (res != -1)
|
||||||
|
event_queue_insert(base, ev, EVLIST_INSERTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we should change the timout state only if the previous event
|
||||||
|
* addition succeeded.
|
||||||
|
*/
|
||||||
|
if (res != -1 && tv != NULL) {
|
||||||
|
struct timeval now;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we already reserved memory above for the case where we
|
||||||
|
* are not replacing an exisiting timeout.
|
||||||
|
*/
|
||||||
|
if (ev->ev_flags & EVLIST_TIMEOUT)
|
||||||
|
event_queue_remove(base, ev, EVLIST_TIMEOUT);
|
||||||
|
|
||||||
/* Check if it is active due to a timeout. Rescheduling
|
/* Check if it is active due to a timeout. Rescheduling
|
||||||
* this timeout before the callback can be executed
|
* this timeout before the callback can be executed
|
||||||
@ -1064,13 +1086,6 @@ event_add_internal(struct event *ev, const struct timeval *tv)
|
|||||||
event_queue_insert(base, ev, EVLIST_TIMEOUT);
|
event_queue_insert(base, ev, EVLIST_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ev->ev_events & (EV_READ|EV_WRITE|EV_SIGNAL)) &&
|
|
||||||
!(ev->ev_flags & (EVLIST_INSERTED|EVLIST_ACTIVE))) {
|
|
||||||
res = evsel->add(evbase, ev);
|
|
||||||
if (res != -1)
|
|
||||||
event_queue_insert(base, ev, EVLIST_INSERTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if we are not in the right thread, we need to wake up the loop */
|
/* if we are not in the right thread, we need to wake up the loop */
|
||||||
if (res != -1 && !EVTHREAD_IN_THREAD(base))
|
if (res != -1 && !EVTHREAD_IN_THREAD(base))
|
||||||
send(base->th_notify_fd[1], "", 1, 0);
|
send(base->th_notify_fd[1], "", 1, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user