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