simple_run.c revision 6881fda812136efa364537ad49964b509a345bd2
af84459fbf938e508fd10b01cb8d699c79083813takashi/* Licensed to the Apache Software Foundation (ASF) under one or more
af84459fbf938e508fd10b01cb8d699c79083813takashi * contributor license agreements. See the NOTICE file distributed with
af84459fbf938e508fd10b01cb8d699c79083813takashi * this work for additional information regarding copyright ownership.
af84459fbf938e508fd10b01cb8d699c79083813takashi * The ASF licenses this file to You under the Apache License, Version 2.0
af84459fbf938e508fd10b01cb8d699c79083813takashi * (the "License"); you may not use this file except in compliance with
af84459fbf938e508fd10b01cb8d699c79083813takashi * the License. You may obtain a copy of the License at
af84459fbf938e508fd10b01cb8d699c79083813takashi * Unless required by applicable law or agreed to in writing, software
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * distributed under the License is distributed on an "AS IS" BASIS,
2e545ce2450a9953665f701bb05350f0d3f26275nd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen/* #define APR_RING_DEBUG 1 */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * Create Timers.
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic apr_status_t simple_main_setup_timers(simple_core_t * sc)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_register_timer(sc, simple_check_children_size, NULL, 0, sc->pool);
af84459fbf938e508fd10b01cb8d699c79083813takashi * Create worker thread pool.
af84459fbf938e508fd10b01cb8d699c79083813takashistatic apr_status_t simple_setup_workers(simple_core_t * sc)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "simple_setup_workers: apr_thread_pool_create with %d threads failed",
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic apr_status_t simple_setup_listeners(simple_core_t * sc)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_pollfd_t *pfd = apr_palloc(sc->pool, sizeof(apr_pollfd_t));
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_sb_t *sb = apr_pcalloc(sc->pool, sizeof(simple_sb_t));
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen rv = apr_socket_opt_set(pfd->desc.s, APR_SO_NONBLOCK, 1);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "simple_setup_workers: apr_socket_opt_set(APR_SO_NONBLOCK = 1) failed on %pI",
4bebf996eb7002ebfe897d46a0e0572390604a77nd "simple_setup_workers: apr_pollcb_add failed on %pI",
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowenstatic apr_status_t simple_io_callback(void *baton, apr_pollfd_t * pfd)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* TODO: */
7e9d90004f580231e0376880710dc25408950ab9rbowenstatic void *simple_timer_invoke(apr_thread_t * thread, void *baton)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#define apr_time_from_msec(msec) ((apr_time_t)(msec) * 1000)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_interval_time_t timeout = apr_time_from_msec(500);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_RING_HEAD(simple_temp_timer_ring_t, simple_timer_t) tmp_ring;
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh if (head != APR_RING_SENTINEL(&sc->timer_ring, simple_timer_t, link)) {
4aa603e6448b99f9371397d439795c91a93637eand /* pqXXXXX: I'm 95% sure that the Linux Powertop guys will slap me for this. */
f039cf01b271a31e317d5b84f24cb135f1c1b6d7nd /* We have already expired timers in the queue. */
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh rv = apr_pollcb_poll(sc->pollcb, timeout, simple_io_callback, sc);
af84459fbf938e508fd10b01cb8d699c79083813takashi if (!APR_STATUS_IS_EINTR(rv) && !APR_STATUS_IS_TIMEUP(rv)) {
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen "simple_main_loop: apr_pollcb_poll failed");
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link);
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic /* now iterate any timers */
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic if (!APR_RING_EMPTY(&sc->timer_ring, simple_timer_t, link)) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* push this task */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_RING_INSERT_TAIL(&tmp_ring, ep, simple_timer_t, link);
4bebf996eb7002ebfe897d46a0e0572390604a77nd APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (!APR_RING_EMPTY(&tmp_ring, simple_timer_t, link)) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* Normally this is only ran in the child processes, but we want to do it here too... */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "simple_single_child_hack: simple_setup_listeners failed");
253547fb9cc7986e84ff68aef076f664fc4169dctakashi int rv = ap_run_simple_drop_privileges(sc->pool, ap_server_conf);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "simple_setup_privs: ap_run_simple_drop_privileges failed");
8559a67073808d84d85bb5dd552d4247caafe709sf rv = apr_pollcb_create(&sc->pollcb, 512 /* pqXXXXX: make configrable */ ,
8559a67073808d84d85bb5dd552d4247caafe709sf "simple_core_init: apr_pollcb_create failed.");
8559a67073808d84d85bb5dd552d4247caafe709sf /* XXXXX: Hack. Reseting parts of the simple core needs to be more
8559a67073808d84d85bb5dd552d4247caafe709sf * thought out than this.
4bebf996eb7002ebfe897d46a0e0572390604a77nd "simple_child_loop: simple_setup_workers failed");
65a611af7093423efb91e5794b8887a527d4cf63trawick "simple_child_loop: simple_setup_sockets failed");
253547fb9cc7986e84ff68aef076f664fc4169dctakashi "simple_child_loop: simple_drop_privs failed");
9534272616b71aaea50aeec4162e749a96aebd7fsf "simple_main_loop: simple_setup_workers failed");
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "simple_main_loop: simple_setup_timers failed");