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

(isc_create): Initialize stale_output_cb_registered and stale_output_cb.

(stale_cb): New static function.
(isc_set_read_callback): New argument: stale_output_cb.
(isc_cancel_stale_output_callback): New static function.
(isc_check_read_callback): New argument: any_written.  All callers
	updated.  Handle a timer callback used to detect if a client
	has stalled.
parent 3792949e
......@@ -50,12 +50,15 @@
#include "oop.h"
#include "s-string.h"
#include "timeval-util.h"
#include "isc.h"
#include "intern.h"
#include "unused.h"
static oop_call_time stale_cb;
/*
** Insert a session into a master control structure
*/
......@@ -178,8 +181,10 @@ isc_create(struct isc_mcb *mcb,
scb->wr_msg_q = NULL;
scb->accept_cb= NULL;
scb->write_cb_registered = 0;
scb->stale_output_cb_registered = 0;
scb->data_available_registered = 0;
scb->data_available_callback = NULL;
scb->stale_output_cb = NULL;
scb->data_available_user = NULL;
scb->cfg = cfg;
......@@ -192,10 +197,24 @@ isc_create(struct isc_mcb *mcb,
return scb;
}
static void *
stale_cb(oop_source *UNUSED(src),
struct timeval UNUSED(tv),
void *user)
{
struct isc_scb_internal *scb = user;
scb->stale_output_cb_registered = 0;
scb->stale_output_cb(scb->pub.master, &scb->pub, scb->data_available_user);
return OOP_CONTINUE;
}
void
isc_set_read_callback(struct isc_scb *scb,
oop_call_fd *data_available_callback,
isc_write_error_cb *write_error_cb,
isc_stale_output_cb *stale_output_cb,
void *user)
{
struct isc_scb_internal *session = (struct isc_scb_internal*)scb;
......@@ -205,25 +224,43 @@ isc_set_read_callback(struct isc_scb *scb,
session->data_available_callback = data_available_callback;
session->data_available_user = user;
session->write_err_cb = write_error_cb;
isc_check_read_callback(session);
session->stale_output_cb = stale_output_cb;
isc_check_read_callback(session, 0);
}
static void
isc_cancel_stale_output_callback(struct isc_scb_internal *session)
{
oop_source *source = session->pub.master->event_source;
if (session->stale_output_cb_registered)
{
source->cancel_time(source, session->stale_output_tv, stale_cb, session);
session->stale_output_cb_registered = 0;
}
}
void
isc_check_read_callback(struct isc_scb_internal *session)
isc_check_read_callback(struct isc_scb_internal *session,
int any_written)
{
oop_source *source = session->pub.master->event_source;
int wanted = 1;
int want_read = 1;
int want_write_timeout = 0;
/* Too many queued blocks? Don't read any more data, until
the client has read the output we have already produced. */
if (isc_sizequeue(session->wr_msg_q) >= session->cfg->max.queuedsize)
wanted = 0;
{
want_read = 0;
want_write_timeout = 1;
}
if (session->state == ISC_STATE_DISABLED)
wanted = 0;
want_read = 0;
if (!wanted)
if (!want_read)
isc_cancel_read_callback(session);
else if (!session->data_available_registered
&& session->data_available_callback != NULL)
......@@ -233,6 +270,19 @@ isc_check_read_callback(struct isc_scb_internal *session)
session->data_available_user);
session->data_available_registered = 1;
}
if (any_written || !want_write_timeout)
isc_cancel_stale_output_callback(session);
if (want_write_timeout
&& !session->stale_output_cb_registered
&& session->stale_output_cb != NULL)
{
setup_timer(&session->stale_output_tv,
session->pub.master->scfg->stale_timeout);
source->on_time(source, session->stale_output_tv, stale_cb, session);
session->stale_output_cb_registered = 1;
}
}
void
......@@ -330,7 +380,7 @@ int isc_disable(struct isc_scb *scb)
return -1;
sci->state = ISC_STATE_DISABLED;
isc_check_read_callback(sci);
isc_check_read_callback(sci, 0);
return 0;
}
......@@ -344,7 +394,7 @@ int isc_enable(struct isc_scb *scb)
return -1;
sci->state = ISC_STATE_RUNNING;
isc_check_read_callback(sci);
isc_check_read_callback(sci, 0);
return 0;
}
......
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