simple_core.c revision 52a5101047d0148d33df1f9f4f77b24bce7fdf70
5fb13eb51bf641a3434828947e137e1a5f2d7eb2Lennart Poettering/* Licensed to the Apache Software Foundation (ASF) under one or more
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen * contributor license agreements. See the NOTICE file distributed with
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips * this work for additional information regarding copyright ownership.
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips * The ASF licenses this file to You under the Apache License, Version 2.0
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips * (the "License"); you may not use this file except in compliance with
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips * the License. You may obtain a copy of the License at
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips *
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips * http://www.apache.org/licenses/LICENSE-2.0
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering *
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * Unless required by applicable law or agreed to in writing, software
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips * distributed under the License is distributed on an "AS IS" BASIS,
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips * See the License for the specific language governing permissions and
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips * limitations under the License.
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips */
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips/* Simple Core utility methods.
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering */
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips#include "simple_types.h"
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips#include "mpm.h"
4149f86d816fc0fef41d35de5beb09bfe81e0d6aBrandon Philips#include "ap_mpm.h"
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek#include "httpd.h"
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek#include "http_log.h"
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmekstatic simple_core_t g_simple_core;
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek#ifndef DEFAULT_MAX_REQUESTS_PER_CHILD
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek#define DEFAULT_MAX_REQUESTS_PER_CHILD 0
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek#endif
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmeksimple_core_t *simple_core_get()
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek{
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek return &g_simple_core;
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek}
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmekapr_status_t simple_core_init(simple_core_t * sc, apr_pool_t * pool)
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek{
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek apr_status_t rv;
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek memset(sc, 0, sizeof(simple_core_t));
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek apr_pool_create(&sc->pool, pool);
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek apr_pool_tag(sc->pool, "simple-mpm-core");
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek sc->mpm_state = AP_MPMQ_STARTING;
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek sc->procmgr.max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek sc->children = apr_hash_make(sc->pool);
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek APR_RING_INIT(&sc->timer_ring, simple_timer_t, link);
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek APR_RING_INIT(&sc->dead_timer_ring, simple_timer_t, link);
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek rv = apr_thread_mutex_create(&sc->mtx, 0, sc->pool);
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek if (rv) {
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek "simple_core_init: apr_thread_mutex_create failed.");
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek return rv;
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek }
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek rv = apr_pollcb_create(&sc->pollcb, 512 /* pqXXXXX: make configrable */ ,
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek sc->pool, 0);
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek if (rv) {
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek "simple_core_init: apr_pollcb_create failed.");
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek return rv;
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek }
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek return APR_SUCCESS;
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek}
302fbdf29eb0ad4ca1fe8ee18755edad7db11b37Zbigniew Jędrzejewski-Szmek