upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / server / mpm / experimental / threadpool / pod.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "pod.h"
18
19 #if APR_HAVE_UNISTD_H
20 #include <unistd.h>
21 #endif
22
23 AP_DECLARE(apr_status_t) ap_mpm_pod_open(apr_pool_t *p, ap_pod_t **pod)
24 {
25     apr_status_t rv;
26
27     *pod = apr_palloc(p, sizeof(**pod));
28     rv = apr_file_pipe_create(&((*pod)->pod_in), &((*pod)->pod_out), p);
29     if (rv != APR_SUCCESS) {
30         return rv;
31     }
32 /*
33     apr_file_pipe_timeout_set((*pod)->pod_in, 0);
34 */
35     (*pod)->p = p;
36     
37     return APR_SUCCESS;
38 }
39
40 AP_DECLARE(int) ap_mpm_pod_check(ap_pod_t *pod)
41 {
42     char c;
43     apr_os_file_t fd;
44     int rc;
45
46     /* we need to surface EINTR so we'll have to grab the
47      * native file descriptor and do the OS read() ourselves
48      */
49     apr_os_file_get(&fd, pod->pod_in);
50     rc = read(fd, &c, 1);
51     if (rc == 1) {
52         switch(c) {
53         case RESTART_CHAR:
54             return AP_RESTART;
55         case GRACEFUL_CHAR:
56             return AP_GRACEFUL;
57         }
58     }
59     return AP_NORESTART;
60 }
61
62 AP_DECLARE(apr_status_t) ap_mpm_pod_close(ap_pod_t *pod)
63 {
64     apr_status_t rv;
65
66     rv = apr_file_close(pod->pod_out);
67     if (rv != APR_SUCCESS) {
68         return rv;
69     }
70
71     rv = apr_file_close(pod->pod_in);
72     if (rv != APR_SUCCESS) {
73         return rv;
74     }
75     return rv;
76 }
77
78 static apr_status_t pod_signal_internal(ap_pod_t *pod, int graceful)
79 {
80     apr_status_t rv;
81     char char_of_death = graceful ? GRACEFUL_CHAR : RESTART_CHAR;
82     apr_size_t one = 1;
83
84     do {
85         rv = apr_file_write(pod->pod_out, &char_of_death, &one);
86     } while (APR_STATUS_IS_EINTR(rv));
87     if (rv != APR_SUCCESS) {
88         ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
89                      "write pipe_of_death");
90     }
91     return rv;
92 }
93
94 AP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t *pod, int graceful)
95 {
96     return pod_signal_internal(pod, graceful);
97 }
98
99 AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t *pod, int num, int graceful)
100 {
101     int i;
102     apr_status_t rv = APR_SUCCESS;
103
104     for (i = 0; i < num && rv == APR_SUCCESS; i++) {
105         rv = pod_signal_internal(pod, graceful);
106     }
107 }
108