7 #include <sys/select.h>
11 #include "opensrf/transport_message.h"
12 #include "osrf_stack.h"
13 #include "osrf_settings.h"
15 #define READ_BUFSIZE 4096
16 #define MAX_BUFSIZE 10485760 /* 10M enough? ;) */
17 #define ABS_MAX_CHILDREN 256
19 /* we receive data. we find the next child in
20 line that is available. pass the data down that childs pipe and go
21 back to listening for more data.
22 when we receive SIGCHLD, we check for any dead children and clean up
23 their respective prefork_child objects, close pipes, etc.
25 we build a select fd_set with all the child pipes (going to the parent)
26 when a child is done processing a request, it writes a small chunk of
27 data to the parent to alert the parent that the child is again available
30 struct prefork_simple_struct {
37 int current_num_children;
39 struct prefork_child_struct* first_child;
40 transport_client* connection;
42 typedef struct prefork_simple_struct prefork_simple;
44 struct prefork_child_struct {
54 struct prefork_child_struct* next;
55 transport_client* connection;
58 typedef struct prefork_child_struct prefork_child;
60 int osrf_prefork_run(char* appname);
62 prefork_simple* prefork_simple_init( transport_client* client,
63 int max_requests, int min_children, int max_children );
65 prefork_child* launch_child( prefork_simple* forker );
66 void prefork_launch_children( prefork_simple* forker );
68 void prefork_run(prefork_simple* forker);
70 void add_prefork_child( prefork_simple* forker, prefork_child* child );
71 prefork_child* find_prefork_child( prefork_simple* forker, pid_t pid );
72 void del_prefork_child( prefork_simple* forker, pid_t pid );
74 void check_children( prefork_simple* forker );
76 void prefork_child_process_request(prefork_child*, char* data);
77 void prefork_child_init_hook(prefork_child*);
79 prefork_child* prefork_child_init(
80 int max_requests, int read_data_fd, int write_data_fd,
81 int read_status_fd, int write_status_fd );
83 /* listens on the 'data_to_child' fd and wait for incoming data */
84 void prefork_child_wait( prefork_child* child );
86 int prefork_free( prefork_simple* );
87 int prefork_child_free( prefork_child* );