Commit aea3feb4 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(login_request): Set the priority and weight from

	param.default_priority and param.default_weight.
(adjust_penalty): Use the weight to reduce the penalty.
(get_scheduling): Return the actual scheduling information from
	the connection.
(set_scheduling): Check the priority and weight against
	param.max_priority and param.max_weight.  Allow the user to
	change them, as long as it is done within those limits.  Store
	the new values in the connection.  Note: the current
	implementation cannot handle more than one priority.  The
	check for that is made in server-config.c.
parent dd421bcc
/*
* $Id: connections.c,v 0.121 2003/08/14 17:08:34 ceder Exp $
* $Id: connections.c,v 0.122 2003/08/14 23:02:02 ceder Exp $
* Copyright (C) 1991-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -856,6 +856,9 @@ login_request(struct isc_scb *session)
cp->penalty = param.max_penalty;
cp->penalty_generation = penalty_generation;
cp->schedule.priority = param.default_priority;
cp->schedule.weight = param.default_weight;
/* Get the real user name, as returned by the Ident protocol (rfc 931). */
realuser = get_real_username(session, remote_ip);
if (realuser == NULL && param.authentication_level == 2)
......@@ -884,13 +887,25 @@ login_request(struct isc_scb *session)
static void
adjust_penalty(Connection *conn)
{
while (penalty_generation - conn->penalty_generation > 0)
unsigned int gens = penalty_generation - conn->penalty_generation;
if (gens > 0)
{
conn->penalty /= 2;
if (conn->penalty == 0)
conn->penalty_generation = penalty_generation;
/* The weight is in the range 1-0xffff (inclusive).
The penalty is in the range 0-0x10000 (inclusive).
This means that the multiplication can never overflow. */
if (conn->penalty <= gens)
conn->penalty = 0;
else
conn->penalty_generation++;
{
unsigned int tmp = conn->penalty - gens * conn->schedule.weight;
if (tmp < conn->penalty)
conn->penalty = tmp;
else
conn->penalty = 0;
}
conn->penalty_generation = penalty_generation;
}
}
......@@ -1182,8 +1197,7 @@ get_scheduling(Session_no session_no,
return FAILURE;
}
result->priority = 0;
result->weight = 1;
*result = cptr->schedule;
return OK;
}
......@@ -1245,10 +1259,10 @@ set_scheduling(Session_no session_no,
return FAILURE;
}
if (priority > 0)
if (priority > param.max_priority)
{
kom_errno = KOM_INDEX_OUT_OF_RANGE;
err_stat = 0;
err_stat = param.max_priority;
return FAILURE;
}
......@@ -1262,12 +1276,15 @@ set_scheduling(Session_no session_no,
}
#endif
if (weight > 1)
if (weight > param.max_weight)
{
kom_errno = KOM_WEIGHT_DENIED;
err_stat = 1;
err_stat = param.max_weight;
return FAILURE;
}
cptr->schedule.priority = priority;
cptr->schedule.weight = weight;
return OK;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment