httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bronto <>
Subject Re: dropping a connection abruptly
Date Tue, 24 Oct 2006 15:52:35 GMT
Hello experts,
I think i can give you some point to go to with this socket thing. We 
are on project, where we have to get the socket descriptor out of the 
apache thus we can use it with external libraries. In one time I've 
found myself with grep and apache sources, google and a lot of coffee ;)
We are on Linux (64 bit architecture).
here's how to get socket from apache in module:

static int my_post_read_request(request_rec *r)
    conn_rec *conn = r->connection;
    apr_socket_t *csd = ((core_net_rec 
    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "mod_my_download: 
client socket file descriptor: %d",csd->socketdes);
    return OK;

static void my_register_hooks(apr_pool_t *p)

ap_hook_post_read_request(my_post_read_request, NULL, NULL, 


module AP_MODULE_DECLARE_DATA my_download_module =

so in my_post_read_request(..) you will have csd->socketdes at one 
point. This is fully functional socket descriptor. I really believe this 
is not the way apache team would like mod developers to play with 
sockets...I believe they don't want it at all (i guess, that's the point 
of storing apr_socket as (void) pointer in input_filters->ctx :) ). If 
you know any cleaner (better), way how to do this, I would appreciate 
any comments.
I'll be glad, if this helps.

Anyway, why i got interested in your mail Roy. You mention there some 
approach to mark a connection as aborted. If one _marks_ a connection as 
aborted, will:
  - apache close this connection right after return from module ?
      - if yes, is there a way to preserve this socket?
  - apache send anything to the (appropriate) socket (connection)?

In general, I want to read headers and check the URL. If it's in certain 
namespace, I would like to:
  - tell apache to forget about this connection (mark as aborted?)
  - pass socket from this connection to 'worker' (my own thread inside 
apache, which will know what to do)
  - return from module, and rely on apache to let this connection as is 
(no data, no further read() from socket, no other modules touch it etc.)

If I'm confusing about something, reply please and I will 
extend(explain) my thoughts.

Best regards,

On Oct 23, 2006, at 2:22 PM, Brian McQueen wrote:
> This is sounding good.  How do I gain the level of control that you
> are describing here?  The request_rec has a conn_rec, but I don't see
> how to get beyond that.  If I've successfully read 4096 bytes, how do
> I then stop any further transactions on the socket?  I don't know how
> to grab the socket in order to close it!

There is a (at least one) way to mark the connection as aborted
after the read.  I'd explain, but have too much on my plate right
now (flight to switzerland in the morning).  Search for "aborted"
in the code and see what others do.


View raw message