httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sorin Manolache <>
Subject Re: How to test if request has been aborted
Date Fri, 29 Jul 2011 07:19:54 GMT
On Fri, Jul 29, 2011 at 02:35, Tony Abo <> wrote:
>> >>  I need to cut the processing short if the user decides to press the
>> >>stop button on the browser. I cant seem to figure out how to test for
>> >>that condition from inside the handler. Can anyone help me?
>> >>
>> >>
>> >> Thanks in advance,
>> >> Tony
>> >
>> > r->connection->aborted
>> >
>> > Cheers
>> >
>> > Tom
>> Thanks Tom
>> Will that value get updated asynchronously if the connection closes
>> while my handler does its processing (I.e without calling any Apache
>> functions)?
> My testing shows that connection->aborted is not being set asynchronously when the
connection is closed by the client. I need one of the following:
> - Some Apache function I can call that will attempt to touch the open socket and either
set connection->aborted or return an error status so I can know it is no longer connected.
> Or
> - Access to the actual socket buried somewhere in the connection structure. I can't seem
to find it. If I had that, I could test it myself.

The earliest hook that is passed the socket is create_connection. The
socket is passed in the third argument. Use apr_os_sock_get to get the
OS-specific socket descriptor.

If you do not place your own callback on the create_connection hook in
order to save the socket in your own structures, then you can use the
method below, but it's a hack, as I guess the core_module structure is
not supposed to be visible to modules. The method works after the
pre_connection hook.

#define CORE_PRIVATE 1
#include <http_core.h>
apr_socket_t *sock = (apr_socket_t
*)ap_get_module_config(r->connection->conn_config, &core_module);
apr_os_sock_t fd; // int for Unix
apr_os_sock_get(&fd, sock);

> Thanks again,
> Tony

View raw message