You are viewing a plain text version of this content. The canonical link for it is here.
Posted to websh-user@tcl.apache.org by Mark Feeney <mf...@SANDVINE.com> on 2004/10/13 18:26:50 UTC

)RE: Detecting client disconnect

Hi Ronnie,

Thanks for mentioning ap_bwrite -- that lead me to find ap_bflush.  What I've done is added a custom option to the apache channel that Websh creates.  Setting this option causes ap_bflush to be called on the client buffer within Apache.  It might be cleaner to have a separate command (vs. using a channel option) to do this, but it was convenient to do as an option.

e.g.
fconfigure [web::request -channel] -flush_apache

It would be nice if tcl's flush command could somehow do this when called on the apache channel, but it wasn't immediately obvious to me how that would be done.  The channel interface doesn't seem to know anything about flushes.

For future reference, a bit more about what I've learned:

After the client disconnects, it takes a couple of writes and ap_bflush() calls before Apache realizes that the client is really gone.  Once it does, the previously mentioned r->connection->aborted flag becomes true.  SIGPIPE is generated as well, so if you have Tclx and its 'signal trap' stuff, you can just handle SIGPIPE and not even worry about the aborted flag.  In fact, you technically don't even need the -flush_apache hack above, you can just write tonnes of output to ensure the buffer is automatically flushed on a regular basis.  I prefer to write a single "\0" and manually flush though :)

Thanks again for your help thus far, Ronnie.


Mark.

-----Original Message-----
From: Ronnie Brunner [mailto:ronnie@netcetera.ch]
Sent: Wednesday, October 13, 2004 3:34 AM
To: Mark Feeney
Cc: websh-user@tcl.apache.org
Subject: Re: Detecting client disconnect


Hi

> The 'apache' channel that Websh creates appears to buffer output
> before sending it off to the client.  Is there a way to change the
> buffer size for the apache channel (or better yet, disable it)?  I
> tried 'fconfigure [web::request -channel] -buffering none', but it
> didn't seem to have an effect.

Yes, the 'apache' channel is created so writing back to the client is
the same a writing to any other Tcl channel.

Internally we use (as you might have seen) ap_rwrite, which again uses
buffer_output in Apache 2.0.X and ap_bwrite in Apache 1.3.X . I'm not
really familiar with that code, and on first sight I don't see how to
influence buffering there ... 

Ronnie
----------------------------------------------------------------------
Ronnie Brunner                             ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich   phone +41 1 247 79 79 fax +41 1 247 70 75

---------------------------------------------------------------------
To unsubscribe, e-mail: websh-user-unsubscribe@tcl.apache.org
For additional commands, e-mail: websh-user-help@tcl.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: websh-user-unsubscribe@tcl.apache.org
For additional commands, e-mail: websh-user-help@tcl.apache.org


Re: Detecting client disconnect

Posted by Ronnie Brunner <ro...@netcetera.ch>.
Mark

Thanks for the info. 

> It would be nice if tcl's flush command could somehow do this when
> called on the apache channel, but it wasn't immediately obvious to
> me how that would be done.  The channel interface doesn't seem to
> know anything about flushes. 

BTW: as of Tcl 8.3.2 the Tcl_ChannelType is enhanced to support a
flsuh proc that could be implemented for the apache channel. However,
this needs even more looking into the depths of Tcl channels and their
implementation in Websh... ;-)

Regards
Ronnie
----------------------------------------------------------------------
Ronnie Brunner                             ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich   phone +41 1 247 79 79 fax +41 1 247 70 75

---------------------------------------------------------------------
To unsubscribe, e-mail: websh-user-unsubscribe@tcl.apache.org
For additional commands, e-mail: websh-user-help@tcl.apache.org


Re: )RE: Detecting client disconnect

Posted by "David N. Welton" <da...@dedasys.com>.
Ronnie Brunner <ro...@netcetera.ch> writes:

> > In Rivet, I just do a flush in the 'write' proc:
> 
> Yeah, that's definitly the simpler approach, although I kind of like
> the idea of supporting flush for the apache channel.

Sure... but... what is the usage case for someone needing one to
buffer and not the other?  Maybe Mark can provide some more input.
When working with the Apache/Tcl glue, I've found that it's sometimes
tricky to decide which system should take care of which job, but that
whichever you pick, go with it and try and reduce the other one, so
that things don't get mixed up and confused...

-- 
David N. Welton
Personal:                   http://www.dedasys.com/davidw/
Apache Tcl:                 http://tcl.apache.org/
Free Software:              http://www.dedasys.com/freesoftware/
Linux Incompatibility List: http://www.leenooks.com/

PS... well, the whole *point* is that we mix them up:-), but it's got
to be done by "areas of competency" I guess I should say, if that
makes sense.  My rule of thumb has always been to use the Tcl API
where possible, in the hope of making the system more portable to
other web servers.

---------------------------------------------------------------------
To unsubscribe, e-mail: websh-user-unsubscribe@tcl.apache.org
For additional commands, e-mail: websh-user-help@tcl.apache.org


Re: )RE: Detecting client disconnect

Posted by Ronnie Brunner <ro...@netcetera.ch>.
> In Rivet, I just do a flush in the 'write' proc:

Yeah, that's definitly the simpler approach, although I kind of like the
idea of supporting flush for the apache channel.

Ronnie
----------------------------------------------------------------------
Ronnie Brunner                             ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich   phone +41 1 247 79 79 fax +41 1 247 70 75

---------------------------------------------------------------------
To unsubscribe, e-mail: websh-user-unsubscribe@tcl.apache.org
For additional commands, e-mail: websh-user-help@tcl.apache.org


Re: )RE: Detecting client disconnect

Posted by "David N. Welton" <da...@dedasys.com>.
"Mark Feeney" <mf...@SANDVINE.com> writes:

> It would be nice if tcl's flush command could somehow do this when
> called on the apache channel, but it wasn't immediately obvious to
> me how that would be done.  The channel interface doesn't seem to
> know anything about flushes.

In Rivet, I just do a flush in the 'write' proc:

static int
outputproc(ClientData instancedata, CONST84 char *buf,
           int toWrite, int *errorCodePtr)
{
    rivet_server_conf *rsc = (rivet_server_conf *)instancedata;
    rivet_interp_globals *globals =
        Tcl_GetAssocData(rsc->server_interp, "rivet", NULL);

    TclWeb_PrintHeaders(globals->req);
    if (globals->req->content_sent == 0)
    {
        ap_rwrite(buf, toWrite, globals->r);
        ap_rflush(globals->r);
    }
    return toWrite;
}

and let Tcl take care of the buffering.

-- 
David N. Welton
Personal:                   http://www.dedasys.com/davidw/
Apache Tcl:                 http://tcl.apache.org/
Free Software:              http://www.dedasys.com/freesoftware/
Linux Incompatibility List: http://www.leenooks.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: websh-user-unsubscribe@tcl.apache.org
For additional commands, e-mail: websh-user-help@tcl.apache.org