Re: How to test if request has been aborted
On Sat, Jul 30, 2011 at 01:02, Tony Abo wrote: >> 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 >> 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); >> #undef CORE_PRIVATE >> >> > Thanks Sorin, that works. I found another approach, but I'm not sure how safe > it is. > > int CheckConnected(request_rec r) > { > int nSocket; > char acBuffer[1]; > int nResult; > core_net_rec *cnr = > pConnID->pRequestRecord->connection->output_filters->ctx; output_filters is a linked list of filters. I think that it cannot be guaranteed that the first filter in the linked list is the core output filter. Thus, one cannot guarantee that output_filters->ctx exists and that it is a core_net_rec. > > if ( apr_os_sock_get( &nSocket, cnr->client_socket ) != APR_SUCCESS ) > return FALSE; > nResult = recv( nSocket, acBuffer, 1, MSG_PEEK | MSG_DONTWAIT ); > return nResult > 0 || (nResult == -1 && errno == EWOULDBLOCK); > } > > Any thoughts? > >> > >> > Thanks again, >> > Tony >> > >> > > >
RE: How to test if request has been aborted
> 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 > 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); > #undef CORE_PRIVATE > > Thanks Sorin, that works. I found another approach, but I'm not sure how safe it is. int CheckConnected(request_rec r) { int nSocket; char acBuffer[1]; int nResult; core_net_rec *cnr = pConnID->pRequestRecord->connection->output_filters->ctx; if ( apr_os_sock_get( &nSocket, cnr->client_socket ) != APR_SUCCESS ) return FALSE; nResult = recv( nSocket, acBuffer, 1, MSG_PEEK | MSG_DONTWAIT ); return nResult > 0 || (nResult == -1 && errno == EWOULDBLOCK); } Any thoughts? > > > > Thanks again, > > Tony > > > >
Re: How to test if request has been aborted
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 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); #undef CORE_PRIVATE > > Thanks again, > Tony > >
RE: How to test if request has been aborted
> >> 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. Thanks again, Tony
Re: How to test if request has been aborted
Sent from my iPhone On 28/07/2011, at 7:18 PM, "Tom Evans" wrote: > On Thu, Jul 28, 2011 at 7:26 AM, ... > 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)?
Re: How to test if request has been aborted
On Thu, Jul 28, 2011 at 7:26 AM, Tony Abo wrote: > I am working on a custom request handler that works with Apache 2.x. There > are times that the request may take a considerable amount of time to process. > 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