1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

r4944: every event_add_*() caller was having to call talloc_steal() to take

control of the event, so instead build that into the function. If you
pass NULL as mem_ctx then it leaves it as a child of the events
structure.
(This used to be commit 7f981b9ed9)
This commit is contained in:
Andrew Tridgell 2005-01-23 12:17:45 +00:00 committed by Gerald (Jerry) Carter
parent fd62df6418
commit 6c14b0133d
10 changed files with 33 additions and 37 deletions

View File

@ -157,7 +157,8 @@ static int event_fd_destructor(void *ptr)
add a fd based event
return NULL on failure (memory allocation error)
*/
struct fd_event *event_add_fd(struct event_context *ev, struct fd_event *e0)
struct fd_event *event_add_fd(struct event_context *ev, struct fd_event *e0,
TALLOC_CTX *mem_ctx)
{
struct fd_event *e = talloc(ev->events, struct fd_event);
if (!e) return NULL;
@ -168,6 +169,9 @@ struct fd_event *event_add_fd(struct event_context *ev, struct fd_event *e0)
ev->maxfd = e->fd;
}
talloc_set_destructor(e, event_fd_destructor);
if (mem_ctx) {
talloc_steal(mem_ctx, e);
}
return e;
}
@ -226,7 +230,8 @@ static int event_timed_destructor(void *ptr)
add a timed event
return NULL on failure (memory allocation error)
*/
struct timed_event *event_add_timed(struct event_context *ev, struct timed_event *e0)
struct timed_event *event_add_timed(struct event_context *ev, struct timed_event *e0,
TALLOC_CTX *mem_ctx)
{
struct timed_event *e = talloc(ev->events, struct timed_event);
if (!e) return NULL;
@ -234,6 +239,9 @@ struct timed_event *event_add_timed(struct event_context *ev, struct timed_event
e->event_ctx = ev;
DLIST_ADD(ev->timed_events, e);
talloc_set_destructor(e, event_timed_destructor);
if (mem_ctx) {
talloc_steal(mem_ctx, e);
}
return e;
}
@ -259,7 +267,8 @@ static int event_loop_destructor(void *ptr)
add a loop event
return NULL on failure (memory allocation error)
*/
struct loop_event *event_add_loop(struct event_context *ev, struct loop_event *e0)
struct loop_event *event_add_loop(struct event_context *ev, struct loop_event *e0,
TALLOC_CTX *mem_ctx)
{
struct loop_event *e = talloc(ev->events, struct loop_event);
if (!e) return NULL;
@ -267,6 +276,9 @@ struct loop_event *event_add_loop(struct event_context *ev, struct loop_event *e
e->event_ctx = ev;
DLIST_ADD(ev->loop_events, e);
talloc_set_destructor(e, event_loop_destructor);
if (mem_ctx) {
talloc_steal(mem_ctx, e);
}
return e;
}

View File

@ -220,9 +220,7 @@ static void messaging_listen_handler(struct event_context *ev, struct fd_event *
fde2.flags = EVENT_FD_READ;
fde2.handler = messaging_recv_handler;
rec->fde = event_add_fd(msg->event.ev, &fde2);
talloc_steal(rec, rec->fde);
rec->fde = event_add_fd(msg->event.ev, &fde2, rec);
}
/*
@ -358,8 +356,7 @@ static void messaging_backoff_handler(struct event_context *ev, struct timed_eve
fde.flags = EVENT_FD_WRITE;
fde.handler = messaging_send_handler;
rec->fde = event_add_fd(msg->event.ev, &fde);
talloc_steal(rec, rec->fde);
rec->fde = event_add_fd(msg->event.ev, &fde, rec);
messaging_send_handler(msg->event.ev, rec->fde, timeval_zero(), EVENT_FD_WRITE);
}
@ -408,7 +405,7 @@ NTSTATUS messaging_send(struct messaging_context *msg, servid_t server, uint32_t
te.next_event = timeval_current_ofs(0, MESSAGING_BACKOFF);
te.handler = messaging_backoff_handler;
te.private = rec;
event_add_timed(msg->event.ev, &te);
event_add_timed(msg->event.ev, &te, rec);
return NT_STATUS_OK;
}
@ -422,8 +419,7 @@ NTSTATUS messaging_send(struct messaging_context *msg, servid_t server, uint32_t
fde.flags = EVENT_FD_WRITE;
fde.handler = messaging_send_handler;
rec->fde = event_add_fd(msg->event.ev, &fde);
talloc_steal(rec, rec->fde);
rec->fde = event_add_fd(msg->event.ev, &fde, rec);
messaging_send_handler(msg->event.ev, rec->fde, timeval_zero(), EVENT_FD_WRITE);
@ -501,8 +497,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, servid_t server_id
fde.handler = messaging_listen_handler;
msg->event.ev = talloc_reference(msg,ev);
msg->event.fde = event_add_fd(ev, &fde);
talloc_steal(msg, msg->event.fde);
msg->event.fde = event_add_fd(ev, &fde, msg);
talloc_set_destructor(msg, messaging_destructor);

View File

@ -266,9 +266,7 @@ struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx,
fde.flags = 0;
fde.handler = nbt_name_socket_handler;
fde.private = nbtsock;
nbtsock->fde = event_add_fd(nbtsock->event_ctx, &fde);
talloc_steal(nbtsock, nbtsock->fde);
nbtsock->fde = event_add_fd(nbtsock->event_ctx, &fde, nbtsock);
return nbtsock;
@ -344,8 +342,7 @@ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock,
te.next_event = timeout;
te.handler = nbt_name_socket_timeout;
te.private = req;
req->te = event_add_timed(nbtsock->event_ctx, &te);
talloc_steal(req, req->te);
req->te = event_add_timed(nbtsock->event_ctx, &te, req);
talloc_set_destructor(req, nbt_name_request_destructor);

View File

@ -138,8 +138,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock,
fde.handler = smbcli_sock_connect_handler;
fde.private = sock;
sock->event.fde = event_add_fd(sock->event.ctx, &fde);
talloc_steal(sock, sock->event.fde);
sock->event.fde = event_add_fd(sock->event.ctx, &fde, sock);
sock->port = port;
set_blocking(fde.fd, False);

View File

@ -321,8 +321,8 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport,
te.next_event = timeval_current_ofs(0, period);
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);
transport->socket->event.te = event_add_timed(transport->socket->event.ctx,
&te, transport);
}
/*

View File

@ -165,13 +165,12 @@ struct smbcli_composite *resolve_name_host_send(struct nbt_name *name,
fde.flags = EVENT_FD_READ;
fde.handler = pipe_handler;
fde.private = c;
state->fde = event_add_fd(c->event_ctx, &fde);
state->fde = event_add_fd(c->event_ctx, &fde, state);
if (state->fde == NULL) {
close(fd[0]);
close(fd[1]);
goto failed;
}
talloc_steal(state, state->fde);
/* signal handling in posix really sucks - doing this in a library
affects the whole app, but what else to do?? */

View File

@ -347,7 +347,7 @@ static NTSTATUS dcerpc_pipe_open_socket(struct dcerpc_connection *c,
fde.handler = sock_io_handler;
fde.private = c;
sock->fde = event_add_fd(sock->event_ctx, &fde);
sock->fde = event_add_fd(sock->event_ctx, &fde, sock);
c->transport.private = sock;

View File

@ -143,8 +143,7 @@ static int pvfs_wait_destructor(void *ptr)
te.next_event = end_time;
te.handler = pvfs_wait_timeout;
te.private = pwait;
pwait->te = event_add_timed(pwait->ev, &te);
talloc_steal(pwait, pwait->te);
pwait->te = event_add_timed(pwait->ev, &te, pwait);
/* register with the messaging subsystem for this message
type */

View File

@ -159,11 +159,10 @@ static long echo_TestSleep(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_c
te.private = p;
te.next_event = timeval_add(&dce_call->time, r->in.seconds, 0);
p->te = event_add_timed(dce_call->event_ctx, &te);
p->te = event_add_timed(dce_call->event_ctx, &te, p);
if (!p->te) {
return 0;
}
talloc_steal(p, p->te);
dce_call->state_flags |= DCESRV_CALL_STATE_FLAG_ASYNC;
return 0;

View File

@ -163,15 +163,14 @@ struct server_stream_socket *service_setup_stream_socket(struct server_service *
stream_socket->service = service;
stream_socket->socket = sock;
stream_socket->event.ctx = service->server->event.ctx;
stream_socket->event.fde = event_add_fd(stream_socket->event.ctx, &fde);
stream_socket->event.fde = event_add_fd(stream_socket->event.ctx,
&fde, stream_socket);
if (!stream_socket->event.fde) {
DEBUG(0,("event_add_fd(stream_socket->event.ctx, &fde) failed\n"));
socket_destroy(sock);
return NULL;
}
talloc_steal(stream_socket, sock);
talloc_steal(stream_socket, stream_socket->event.fde);
if (stream_socket->stream.ops->socket_init) {
stream_socket->stream.ops->socket_init(stream_socket);
@ -239,11 +238,8 @@ struct server_connection *server_setup_connection(struct event_context *ev,
stream_socket->stream.ops->accept_connection(srv_conn);
/* accpect_connection() of the service may changed idle.next_event */
srv_conn->event.fde = event_add_fd(ev,&fde);
srv_conn->event.idle = event_add_timed(ev,&idle);
talloc_steal(srv_conn, srv_conn->event.fde);
talloc_steal(srv_conn, srv_conn->event.idle);
srv_conn->event.fde = event_add_fd(ev, &fde, srv_conn);
srv_conn->event.idle = event_add_timed(ev, &idle, srv_conn);
talloc_set_destructor(srv_conn, server_connection_destructor);