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

(parse_unparsed) [DEBUG_CALLS]: Don't process any request if the

	client is disabled by disable_client.
(may_read_more): New method, extracted from read_from_connection.
	Return false if disabled by disable_client.
(should_be_disabled): New method, extracted from read_from_connection
	and check_idle_callback. Return true if disabled by
	disable_client.
(read_from_connection): Simplified code by using may_read_more and
	should_be_disabled.
(check_idle_callback): Simplified code by using should_be_disabled.
(disable_client): New debug request.
parent 948f5993
......@@ -448,6 +448,10 @@ parse_unparsed(Connection *client)
parse_packet(client);
if (client->blocked_by_dns)
return TRUE;
#ifdef DEBUG_CALLS
if (client->blocked_by_disable_client)
return TRUE;
#endif
update_stat(STAT_REQUESTS, 1);
status = call_function(client, &result);
update_stat(STAT_REQUESTS, -1);
......@@ -930,6 +934,35 @@ adjust_penalty(Connection *conn)
}
static Bool
may_read_more(Connection *conn)
{
if (go_and_die)
return FALSE;
if (conn->penalty >= param.max_penalty)
return FALSE;
if (conn->kill_status != ks_none)
return FALSE;
if (conn->blocked_by_dns)
return FALSE;
#ifdef DEBUG_CALLS
if (conn->blocked_by_disable_client == 1)
return FALSE;
#endif
return TRUE;
}
static Bool
should_be_disabled(Connection *conn)
{
#ifdef DEBUG_CALLS
if (conn->blocked_by_disable_client == 1)
return TRUE;
#endif
return conn->penalty >= param.max_penalty && !conn->blocked_by_dns;
}
static void
read_from_connection(Connection *conn)
{
......@@ -939,19 +972,15 @@ read_from_connection(Connection *conn)
adjust_penalty(conn);
while (!would_block && !go_and_die && conn->penalty < param.max_penalty
&& conn->kill_status == ks_none && !conn->blocked_by_dns)
while (!would_block && may_read_more(conn))
{
pre = s_strlen(conn->unparsed) - conn->first_to_parse;
while (conn->more_to_parse
&& !go_and_die && conn->penalty < param.max_penalty
&& conn->kill_status == ks_none && !conn->blocked_by_dns)
while (conn->more_to_parse && may_read_more(conn))
need_flush |= parse_unparsed(conn);
update_stat(STAT_RECV_QUEUE,
s_strlen(conn->unparsed) - conn->first_to_parse - pre);
if (go_and_die || conn->penalty >= param.max_penalty
|| conn->kill_status != ks_none || conn->blocked_by_dns)
if (!may_read_more(conn))
break;
if (!conn->more_to_parse)
......@@ -996,7 +1025,7 @@ read_from_connection(Connection *conn)
restart_kom("parse_unparsed: s_trim_left\n");
conn->first_to_parse = 0;
if (conn->penalty >= param.max_penalty && !conn->blocked_by_dns)
if (should_be_disabled(conn))
{
/* isc_disable() will fail if we have received EPIPE on
this socket. In that case will soon close it, since
......@@ -1040,7 +1069,7 @@ check_idle_callback(oop_source *UNUSED(source),
c = next;
next = next->queue_next;
adjust_penalty(c);
if (c->penalty < param.low_penalty)
if (!should_be_disabled(c))
{
queue_remove(c);
......@@ -1308,3 +1337,35 @@ set_scheduling(Session_no session_no,
return OK;
}
#ifdef DEBUG_CALLS
Success
disable_client(Session_no session_no,
int state)
{
Connection *cptr;
CHK_CONNECTION(FAILURE);
if (state != 0 && state != 1)
{
kom_errno = KOM_BAD_BOOL;
err_stat = 0;
return FAILURE;
}
if (session_no != 0 && session_no != active_connection->session_no)
CHK_LOGIN(FAILURE);
if ((cptr = get_conn_by_number(session_no)) == NULL
|| !handshake_ok(cptr, 0))
{
kom_errno = KOM_UNDEF_SESSION;
err_stat = session_no;
return FAILURE;
}
cptr->blocked_by_disable_client = state;
return OK;
}
#endif
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