]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/libstack/osrf_prefork.h
28df9dfbda1e40fdc099a2d55fdb6c48843a1235
[OpenSRF.git] / src / libstack / osrf_prefork.h
1 #include <sys/types.h>
2 #include <sys/time.h>
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <sys/select.h>
8 #include <sys/wait.h>
9
10 #include "opensrf/utils.h"
11 #include "opensrf/transport_message.h"
12 #include "opensrf/transport_client.h"
13 #include "osrf_stack.h"
14 #include "osrf_settings.h"
15 #include "osrfConfig.h"
16
17 //#define READ_BUFSIZE 4096
18 #define READ_BUFSIZE 1024
19 #define MAX_BUFSIZE 10485760 /* 10M enough? ;) */
20 #define ABS_MAX_CHILDREN 256 
21
22 /* we receive data.  we find the next child in
23         line that is available.  pass the data down that childs pipe and go
24         back to listening for more data.
25         when we receive SIGCHLD, we check for any dead children and clean up
26         their respective prefork_child objects, close pipes, etc.
27
28         we build a select fd_set with all the child pipes (going to the parent) 
29         when a child is done processing a request, it writes a small chunk of 
30         data to the parent to alert the parent that the child is again available 
31         */
32
33 struct prefork_simple_struct {
34         int max_requests;
35         int min_children;
36         int max_children;
37         int fd;
38         int data_to_child;
39         int data_to_parent;
40         int current_num_children;
41         int keepalive; /* keepalive time for stateful sessions */
42         char* appname;
43         struct prefork_child_struct* first_child;
44         transport_client* connection;
45 };
46 typedef struct prefork_simple_struct prefork_simple;
47
48 struct prefork_child_struct {
49         pid_t pid;
50         int read_data_fd;
51         int write_data_fd;
52         int read_status_fd;
53         int write_status_fd;
54         int min_children;
55         int available;
56         int max_requests;
57         char* appname;
58         int keepalive;
59         struct prefork_child_struct* next;
60 };
61
62 typedef struct prefork_child_struct prefork_child;
63
64 int osrf_prefork_run(char* appname);
65
66 prefork_simple*  prefork_simple_init( transport_client* client, 
67         int max_requests, int min_children, int max_children );
68
69 prefork_child*  launch_child( prefork_simple* forker );
70 void prefork_launch_children( prefork_simple* forker );
71
72 void prefork_run(prefork_simple* forker);
73
74 void add_prefork_child( prefork_simple* forker, prefork_child* child );
75 prefork_child* find_prefork_child( prefork_simple* forker, pid_t pid );
76 void del_prefork_child( prefork_simple* forker, pid_t pid );
77
78 void check_children( prefork_simple* forker, int forever );
79
80 void prefork_child_process_request(prefork_child*, char* data);
81 int prefork_child_init_hook(prefork_child*);
82
83 prefork_child* prefork_child_init( 
84                 int max_requests, int read_data_fd, int write_data_fd, 
85                 int read_status_fd, int write_status_fd );
86
87 /* listens on the 'data_to_child' fd and wait for incoming data */
88 void prefork_child_wait( prefork_child* child );
89
90 int prefork_free( prefork_simple* );
91 int prefork_child_free( prefork_child* );
92
93
94 void osrf_prefork_register_routers( char* appname );
95
96