summaryrefslogtreecommitdiff
path: root/source4/smbd/process_thread.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-01-30 02:55:30 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:09:23 -0500
commit1447b9a8c135ddc8d369be9ab970a4cccf4ecf0e (patch)
treefea0e3bc04a63cb7d3eb0dfad86e0589b12a235d /source4/smbd/process_thread.c
parent597142ddd3575a50a491a89dd5ce5fb40945028f (diff)
downloadsamba-1447b9a8c135ddc8d369be9ab970a4cccf4ecf0e.tar.gz
samba-1447b9a8c135ddc8d369be9ab970a4cccf4ecf0e.tar.bz2
samba-1447b9a8c135ddc8d369be9ab970a4cccf4ecf0e.zip
r5104: - added support for task based servers. These are servers that within
themselves are run as a single process, but run as a child of the main process when smbd is run in the standard model, and run as part of the main process when in the single mode. - rewrote the winbind template code to use the new task services. Also fixed the packet queueing - got rid of event_context_merge() as it is no longer needed (This used to be commit 339964a596689278d2138cff05d7d444798a3504)
Diffstat (limited to 'source4/smbd/process_thread.c')
-rw-r--r--source4/smbd/process_thread.c69
1 files changed, 65 insertions, 4 deletions
diff --git a/source4/smbd/process_thread.c b/source4/smbd/process_thread.c
index 6b62ca413e..223fb02085 100644
--- a/source4/smbd/process_thread.c
+++ b/source4/smbd/process_thread.c
@@ -105,10 +105,70 @@ static void thread_accept_connection(struct event_context *ev,
}
}
-/* called when a SMB connection goes down */
-static void thread_terminate_connection(struct event_context *event_ctx, const char *reason)
+
+struct new_task_state {
+ struct event_context *ev;
+ void (*new_task)(struct event_context *, uint32_t , void *);
+ void *private;
+};
+
+static void *thread_task_fn(void *thread_parm)
+{
+ struct new_task_state *new_task = talloc_get_type(thread_parm, struct new_task_state);
+
+ new_task->new_task(new_task->ev, pthread_self(), new_task->private);
+
+ /* run this connection from here */
+ event_loop_wait(new_task->ev);
+
+ talloc_free(new_task);
+
+ return NULL;
+}
+
+/*
+ called when a new task is needed
+*/
+static void thread_new_task(struct event_context *ev,
+ void (*new_task)(struct event_context *, uint32_t , void *),
+ void *private)
+{
+ int rc;
+ pthread_t thread_id;
+ pthread_attr_t thread_attr;
+ struct new_task_state *state;
+ struct event_context *ev2;
+
+ ev2 = event_context_init(ev);
+ if (ev2 == NULL) return;
+
+ state = talloc(ev2, struct new_task_state);
+ if (state == NULL) {
+ talloc_free(ev2);
+ return;
+ }
+
+ state->new_task = new_task;
+ state->private = private;
+ state->ev = ev2;
+
+ pthread_attr_init(&thread_attr);
+ pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
+ rc = pthread_create(&thread_id, &thread_attr, thread_task_fn, state);
+ pthread_attr_destroy(&thread_attr);
+ if (rc == 0) {
+ DEBUG(4,("thread_new_task: created thread_id=%lu\n",
+ (unsigned long int)thread_id));
+ } else {
+ DEBUG(0,("thread_new_task: thread create failed rc=%d\n", rc));
+ talloc_free(ev2);
+ }
+}
+
+/* called when a task goes down */
+static void thread_terminate(struct event_context *event_ctx, const char *reason)
{
- DEBUG(10,("thread_terminate_connection: reason[%s]\n",reason));
+ DEBUG(10,("thread_terminate: reason[%s]\n",reason));
talloc_free(event_ctx);
@@ -442,7 +502,8 @@ static const struct model_ops thread_ops = {
.name = "thread",
.model_init = thread_model_init,
.accept_connection = thread_accept_connection,
- .terminate_connection = thread_terminate_connection,
+ .new_task = thread_new_task,
+ .terminate = thread_terminate,
};
/*