r5104: - added support for task based servers. These are servers that within
[kai/samba.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 "events.h"
27 #include "dlinklist.h"
28 #include "smb_server/smb_server.h"
29
30
31 /*
32   called when the process model is selected
33 */
34 static void single_model_init(struct event_context *ev)
35 {
36 }
37
38 /*
39   called when a listening socket becomes readable. 
40 */
41 static void single_accept_connection(struct event_context *ev, 
42                                      struct socket_context *sock,
43                                      void (*new_conn)(struct event_context *, struct socket_context *, 
44                                                       uint32_t , void *), 
45                                      void *private)
46 {
47         NTSTATUS status;
48         struct socket_context *sock2;
49
50         /* accept an incoming connection. */
51         status = socket_accept(sock, &sock2);
52         if (!NT_STATUS_IS_OK(status)) {
53                 DEBUG(0,("accept_connection_single: accept: %s\n", nt_errstr(status)));
54                 return;
55         }
56
57         talloc_steal(private, sock);
58
59         new_conn(ev, sock2, socket_get_fd(sock), private);
60 }
61
62 /*
63   called to startup a new task
64 */
65 static void single_new_task(struct event_context *ev, 
66                             void (*new_task)(struct event_context *, uint32_t, void *), 
67                             void *private)
68 {
69         static uint32_t taskid = 0x10000000;
70         new_task(ev, taskid++, private);
71 }
72
73
74 /* called when a task goes down */
75 static void single_terminate(struct event_context *ev, const char *reason) 
76 {
77 }
78
79 static const struct model_ops single_ops = {
80         .name                   = "single",
81         .model_init             = single_model_init,
82         .new_task               = single_new_task,
83         .accept_connection      = single_accept_connection,
84         .terminate              = single_terminate,
85 };
86
87 /*
88   initialise the single process model, registering ourselves with the
89   process model subsystem
90  */
91 NTSTATUS process_model_single_init(void)
92 {
93         return register_process_model(&single_ops);
94 }