r12608: Remove some unused #include lines.
[abartlet/samba.git/.git] / source4 / smbd / process_single.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    process model: process (1 process handles all client connections)
5
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) James J Myers 2003 <myersjj@samba.org>
8    Copyright (C) Stefan (metze) Metzmacher 2004
9    
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.
14    
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.
19    
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.
23 */
24
25 #include "includes.h"
26 #include "smb_server/smb_server.h"
27
28 /* For sepecifiying event context to GSSAPI below */
29 #include "heimdal/lib/gssapi/gssapi_locl.h"
30
31
32 /*
33   called when the process model is selected
34 */
35 static void single_model_init(struct event_context *ev)
36 {
37         /* Hack to ensure that GSSAPI uses the right event context */
38         gssapi_krb5_init_ev(ev);
39 }
40
41 /*
42   called when a listening socket becomes readable. 
43 */
44 static void single_accept_connection(struct event_context *ev, 
45                                      struct socket_context *sock,
46                                      void (*new_conn)(struct event_context *, struct socket_context *, 
47                                                       uint32_t , void *), 
48                                      void *private)
49 {
50         NTSTATUS status;
51         struct socket_context *sock2;
52
53         /* accept an incoming connection. */
54         status = socket_accept(sock, &sock2);
55         if (!NT_STATUS_IS_OK(status)) {
56                 DEBUG(0,("accept_connection_single: accept: %s\n", nt_errstr(status)));
57                 /* this looks strange, but is correct. We need to
58                    throttle things until the system clears enough
59                    resources to handle this new socket. If we don't
60                    then we will spin filling the log and causing more
61                    problems. We don't panic as this is probably a
62                    temporary resource constraint */
63                 sleep(1);
64                 return;
65         }
66
67         talloc_steal(private, sock);
68
69         new_conn(ev, sock2, socket_get_fd(sock2), private);
70 }
71
72 /*
73   called to startup a new task
74 */
75 static void single_new_task(struct event_context *ev, 
76                             void (*new_task)(struct event_context *, uint32_t, void *), 
77                             void *private)
78 {
79         static uint32_t taskid = 0x10000000;
80         new_task(ev, taskid++, private);
81 }
82
83
84 /* called when a task goes down */
85 static void single_terminate(struct event_context *ev, const char *reason) 
86 {
87         DEBUG(2,("single_terminate: reason[%s]\n",reason));
88 }
89
90 static const struct model_ops single_ops = {
91         .name                   = "single",
92         .model_init             = single_model_init,
93         .new_task               = single_new_task,
94         .accept_connection      = single_accept_connection,
95         .terminate              = single_terminate,
96 };
97
98 /*
99   initialise the single process model, registering ourselves with the
100   process model subsystem
101  */
102 NTSTATUS process_model_single_init(void)
103 {
104         return register_process_model(&single_ops);
105 }