diff options
author | Evgeny Kotkov <kotkov@apache.org> | 2017-07-07 13:14:25 +0200 |
---|---|---|
committer | Evgeny Kotkov <kotkov@apache.org> | 2017-07-07 13:14:25 +0200 |
commit | c3c585fa8ef5a370bef4fd9d39670e4630500a5a (patch) | |
tree | c94e79856e91daef4b8d666222b7bc120e549e00 /server | |
parent | mpm_winnt: Remove an unnecessary retry after receiving a non-timeout failure (diff) | |
download | apache2-c3c585fa8ef5a370bef4fd9d39670e4630500a5a.tar.xz apache2-c3c585fa8ef5a370bef4fd9d39670e4630500a5a.zip |
mpm_winnt: Refactor the mpm_get_completion_context() function so that it
would return a proper apr_status_t instead of yielding the result via the
*timeout out variable.
This makes the calling side easier to follow by avoiding an additional
layer of if's.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1801147 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server')
-rw-r--r-- | server/mpm/winnt/child.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/server/mpm/winnt/child.c b/server/mpm/winnt/child.c index c891a1a6f5..1a65f8ca0d 100644 --- a/server/mpm/winnt/child.c +++ b/server/mpm/winnt/child.c @@ -159,12 +159,12 @@ static void mpm_recycle_completion_context(winnt_conn_ctx_t *context) } } -static winnt_conn_ctx_t *mpm_get_completion_context(int *timeout) +static apr_status_t mpm_get_completion_context(winnt_conn_ctx_t **context_p) { - apr_status_t rv; + apr_status_t status; winnt_conn_ctx_t *context = NULL; - *timeout = 0; + *context_p = NULL; while (1) { /* Grab a context off the queue */ apr_thread_mutex_lock(qlock); @@ -185,6 +185,7 @@ static winnt_conn_ctx_t *mpm_get_completion_context(int *timeout) * at once. */ if (num_completion_contexts >= max_num_completion_contexts) { + DWORD rv; /* All workers are busy, need to wait for one */ static int reported = 0; if (!reported) { @@ -209,16 +210,17 @@ static winnt_conn_ctx_t *mpm_get_completion_context(int *timeout) ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(00327) "mpm_get_completion_context: Failed to get a " "free context within 1 second"); - *timeout = 1; + return APR_TIMEUP; } else { /* should be the unexpected, generic WAIT_FAILED */ - ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(), + status = APR_FROM_OS_ERROR(rv); + ap_log_error(APLOG_MARK, APLOG_WARNING, status, ap_server_conf, APLOGNO(00328) "mpm_get_completion_context: " "WaitForSingleObject failed to get free context"); + return status; } - return NULL; } } else { /* Allocate another context. @@ -237,28 +239,29 @@ static winnt_conn_ctx_t *mpm_get_completion_context(int *timeout) FALSE, NULL); if (context->overlapped.hEvent == NULL) { /* Hopefully this is a temporary condition ... */ - ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(), + status = apr_get_os_error(); + ap_log_error(APLOG_MARK, APLOG_WARNING, status, ap_server_conf, APLOGNO(00329) "mpm_get_completion_context: " "CreateEvent failed."); apr_thread_mutex_unlock(child_lock); - return NULL; + return status; } /* Create the transaction pool */ apr_allocator_create(&allocator); apr_allocator_max_free_set(allocator, ap_max_mem_free); - rv = apr_pool_create_ex(&context->ptrans, pchild, NULL, - allocator); - if (rv != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf, APLOGNO(00330) + status = apr_pool_create_ex(&context->ptrans, pchild, NULL, + allocator); + if (status != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_WARNING, status, ap_server_conf, APLOGNO(00330) "mpm_get_completion_context: Failed " "to create the transaction pool."); CloseHandle(context->overlapped.hEvent); apr_thread_mutex_unlock(child_lock); - return NULL; + return status; } apr_allocator_owner_set(allocator, context->ptrans); apr_pool_tag(context->ptrans, "transaction"); @@ -276,7 +279,8 @@ static winnt_conn_ctx_t *mpm_get_completion_context(int *timeout) } } - return context; + *context_p = context; + return APR_SUCCESS; } typedef enum { @@ -358,7 +362,7 @@ static unsigned int __stdcall winnt_accept(void *lr_) LPFN_GETACCEPTEXSOCKADDRS lpfnGetAcceptExSockaddrs = NULL; GUID GuidAcceptEx = WSAID_ACCEPTEX; GUID GuidGetAcceptExSockaddrs = WSAID_GETACCEPTEXSOCKADDRS; - int rv; + apr_status_t rv; accept_filter_e accf; int err_count = 0; HANDLE events[3]; @@ -433,16 +437,14 @@ reinit: /* target of connect upon too many AcceptEx failures */ while (!shutdown_in_progress) { if (!context) { - int timeout; - - context = mpm_get_completion_context(&timeout); - if (!context) { - if (!timeout) { - break; - } + rv = mpm_get_completion_context(&context); + if (APR_STATUS_IS_TIMEUP(rv)) { Sleep(100); continue; } + else if (rv) { + break; + } } if (accf == ACCEPT_FILTER_CONNECT) |