diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-01-23 11:49:15 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:09:08 -0500 |
commit | fd62df64188c0f992876c72fdda8a6da5dba3090 (patch) | |
tree | a5f212e796816c648a3a0e49caa457eb597e292b /source4/lib/messaging | |
parent | 54eff1435dd69d489ae35834f17989f79011418e (diff) | |
download | samba-fd62df64188c0f992876c72fdda8a6da5dba3090.tar.gz samba-fd62df64188c0f992876c72fdda8a6da5dba3090.tar.bz2 samba-fd62df64188c0f992876c72fdda8a6da5dba3090.zip |
r4943: Smplified the events handling code a lot. The first source of
complexity was that events didn't automatically cleanup
themselves. This was because the events code was written before we had
talloc destructors, so you needed to call event_remove_XX() to clean
the event out of the event lists from every piece of code that used
events. I have now added automatic event destructors, which in turn
allowed me to simplify a lot of the calling code.
The 2nd source of complexity was caused by the ref_count, which was
needed to cope with event handlers destroying events while handling
them, which meant the linked lists became invalid, so the ref_count ws
used to mark events for later destruction.
The new system is much simpler. I now have a ev->destruction_count,
which is incremented in all event destructors. The event dispatch code
checks for changes to this and handles it.
(This used to be commit a3c7417cfeab429ffb22d5546b205818f531a7b4)
Diffstat (limited to 'source4/lib/messaging')
-rw-r--r-- | source4/lib/messaging/messaging.c | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 84c9adc874..beceb342c9 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -189,17 +189,6 @@ static void messaging_recv_handler(struct event_context *ev, struct fd_event *fd } /* - destroy a messaging record -*/ -static int rec_destructor(void *ptr) -{ - struct messaging_rec *rec = ptr; - struct messaging_context *msg = rec->msg; - event_remove_fd(msg->event.ev, rec->fde); - return 0; -} - -/* handle a new incoming connection */ static void messaging_listen_handler(struct event_context *ev, struct fd_event *fde, @@ -233,7 +222,7 @@ static void messaging_listen_handler(struct event_context *ev, struct fd_event * rec->fde = event_add_fd(msg->event.ev, &fde2); - talloc_set_destructor(rec, rec_destructor); + talloc_steal(rec, rec->fde); } /* @@ -370,8 +359,7 @@ static void messaging_backoff_handler(struct event_context *ev, struct timed_eve fde.handler = messaging_send_handler; rec->fde = event_add_fd(msg->event.ev, &fde); - - talloc_set_destructor(rec, rec_destructor); + talloc_steal(rec, rec->fde); messaging_send_handler(msg->event.ev, rec->fde, timeval_zero(), EVENT_FD_WRITE); } @@ -435,8 +423,7 @@ NTSTATUS messaging_send(struct messaging_context *msg, servid_t server, uint32_t fde.handler = messaging_send_handler; rec->fde = event_add_fd(msg->event.ev, &fde); - - talloc_set_destructor(rec, rec_destructor); + talloc_steal(rec, rec->fde); messaging_send_handler(msg->event.ev, rec->fde, timeval_zero(), EVENT_FD_WRITE); @@ -464,7 +451,6 @@ NTSTATUS messaging_send_ptr(struct messaging_context *msg, servid_t server, static int messaging_destructor(void *ptr) { struct messaging_context *msg = ptr; - event_remove_fd(msg->event.ev, msg->event.fde); unlink(msg->path); return 0; } @@ -516,6 +502,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, servid_t server_id msg->event.ev = talloc_reference(msg,ev); msg->event.fde = event_add_fd(ev, &fde); + talloc_steal(msg, msg->event.fde); talloc_set_destructor(msg, messaging_destructor); |