Commit 71c27f13 authored by Jim Jagielski's avatar Jim Jagielski
Browse files

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
parent 7ab70e02
Loading
Loading
Loading
Loading
+3 −32
Changes for modules/proxy/mod_proxy.c: 3 added lines, 32 removed lines.
Original line number Diff line number Diff line
@@ -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,41 +210,11 @@ 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")) {
        if (!strcasecmp(val, "on"))
            worker->s->flush_packets = flush_on;
+24 −3
Changes for modules/proxy/mod_proxy.h: 24 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -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.
+41 −0
Changes for modules/proxy/proxy_util.c: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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;
}