Change maxsessions feature behaviour

*  0 will allow 0 sessions (e.g. can be used for draining rtpengine)
* -1 will disable the feature and will be treated the same way as if
MAX_SESSIONS variable has not been set via configuration file
(or has been set to -1 in configuration file)
* < -1 will not be taken into consideration
* add check for minint range also
pull/192/head
smititelu 10 years ago
parent 06b129335a
commit c969ab9f60

@ -752,7 +752,7 @@ out:
const char *call_offer_ng(bencode_item_t *input, struct callmaster *m, bencode_item_t *output, const char* addr,
const struct sockaddr_in6 *sin)
{
if (m->conf.max_sessions>0) {
if (m->conf.max_sessions>=0) {
rwlock_lock_r(&m->hashlock);
if (g_hash_table_size(m->callhash) >= m->conf.max_sessions) {
rwlock_unlock_r(&m->hashlock);

@ -286,6 +286,8 @@ static void cli_incoming_set_maxopenfiles(char* buffer, int len, struct callmast
static void cli_incoming_set_maxsessions(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) {
int printlen = 0;
int maxsessions_num;
int err = 0x80000000;
int disabled = -1;
str maxsessions;
if (len<=1) {
@ -297,22 +299,27 @@ static void cli_incoming_set_maxsessions(char* buffer, int len, struct callmaste
++buffer; --len; // one space
maxsessions.s = buffer;
maxsessions.len = len;
maxsessions_num = str_to_i(&maxsessions, -1);
maxsessions_num = str_to_i(&maxsessions, err);
if (maxsessions_num == -1) {
if (maxsessions_num == err) {
printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting maxsessions to %.*s; not an integer\n", maxsessions.len, maxsessions.s);
ADJUSTLEN(printlen,outbufend,replybuffer);
return;
} else if (maxsessions_num < 0) {
printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting maxsessions to %d; negative value\n", maxsessions_num);
} else if (maxsessions_num < disabled) {
printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting maxsessions to %d; either positive or -1 values allowed\n", maxsessions_num);
ADJUSTLEN(printlen,outbufend,replybuffer);
} else if (maxsessions_num == disabled) {
/* don't lock anything while writing the value - only this command modifies its value */
m->conf.max_sessions = maxsessions_num;
printlen = snprintf (replybuffer,(outbufend-replybuffer), "Success setting maxsessions to %d; disable feature\n", maxsessions_num);
ADJUSTLEN(printlen,outbufend,replybuffer);
return;
} else {
/* don't lock anything while writing the value - only this command modifies its value */
m->conf.max_sessions = maxsessions_num;
printlen = snprintf (replybuffer,(outbufend-replybuffer), "Success setting maxsessions to %d\n", maxsessions_num);
ADJUSTLEN(printlen,outbufend,replybuffer);
}
return;
}
static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) {

@ -72,7 +72,7 @@ static int timeout;
static int silent_timeout;
static int port_min = 30000;
static int port_max = 40000;
static int max_sessions = 0;
static int max_sessions = -1;
static u_int32_t redis_ip;
static u_int16_t redis_port;
static int redis_db = -1;
@ -530,6 +530,9 @@ no_kernel:
mc.interfaces = &interfaces;
mc.port_min = port_min;
mc.port_max = port_max;
if (max_sessions < -1) {
max_sessions = -1;
}
mc.max_sessions = max_sessions;
mc.timeout = timeout;
mc.silent_timeout = silent_timeout;

@ -248,6 +248,7 @@ INLINE int str_to_i(str *s, int def) {
char c, *ep;
long ret;
int maxint = 0x7FFFFFFF;
int minint = 0x80000000;
if (s->len <= 0)
return def;
c = s->s[s->len];
@ -258,6 +259,8 @@ INLINE int str_to_i(str *s, int def) {
return def;
if (ret > maxint)
return def;
if (ret < minint)
return def;
return ret;
}

Loading…
Cancel
Save