1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-16 20:23:50 +03:00

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 commit is contained in:
Andrew Tridgell
2005-01-23 11:49:15 +00:00
committed by Gerald (Jerry) Carter
parent 133e67bb1f
commit a3c7417cfe
10 changed files with 113 additions and 158 deletions

View File

@@ -188,17 +188,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
*/
@@ -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);