From 5fa0d3d56824f4ef3dfdb0f97c836554a62c4875 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 3 Jan 2009 12:47:24 +0100 Subject: s4:socket: use a socket_wrapper aware function to auto close the fd event for sockets metze --- source4/smbd/service_stream.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'source4/smbd') diff --git a/source4/smbd/service_stream.c b/source4/smbd/service_stream.c index ef98919f93..a5642c258f 100644 --- a/source4/smbd/service_stream.c +++ b/source4/smbd/service_stream.c @@ -258,6 +258,7 @@ NTSTATUS stream_setup_socket(struct tevent_context *event_context, NTSTATUS status; struct stream_socket *stream_socket; struct socket_address *socket_address; + struct tevent_fd *fde; int i; stream_socket = talloc_zero(event_context, struct stream_socket); @@ -322,20 +323,24 @@ NTSTATUS stream_setup_socket(struct tevent_context *event_context, return status; } - /* By specifying EVENT_FD_AUTOCLOSE below, we indicate that we - * will close the socket using the events system. This avoids - * nasty interactions with waiting for talloc to close the socket. */ - - socket_set_flags(stream_socket->sock, SOCKET_FLAG_NOCLOSE); - /* Add the FD from the newly created socket into the event * subsystem. it will call the accept handler whenever we get * new connections */ - event_add_fd(event_context, stream_socket->sock, - socket_get_fd(stream_socket->sock), - EVENT_FD_READ|EVENT_FD_AUTOCLOSE, - stream_accept_handler, stream_socket); + fde = tevent_add_fd(event_context, stream_socket->sock, + socket_get_fd(stream_socket->sock), + TEVENT_FD_READ, + stream_accept_handler, stream_socket); + if (!fde) { + DEBUG(0,("Failed to setup fd event\n")); + talloc_free(stream_socket); + return NT_STATUS_NO_MEMORY; + } + + /* we let events system to the close on the socket. This avoids + * nasty interactions with waiting for talloc to close the socket. */ + tevent_fd_set_close_fn(fde, socket_tevent_fd_close_fn); + socket_set_flags(stream_socket->sock, SOCKET_FLAG_NOCLOSE); stream_socket->private = talloc_reference(stream_socket, private); stream_socket->ops = stream_ops; -- cgit