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/**
18 * @file  event/fdqueue.h
19 * @brief fd queue declarations
20 *
21 * @addtogroup APACHE_MPM_EVENT
22 * @{
23 */
24
25#ifndef FDQUEUE_H
26#define FDQUEUE_H
27#include "httpd.h"
28#include <stdlib.h>
29#if APR_HAVE_UNISTD_H
30#include <unistd.h>
31#endif
32#include <apr_thread_mutex.h>
33#include <apr_thread_cond.h>
34#include <sys/types.h>
35#if APR_HAVE_SYS_SOCKET_H
36#include <sys/socket.h>
37#endif
38#include <apr_errno.h>
39
40#include "ap_mpm.h"
41
42typedef struct fd_queue_info_t fd_queue_info_t;
43typedef struct event_conn_state_t event_conn_state_t;
44
45apr_status_t ap_queue_info_create(fd_queue_info_t ** queue_info,
46                                  apr_pool_t * pool, int max_idlers,
47                                  int max_recycled_pools);
48apr_status_t ap_queue_info_set_idle(fd_queue_info_t * queue_info,
49                                    apr_pool_t * pool_to_recycle);
50apr_status_t ap_queue_info_try_get_idler(fd_queue_info_t * queue_info);
51apr_status_t ap_queue_info_wait_for_idler(fd_queue_info_t * queue_info,
52                                          int *had_to_block);
53apr_status_t ap_queue_info_term(fd_queue_info_t * queue_info);
54apr_uint32_t ap_queue_info_get_idlers(fd_queue_info_t * queue_info);
55
56struct fd_queue_elem_t
57{
58    apr_socket_t *sd;
59    apr_pool_t *p;
60    event_conn_state_t *ecs;
61};
62typedef struct fd_queue_elem_t fd_queue_elem_t;
63
64typedef struct timer_event_t timer_event_t;
65
66struct timer_event_t {
67    APR_RING_ENTRY(timer_event_t) link;
68    apr_time_t when;
69    ap_mpm_callback_fn_t *cbfunc;
70    void *baton;
71};
72
73
74struct fd_queue_t
75{
76    APR_RING_HEAD(timers_t, timer_event_t) timers;
77    fd_queue_elem_t *data;
78    unsigned int nelts;
79    unsigned int bounds;
80    unsigned int in;
81    unsigned int out;
82    apr_thread_mutex_t *one_big_mutex;
83    apr_thread_cond_t *not_empty;
84    int terminated;
85};
86typedef struct fd_queue_t fd_queue_t;
87
88void ap_pop_pool(apr_pool_t ** recycled_pool, fd_queue_info_t * queue_info);
89void ap_push_pool(fd_queue_info_t * queue_info,
90                                    apr_pool_t * pool_to_recycle);
91
92apr_status_t ap_queue_init(fd_queue_t * queue, int queue_capacity,
93                           apr_pool_t * a);
94apr_status_t ap_queue_push(fd_queue_t * queue, apr_socket_t * sd,
95                           event_conn_state_t * ecs, apr_pool_t * p);
96apr_status_t ap_queue_push_timer(fd_queue_t *queue, timer_event_t *te);
97apr_status_t ap_queue_pop_something(fd_queue_t * queue, apr_socket_t ** sd,
98                                    event_conn_state_t ** ecs, apr_pool_t ** p,
99                                    timer_event_t ** te);
100apr_status_t ap_queue_interrupt_all(fd_queue_t * queue);
101apr_status_t ap_queue_term(fd_queue_t * queue);
102
103#endif /* FDQUEUE_H */
104/** @} */
105