r21745: indent
[Samba/ekacnet.git] / source4 / smbd / process_single.c
blob221cfb780746d5c51da4d27feba9dacde55c1c24
1 /*
2 Unix SMB/CIFS implementation.
4 process model: process (1 process handles all client connections)
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) James J Myers 2003 <myersjj@samba.org>
8 Copyright (C) Stefan (metze) Metzmacher 2004
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "includes.h"
26 #include "smbd/process_model.h"
27 #include "system/filesys.h"
28 #include "cluster/cluster.h"
31 called when the process model is selected
33 static void single_model_init(struct event_context *ev)
38 called when a listening socket becomes readable.
40 static void single_accept_connection(struct event_context *ev,
41 struct socket_context *sock,
42 void (*new_conn)(struct event_context *, struct socket_context *,
43 struct server_id , void *),
44 void *private)
46 NTSTATUS status;
47 struct socket_context *sock2;
49 /* accept an incoming connection. */
50 status = socket_accept(sock, &sock2);
51 if (!NT_STATUS_IS_OK(status)) {
52 DEBUG(0,("single_accept_connection: accept: %s\n", nt_errstr(status)));
53 /* this looks strange, but is correct. We need to
54 throttle things until the system clears enough
55 resources to handle this new socket. If we don't
56 then we will spin filling the log and causing more
57 problems. We don't panic as this is probably a
58 temporary resource constraint */
59 sleep(1);
60 return;
63 talloc_steal(private, sock);
65 new_conn(ev, sock2, cluster_id(socket_get_fd(sock2)), private);
69 called to startup a new task
71 static void single_new_task(struct event_context *ev,
72 void (*new_task)(struct event_context *, struct server_id, void *),
73 void *private)
75 static uint32_t taskid = 0x10000000;
76 new_task(ev, cluster_id(taskid++), private);
80 /* called when a task goes down */
81 static void single_terminate(struct event_context *ev, const char *reason)
83 DEBUG(2,("single_terminate: reason[%s]\n",reason));
86 /* called to set a title of a task or connection */
87 static void single_set_title(struct event_context *ev, const char *title)
91 static const struct model_ops single_ops = {
92 .name = "single",
93 .model_init = single_model_init,
94 .new_task = single_new_task,
95 .accept_connection = single_accept_connection,
96 .terminate = single_terminate,
97 .set_title = single_set_title,
101 initialise the single process model, registering ourselves with the
102 process model subsystem
104 NTSTATUS process_model_single_init(void)
106 return register_process_model(&single_ops);