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/libcli/raw | |
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/libcli/raw')
-rw-r--r-- | source4/libcli/raw/clisocket.c | 20 | ||||
-rw-r--r-- | source4/libcli/raw/clitransport.c | 2 |
2 files changed, 4 insertions, 18 deletions
diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 9249f453e8..847f5c1b0a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -37,16 +37,6 @@ struct clisocket_connect { }; -static int smbcli_sock_destructor(void *ptr) -{ - struct smbcli_socket *sock = talloc_get_type(ptr, struct smbcli_socket); - - if (sock->event.fde && sock->event.ctx) { - event_remove_fd(sock->event.ctx, sock->event.fde); - } - return 0; -} - /* create a smbcli_socket context The event_ctx is optional - if not supplied one will be created @@ -71,8 +61,6 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, return NULL; } - talloc_set_destructor(sock, smbcli_sock_destructor); - return sock; } @@ -134,11 +122,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, talloc_free(sock->sock); sock->sock = NULL; } - - if (sock->event.fde) { - event_remove_fd(sock->event.ctx, sock->event.fde); - sock->event.fde = NULL; - } + talloc_free(sock->event.fde); status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); if (!NT_STATUS_IS_OK(status)) { @@ -155,6 +139,8 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, fde.private = sock; sock->event.fde = event_add_fd(sock->event.ctx, &fde); + talloc_steal(sock, sock->event.fde); + sock->port = port; set_blocking(fde.fd, False); diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 918f18fa40..b053b362ca 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -55,7 +55,6 @@ static int transport_destructor(void *ptr) struct smbcli_transport *transport = ptr; smbcli_transport_dead(transport); - event_remove_timed(transport->socket->event.ctx, transport->socket->event.te); return 0; } @@ -323,6 +322,7 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport, te.handler = idle_handler; te.private = transport; transport->socket->event.te = event_add_timed(transport->socket->event.ctx, &te); + talloc_steal(transport, transport->socket->event.te); } /* |