Commit 6beb6831 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(parse_unparsed): Return immediately if the session became blocked by DNS.

(dns_resolution): Schedule an idle check, as a client may have
	become unblocked.  Don't call isc_enable() here.  Instead, add
	the session to the run-queue.  There may be pending input in
	the input buffer.  Handle ADNS errors.
(login_request): Check the return value of isc_resolve_remote().
(read_from_connection): Return if the session is blocked by DNS.
parent 463d031c
/*
* $Id: connections.c,v 0.115 2003/08/05 09:51:36 ceder Exp $
* $Id: connections.c,v 0.116 2003/08/06 06:59:13 ceder Exp $
* Copyright (C) 1991-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -49,6 +49,7 @@
#include <assert.h>
#include <netdb.h>
#include "adns.h"
#include "oop.h"
#include "unused.h"
......@@ -136,6 +137,9 @@ static isc_stale_output_cb idle_cb;
static Connection *queue_first = NULL;
static Connection *queue_last = NULL;
static void busy(void);
static void
queue_add(Connection *c)
{
......@@ -438,6 +442,8 @@ parse_unparsed(Connection *client)
case 0 :
/* Parse message. If message is complete call function and reply. */
parse_packet(client);
if (client->blocked_by_dns)
return TRUE;
update_stat(STAT_REQUESTS, 1);
status = call_function(client, &result);
update_stat(STAT_REQUESTS, -1);
......@@ -684,6 +690,8 @@ dns_resolution(struct isc_scb *scb,
Connection *conn;
char *hostname = NULL;
busy();
update_stat(STAT_DNS_QUEUE, -1);
conn = scb->udg;
......@@ -691,10 +699,9 @@ dns_resolution(struct isc_scb *scb,
conn->dns_done = TRUE;
if (conn->blocked_by_dns)
{
if (isc_enable(scb) < 0)
restart_kom("Failed to enble session after DNS resolution.\n");
conn->blocked_by_dns = FALSE;
if (!conn->on_queue)
queue_add(conn);
}
if (res == isc_resolve_aborted)
......@@ -723,6 +730,14 @@ dns_resolution(struct isc_scb *scb,
errcode, hostname);
}
if (res == isc_resolve_adns_error)
{
if (hostname == NULL)
hostname = s_crea_c_str(scb->remote);
kom_log("Error looking up %s: %s\n", hostname, adns_strerror(errcode));
}
if (diff > param.dns_log_threshold)
{
if (hostname == NULL)
......@@ -808,11 +823,8 @@ login_request(struct isc_scb *session)
remote_ip = s_crea_c_str(cp->remote_ip);
/* Initiate DNS lookup. */
if (param.use_dns)
{
if (param.use_dns && isc_resolve_remote(session, dns_resolution) == 0)
update_stat(STAT_DNS_QUEUE, 1);
isc_resolve_remote(session, dns_resolution);
}
else
s_strcpy(&session->remote, cp->remote_ip);
......@@ -879,18 +891,18 @@ read_from_connection(Connection *conn)
adjust_penalty(conn);
while (!would_block && !go_and_die && conn->penalty < param.max_penalty
&& !conn->kill_pending)
&& !conn->kill_pending && !conn->blocked_by_dns)
{
pre = s_strlen(conn->unparsed) - conn->first_to_parse;
while (conn->more_to_parse
&& !go_and_die && conn->penalty < param.max_penalty
&& !conn->kill_pending)
&& !conn->kill_pending && !conn->blocked_by_dns)
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_pending)
|| conn->kill_pending || conn->blocked_by_dns)
break;
if (!conn->more_to_parse)
......@@ -935,7 +947,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)
if (conn->penalty >= param.max_penalty && !conn->blocked_by_dns)
{
/* isc_disable() will fail if we have received EPIPE on
this socket. In that case will soon close it, since
......@@ -1031,6 +1043,19 @@ saver_callback(oop_source *source,
}
static void
busy(void)
{
/* Something arrived, so we are busy. */
if (is_idle)
{
is_idle = FALSE;
enable_idle_check();
}
work_done = TRUE;
}
static void *
data_available_callback(oop_source *source,
int fd,
......@@ -1044,15 +1069,7 @@ data_available_callback(oop_source *source,
assert(isc_getoopsource(conn->isc_session) == source);
assert(conn->on_queue == FALSE);
/* Something arrived, so we are busy. */
if (is_idle)
{
is_idle = FALSE;
enable_idle_check();
}
work_done = TRUE;
busy();
set_time();
read_from_connection(conn);
......
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