From 6c0a4fc5da5a2fae58e5f3f1747c59a0f6d87052 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Tue, 1 Feb 2011 18:13:15 +0000 Subject: [PATCH] Move the setting of flags into a func... that way there is one place to maintain as the number of flags grow... Since we are using just the bits, make unsigned. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1066110 13f79535-47bb-0310-9956-ffa450edef68 --- modules/proxy/mod_proxy.c | 35 +++----------------------------- modules/proxy/mod_proxy.h | 27 ++++++++++++++++++++++--- modules/proxy/proxy_util.c | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 35 deletions(-) diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index 4c3f151725..158d4e834b 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -198,6 +198,7 @@ static const char *set_worker_param(apr_pool_t *p, else if (!strcasecmp(key, "status")) { const char *v; int mode = 1; + apr_status_t rv; /* Worker status. */ for (v = val; *v; v++) { @@ -209,39 +210,9 @@ static const char *set_worker_param(apr_pool_t *p, mode = 0; v++; } - if (*v == 'D' || *v == 'd') { - if (mode) - worker->s->status |= PROXY_WORKER_DISABLED; - else - worker->s->status &= ~PROXY_WORKER_DISABLED; - } - else if (*v == 'S' || *v == 's') { - if (mode) - worker->s->status |= PROXY_WORKER_STOPPED; - else - worker->s->status &= ~PROXY_WORKER_STOPPED; - } - else if (*v == 'E' || *v == 'e') { - if (mode) - worker->s->status |= PROXY_WORKER_IN_ERROR; - else - worker->s->status &= ~PROXY_WORKER_IN_ERROR; - } - else if (*v == 'H' || *v == 'h') { - if (mode) - worker->s->status |= PROXY_WORKER_HOT_STANDBY; - else - worker->s->status &= ~PROXY_WORKER_HOT_STANDBY; - } - else if (*v == 'I' || *v == 'i') { - if (mode) - worker->s->status |= PROXY_WORKER_IGNORE_ERRORS; - else - worker->s->status &= ~PROXY_WORKER_IGNORE_ERRORS; - } - else { + rv = ap_proxy_set_wstatus(*v, mode, &worker->s->status); + if (rv != APR_SUCCESS) return "Unknown status parameter option"; - } } } else if (!strcasecmp(key, "flushpackets")) { diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index b1a90ff913..bbacb3eefc 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -254,7 +254,7 @@ struct proxy_conn_pool { proxy_conn_rec *conn; /* Single connection for prefork mpm */ }; -/* worker status flags */ +/* worker status bits */ #define PROXY_WORKER_INITIALIZED 0x0001 #define PROXY_WORKER_IGNORE_ERRORS 0x0002 #define PROXY_WORKER_DRAIN 0x0004 @@ -265,6 +265,17 @@ struct proxy_conn_pool { #define PROXY_WORKER_HOT_STANDBY 0x0100 #define PROXY_WORKER_FREE 0x0200 +/* worker status flags */ +#define PROXY_WORKER_INITIALIZED_FLAG 'O' +#define PROXY_WORKER_IGNORE_ERRORS_FLAG 'I' +#define PROXY_WORKER_DRAIN_FLAG 'N' +#define PROXY_WORKER_IN_SHUTDOWN_FLAG 'U' +#define PROXY_WORKER_DISABLED_FLAG 'D' +#define PROXY_WORKER_STOPPED_FLAG 'S' +#define PROXY_WORKER_IN_ERROR_FLAG 'E' +#define PROXY_WORKER_HOT_STANDBY_FLAG 'H' +#define PROXY_WORKER_FREE_FLAG 'F' + #define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \ PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR ) @@ -296,7 +307,6 @@ typedef struct { char redirect[PROXY_WORKER_MAX_ROUTE_SIZE]; /* temporary balancing redirection route */ char flusher[PROXY_WORKER_MAX_SCHEME_SIZE]; /* flush provider used by mod_proxy_fdpass */ int lbset; /* load balancer cluster set */ - int status; int retries; /* number of retries on this worker */ int lbstatus; /* Current lbstatus */ int lbfactor; /* dynamic lbfactor */ @@ -306,6 +316,7 @@ typedef struct { int flush_wait; /* poll wait time in microseconds if flush_auto */ int index; /* shm array index */ unsigned int hash; /* hash of worker name */ + unsigned int status; /* worker status bitfield */ enum { flush_off, flush_on, @@ -348,11 +359,11 @@ typedef struct { /* Worker configuration */ struct proxy_worker { unsigned int hash; /* hash of worker name */ + unsigned int local_status; /* status of per-process worker */ proxy_conn_pool *cp; /* Connection pool to use */ proxy_worker_shared *s; /* Shared data */ proxy_balancer *balancer; /* which balancer am I in? */ apr_thread_mutex_t *mutex; /* Thread lock for updating address cache */ - int local_status; /* status of per-process worker */ void *context; /* general purpose storage */ }; @@ -810,6 +821,16 @@ typedef enum { PROXY_HASHFUNC_DEFAULT, PROXY_HASHFUNC_APR, PROXY_HASHFUNC_FNV } PROXY_DECLARE(unsigned int) ap_proxy_hashfunc(const char *str, proxy_hash_t method); + +/** + * Set/unset the worker status bitfield depending on flag + * @param c flag + * @param set set or unset bit + * @param status bitfield to use + * @return APR_SUCCESS if valid flag + */ +PROXY_DECLARE(apr_status_t) ap_proxy_set_wstatus(char c, int set, unsigned int *status); + #define PROXY_LBMETHOD "proxylbmethod" /* The number of dynamic workers that can be added when reconfiguring. diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index bc0d443126..02c8e9ed16 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -2833,3 +2833,44 @@ ap_proxy_hashfunc(const char *str, proxy_hash_t method) return hash; } } + +PROXY_DECLARE(apr_status_t) ap_proxy_set_wstatus(const char c, int set, unsigned int *status) +{ + char bit = toupper(c); + switch (bit) { + case PROXY_WORKER_DISABLED_FLAG : + if (set) + *status |= PROXY_WORKER_DISABLED; + else + *status &= ~PROXY_WORKER_DISABLED; + break; + case PROXY_WORKER_STOPPED_FLAG : + if (set) + *status |= PROXY_WORKER_STOPPED; + else + *status &= ~PROXY_WORKER_STOPPED; + break; + case PROXY_WORKER_IN_ERROR_FLAG : + if (set) + *status |= PROXY_WORKER_IN_ERROR; + else + *status &= ~PROXY_WORKER_IN_ERROR; + break; + case PROXY_WORKER_HOT_STANDBY_FLAG : + if (set) + *status |= PROXY_WORKER_HOT_STANDBY; + else + *status &= ~PROXY_WORKER_HOT_STANDBY; + break; + case PROXY_WORKER_IGNORE_ERRORS_FLAG : + if (set) + *status |= PROXY_WORKER_IGNORE_ERRORS; + else + *status &= ~PROXY_WORKER_IGNORE_ERRORS; + break; + default: + return APR_EINVAL; + break; + } + return APR_SUCCESS; +} -- 2.50.0