[PATCH] Limit conn: Added "off" parameter to the 'limit_conn' directive

Maxim Dounin mdounin at mdounin.ru
Wed Feb 10 13:53:16 UTC 2016


Hello!

On Wed, Feb 10, 2016 at 11:31:42AM +0600, Pavel V. wrote:

> Hi, Maxim!
> 
> Thanks for reviewing my patches.
> 
> >> +
> >> +    if (ngx_strcmp(value[1].data, "off") == 0) {
> >> +        if (cf->args->nelts != 2) {
> >> +            return "has invalid number of arguments";
> >> +        }
> >> +
> >> +        if (lccf->off || lccf->limits.elts) {
> >> +            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
> >> +                               "\"limit_conn off\" cannot be used with other "
> >> +                               "\"limit_conn\" directives on the same level");
> >> +            return NGX_CONF_ERROR;
> >> +        }
> >> +
> >> +        lccf->off = 1;
> >> +        return NGX_CONF_OK;
> >> +    }
> >> +
> >> +    if (cf->args->nelts != 3) {
> >> +        return "has invalid number of arguments";
> >> +    }
> >> +
> >> +    if (lccf->off) {
> >> +        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
> >> +                           "\"limit_conn off\" cannot be used with other "
> >> +                           "\"limit_conn\" directives on the same level");
> >> +        return NGX_CONF_ERROR;
> >> +    }
> >> +
> 
> > This looks overcomplicated and far from what nginx normally prints 
> > on similar errors at the same time.  It should be possible to do 
> > this better.
> 
> Will the "'limit_conn' directive already defined with conflicting parameters"
> message be  suitable in this case?
> Which one should I use - ngx_conf_log_error() or
> return 'already defined with conflicting parameter'?

I would use something like

   return "conflicts with previous limits";

or something like this.  Though I haven't really tried and there 
may be better options.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list