summaryrefslogtreecommitdiff
path: root/source4/smbd
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2009-01-03 12:47:24 +0100
committerStefan Metzmacher <metze@samba.org>2009-01-03 19:58:53 +0100
commit5fa0d3d56824f4ef3dfdb0f97c836554a62c4875 (patch)
tree6973a352fc244df2641655e9c645f319a0632970 /source4/smbd
parentb1be241ca5d7f02be93bd3582b98d428b1e207ce (diff)
downloadsamba-5fa0d3d56824f4ef3dfdb0f97c836554a62c4875.tar.gz
samba-5fa0d3d56824f4ef3dfdb0f97c836554a62c4875.tar.bz2
samba-5fa0d3d56824f4ef3dfdb0f97c836554a62c4875.zip
s4:socket: use a socket_wrapper aware function to auto close the fd event for sockets
metze
Diffstat (limited to 'source4/smbd')
-rw-r--r--source4/smbd/service_stream.c25
1 files changed, 15 insertions, 10 deletions
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;