1N/A * Copyright (c) 2003-2004, 2007, 2009-2011 Sendmail, Inc. and its suppliers. 1N/A * All rights reserved. 1N/A * By using this file, you agree to the terms and conditions set 1N/A * forth in the LICENSE file which can be found at the top level of 1N/A * the sendmail distribution. 1N/A * Contributed by Jose Marcio Martins da Cruz - Ecole des Mines de Paris 1N/A * Jose-Marcio.Martins@ensmp.fr 1N/A int tm_p[
2];
/* poll control pipe */ 1N/A "Error writing to event pipe: %s", \
1N/A#
endif /* USE_PIPE_WAKE_POLL */ 1N/A/* poll check periodicity (default 10000 - 10 s) */ 1N/A/* worker conditional wait timeout (default 10 s) */ 1N/A** periodicity of cleaning up old sessions (timedout) 1N/A** sessions list will be checked to find old inactive 1N/A** sessions each DT_CHECK_OLD_SESSIONS sec 1N/A#
endif /* OLD_SESSION_TIMEOUT */ 1N/A/* session states - with respect to the pool of workers */ 1N/A** Macros for threads and mutex management 1N/A#
else /* POOL_DEBUG */ 1N/A#
endif /* POOL_DEBUG */ 1N/A** MI_START_SESSION -- Start a session in the pool of workers 1N/A** ctx -- context structure 1N/A /* this can happen if the milter is shutting down */ 1N/A /* if there is an idle worker, signal it, otherwise start new worker */ 1N/A** MI_CLOSE_SESSION -- Close a session and clean up data structures 1N/A** ctx -- context structure 1N/A** NONBLOCKING -- set nonblocking mode for a file descriptor. 1N/A** fd -- file descriptor 1N/A** name -- name for (error) logging 1N/A** MI_POOL_CONTROLER_INIT -- Launch the worker pool controller 1N/A** Must be called before starting sessions. 1N/A /* Launch the pool controller */ 1N/A /* Create the pool of workers */ 1N/A** MI_POOL_CONTROLLER -- manage the pool of workers 1N/A** This thread must be running when listener begins 1N/A** Look for timed out sessions 1N/A** Select sessions to wait for sendmail command 1N/A** Poll set of file descriptors 1N/A** For each file descriptor ready 1N/A** launch new thread if no worker available 1N/A** signal waiting worker 1N/A/* Poll structure array (pollfd) size step */ 1N/A int pcnt = 0;
/* error count for poll() failures */ 1N/A /* check for timed out sessions? */ 1N/A /* if session timed out, close it */ 1N/A (
"Closing old connection: sd=%d id=%d",
1N/A ** Initialize poll set. 1N/A ** Insert into the poll set the file descriptors of 1N/A ** all sessions waiting for a command from sendmail. 1N/A /* begin with worker pipe */ 1N/A ** update ctx_wait - start of wait moment - 1N/A /* add the session to the pollfd array? */ 1N/A ** Resize the pollfd array if it 1N/A ** isn't large enough. 1N/A "Failed to realloc pollfd array:%s",
1N/A /* add the session to pollfd array */ 1N/A /* Everything is ready, let's wait for an event */ 1N/A "%s() failed (%s), %s",
1N/A /* something happened */ 1N/A /* has a worker signaled an end of task ? */ 1N/A (
"PIPE WILL READ evt = %08X %08X",
1N/A (
"PIPE DONE READ i=[%d] fd=[%d] r=[%d] evt=[%d]",
1N/A /* Exception handling */ 1N/A /* no ! sendmail wants to send a command */ 1N/A (
"Checking context sd=%d - fd=%d ",
1N/A (
"TASK: found %d for fd[%d]=%d",
1N/A (
"TASK %s FOUND - Checking PIPE for fd[%d]",
1N/A** Look for a task ready to run. 1N/A** Value of ctx is NULL or a pointer to a task ready to run. 1N/A** MI_WORKER -- worker thread 1N/A** executes tasks distributed by the mi_pool_controller 1N/A** or by mi_start_session 1N/A** arg -- pointer to context structure 1N/A /* let's handle next task... */ 1N/A (
"worker %d: new task -> let's handle it",
1N/A ** Delete context from linked list of 1N/A ** sessions and close session. 1N/A (
"writing to event pipe..."));
1N/A ** Signal task controller to add new session 1N/A /* check if there is any task waiting to be served */ 1N/A ** if not, let's check if there is enough idle workers 1N/A ** if no task ready to run, wait for another one 1N/A /* look for a task */ 1N/A** MI_LIST_ADD_CTX -- add new session to linked list 1N/A** ctx -- context structure 1N/A** MI_LIST_DEL_CTX -- remove session from linked list when finished 1N/A** ctx -- context structure 1N/A#
endif /* _FFR_WORKERS_POOL */