22 #include <apr_signal.h>
25 #define AFW_IMPLEMENTATION_ID "fcgi"
34 static const afw_utf8_t impl_compiled_afw_version =
39 static void impl_handle_sigterm(
int signum)
48 FCGX_ShutdownPending();
65 "FCGX_Init() error", xctx);
73 impl_server_xctx = xctx;
82 self->pub.inf = &impl_afw_server_inf;
83 self->pub.xctx = xctx;
85 self->pub.thread_count = thread_count;
87 self->pub.afw_compiled_version = &impl_compiled_afw_version;
88 self->pub.server_version = &impl_compiled_afw_version;
89 self->pub.server_type = &afw_server_fcgi_s_afw_server_fcgi;
93 self->pub.server_version = &impl_compiled_afw_version;
96 self->environment_variables_object =
101 self->environment_variables_object,
true, xctx->p, xctx);
104 self->sock = FCGX_OpenSocket(path, 500);
105 if (self->sock < 0) {
107 "FCGX_OpenSocket() error", xctx);
118 &afw_s__AdaptiveServer_,
119 &afw_s_current,
self,
true, xctx);
123 &afw_server_fcgi_s_a_flag_trace_server,
124 &afw_server_fcgi_s_a_flag_trace_server_brief,
125 &afw_server_fcgi_s_a_flag_trace_server_description,
131 &afw_server_fcgi_s_a_flag_trace_server_request,
132 &afw_server_fcgi_s_a_flag_trace_server_request_brief,
133 &afw_server_fcgi_s_a_flag_trace_server_request_description,
134 &afw_server_fcgi_s_a_flag_trace_server,
139 &afw_server_fcgi_s_a_flag_trace_server_request_process,
140 &afw_server_fcgi_s_a_flag_trace_server_request_process_brief,
141 &afw_server_fcgi_s_a_flag_trace_server_request_process_description,
142 &afw_server_fcgi_s_a_flag_trace_server_request,
145 &afw_server_fcgi_s_a_flag_trace_server_request_process,
182 self, server_thread->fcgx_request, xctx);
183 xctx->request = request;
187 "Request begin thread %d concurrent %d",
189 server_thread->server->pub.concurrent);
226 "Request end thread %d concurrent %d",
228 server_thread->server->pub.concurrent);
234 impl_afw_server_request_thread_start(
const afw_thread_t *thread,
247 FCGX_InitRequest(server_thread->fcgx_request, server->sock,
248 FCGI_FAIL_ACCEPT_ON_INTR);
252 FCGX_Accept_r(server_thread->fcgx_request) >= 0)
261 max_concurrent = server->pub.max_concurrent;
263 if (concurrent > max_concurrent) {
265 max_concurrent, concurrent);
273 impl_process_request(server, server->director,
274 server_thread, request_session_xctx);
288 if (request_session_xctx) {
318 server->director = handler;
332 for (count = 1, server_thread = server->threads;
333 count <= server->pub.thread_count;
334 count++, server_thread++)
336 server_thread->server = server;
339 impl_afw_server_request_thread_start, server_thread,
345 for (count = 1, server_thread = server->threads;
346 count <= server->pub.thread_count;
347 count++, server_thread++)
Adaptive Framework Core API.
Header for interface afw_request* implementation development.
const afw_server_t * afw_server_fcgi_internal_create(const char *path, afw_integer_t thread_count, afw_xctx_t *xctx)
Create an FCGI afw_server.
Internal header file for AFW FCGI Server.
afw_server_fcgi_internal_request_t * afw_server_fcgi_internal_create_request(afw_server_fcgi_internal_t *server, FCGX_Request *fcgx_request, afw_xctx_t *xctx)
Adaptive Framework (afw_server_fcgi_) strings header.
Adaptive Framework Version (afw_server_fcgi_) header.
Interface afw_interface implementation declares.
afw_integer_t afw_atomic_integer_decrement(AFW_ATOMIC afw_integer_t *mem)
Integer atomic decrement.
afw_integer_t afw_atomic_integer_increment(AFW_ATOMIC afw_integer_t *mem)
Integer atomic increment.
afw_boolean_t afw_atomic_integer_cas(AFW_ATOMIC afw_integer_t *mem, afw_integer_t expected, afw_integer_t desired)
Integer atomic decrement.
#define AFW_UTF8_LITERAL(A_STRING)
String literal initializer.
#define AFW_THREAD_FUNCTION
Uses APR_THREAD_FUNC as AFW_THREAD_FUNCTION.
apr_size_t afw_size_t
size_t.
struct afw_thread_attr_s afw_thread_attr_t
Typedef for afw_thread_attr.
apr_int64_t afw_integer_t
typedef for big signed int.
const afw_object_t * afw_environment_create_environment_variables_object(afw_boolean_t preload_variables, afw_xctx_t *xctx)
Create a readonly object for accessing environment variables.
#define AFW_FINALLY
Always executed regardless of error.
afw_error_http_status(const afw_error_t *error)
Returns http status for error.
#define AFW_CATCH_UNHANDLED
Catch an unhandled error that occurs in a AFW_TRY block.
afw_error_write_log(afw_log_priority_t priority, const afw_error_t *error, afw_xctx_t *xctx)
Write error to environment log.
#define AFW_ENDTRY
Ends an AFW try block.
#define AFW_TRY
Begin an AFW TRY block.
#define AFW_ERROR_THROWN
Access the thrown error. See AFW_TRY.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
#define AFW_CATCH(__CODE_)
Catch a particular error that occurs in a AFW_TRY block.
void afw_flag_environment_register_flag(const afw_utf8_t *flag_id, const afw_utf8_t *brief, const afw_utf8_t *description, const afw_utf8_t *included_by_flag_id, afw_xctx_t *xctx)
Register a flag definition.
afw_flag_get_index(const afw_utf8_t *flag_id, afw_xctx_t *xctx)
Get the flag index for a flag id.
#define afw_object_create_managed(p, xctx)
Create an empty entity object in its own pool.
afw_request_impl_trace_begin(const afw_request_t *instance, afw_xctx_t *xctx)
Trace request begin if requested.
#define afw_request_handler_process(instance, request, xctx)
Call method process of interface afw_request_handler.
#define afw_request_release(instance, xctx)
Call method release of interface afw_request.
afw_request_write_error_to_response_body(const afw_request_t *instance, const afw_utf8_t *code, const afw_error_t *error, afw_xctx_t *xctx)
Write xctx error to response body.
afw_runtime_env_create_and_set_indirect_object(const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, void *internal, afw_boolean_t overwrite, afw_xctx_t *xctx)
Create and set an indirect runtime object.
afw_runtime_xctx_set_object(const afw_object_t *object, afw_boolean_t overwrite, afw_xctx_t *xctx)
Set an object pointer in the xctx's runtime objects.
void impl_afw_server_release(const afw_server_t *instance, afw_xctx_t *xctx)
void impl_afw_server_run(const afw_server_t *instance, const afw_request_handler_t *handler, afw_xctx_t *xctx)
afw_thread_join(const afw_thread_t *thread, afw_xctx_t *xctx)
Join a thread.
afw_thread_create(afw_thread_attr_t *thread_attr, afw_thread_function_t start_function, void *start_function_arg, const afw_utf8_t *name, afw_integer_t thread_number, afw_xctx_t *xctx)
Create a thread.
afw_thread_attr_create(const afw_pool_t *p, afw_xctx_t *xctx)
Create a thread attr.
afw_dateTime_now_local(const afw_pool_t *p, afw_xctx_t *xctx)
Get now local time as dateTime in specified pool.
#define afw_trace_fz(trace_level, flag_index, instance, xctx, format_z,...)
If applicable, write trace using a printf style format.
const afw_utf8_t * afw_version_string()
#define afw_xctx_release(instance, xctx)
Call method release of interface afw_xctx.
#define AFW_XCTX_s_NAME_REQUEST_SESSION
#define AFW_XCTX_s_NAME_REQUEST_THREAD
afw_xctx_push_qualifier_object(const afw_utf8_t *qualifier_name, const afw_object_t *qualifier_object, afw_boolean_t secure, const afw_pool_t *p, afw_xctx_t *xctx)
Push qualifier object on to stack.
afw_boolean_t afw_xctx_environment_is_terminating(afw_xctx_t *xctx)
Test for environment terminating.
#define afw_xctx_calloc(size, xctx)
Macro to allocate cleared memory in xctx's pool.
afw_xctx_create(const afw_utf8_t *name, afw_integer_t number, afw_xctx_t *xctx)
Create an Adaptive Framework xctx.
#define afw_xctx_calloc_type(type, xctx)
Macro to allocate cleared memory to hold type in xctx's pool.
Struct for typedef afw_environment_t defined in afw_common.h.
afw_boolean_t terminating
Indicates that environment is terminating.
Interface afw_request_handler public struct.
Interface afw_request public struct.
Interface afw_server public struct.
Struct for public part of afw_pool_t.
afw_integer_t thread_number
The thread number within the afw environment.
afw_xctx_t * xctx
The base xctx for the thread.
NFC normalized UTF-8 string.
Interface afw_xctx public struct.