Process Worker ================= Functions for controlling forking and signal handling in yimmo-wsgi .. c:macro:: YMO_WSGI_TKILL_TIMEOUT HACK: move elsewhere .. code-block:: c :caption: Definition #define YMO_WSGI_TKILL_TIMEOUT 5.0 --------------------------------- Types --------------------------------- .. c:struct:: ymo_wsgi_proc Stores process information for the WSGI server in both single- and multi-processing mode. .. code-block:: c :caption: Definition struct ymo_wsgi_proc { /* Process Info: */ char* proc_name; size_t proc_name_len; size_t proc_name_buflen; long no_wsgi_proc; long no_wsgi_threads; int restart_count; long port; int term; /* Process Type: */ int is_main; int is_worker; /* Main process: */ pid_t* children; ev_signal sigint_watcher; ev_signal sigchld_watcher; ev_signal sigterm_watcher; ev_timer pkill_timer; ev_timer tkill_timer; /* Child process: */ pid_t ppid; int worker_id; ymo_wsgi_worker_t* w_threads; /* All processes: */ ymo_server_t* http_srv; struct ev_loop* loop; char* module; char* app; ymo_yaml_doc_t* cfg; }; --------------------------------- Functions --------------------------------- .. c:function:: pid_t ymo_wsgi_proc_fork_new(ymo_wsgi_proc_t* w_proc, int worker_id) Invoked by the main process in multi-processing mode to spawn a new worker process. .. c:function:: int ymo_wsgi_proc_main(ymo_wsgi_proc_t* w_proc) Entrypoint for WSGI worker processes (or the main process in single-proc mode). .. c:function:: void ymo_wsgi_proc_sigint(struct ev_loop* loop, ev_signal* w, int revents) SIGINT handler. .. c:function:: void ymo_wsgi_proc_sigchld(struct ev_loop* loop, ev_signal* w, int revents) SIGCHLD handler. .. c:function:: void ymo_wsgi_proc_sigterm(struct ev_loop* loop, ev_signal* w, int revents) SIGTERM handler. .. c:function:: ymo_wsgi_worker_t* ymo_wsgi_init_workers( int no_wsgi_threads, struct ev_loop* loop) Spawn ``no_wsgi_threads`` worker threads. Returns a pointer to an array of works. .. warning:: This is a HACK. .. c:function:: ymo_status_t ymo_wsgi_stop_workers( int no_wsgi_threads, ymo_wsgi_worker_t* workers) Stop the WSGI worker threads in the the ``workers`` array. .. warning:: This is a HACK. .. c:function:: ymo_wsgi_worker_t* ymo_wsgi_proc_assign_worker(ymo_wsgi_proc_t* w_proc, size_t session_id) Given a session ID, return the worker that should handle requests from the session.