You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Tyler MacDonald <ty...@yi.org> on 2006/05/11 22:05:24 UTC

How to get at the apr_socket_t?

Hello,

	I'm working on a raw tcp/ip handler which is going to have to do
nonblocking I/O. I'd like to get direct access to the apr_socket_t from the
request_rec/conn_rec... I've been poking around the documentation, and I
can't find a reference to an apr_socket_t anywhere in that namespace! Is
there some magic I need to do to get at the actual file descriptor for the
open TCP connection?

	Thanks,
		Tyler

Re: How to get at the apr_socket_t?

Posted by Tyler MacDonald <ty...@yi.org>.
William A. Rowe, Jr. <wr...@rowe-clan.net> wrote:
> >    ap_get_module_config(r->connection->conn_config, &core_module);
> >But that is only avaialable if CORE_PRIVATE is defined... Does that mean my
> >module needs to define CORE_PRIVATE in order to get access to an
> >apr_socket_t? That seems dirty to me... is there some better way?
> In httpd 2.0 there's no assurance that httpd is even accessed by a socket,
> so of course you are rolling the dice.  For example, in mod_perchild, the
> backend is a domain socket to another instance of Apache.  In mod_ftp you
> would see the data socket, not the control socket, etc.  It's private for
> a reason, if you know what you are doing, declare CORE_PRIVATE and use it.

	Okay, fair enough. I think I know what I'm doing, so I'll go ahead
with it. :-)

Davi Arnaut <da...@haxent.com.br> wrote:
> How about: conn_rec->cs->pfd->desc ?

	So what exactly is that, William? Is that the same socket, the main
listening socket that httpd accept()s on, or something else?

	Thanks,
		Tyler


Re: How to get at the apr_socket_t?

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Tyler MacDonald wrote:
> Tyler MacDonald <ty...@yi.org> wrote:
> 
>>	I'm working on a raw tcp/ip handler which is going to have to do
>>nonblocking I/O. I'd like to get direct access to the apr_socket_t from the
>>request_rec/conn_rec...
> 
> OK, I found this in mod_proxy:
> 
>     apr_socket_t *client_socket = ap_get_module_config(r->connection->conn_config, &core_module);
> 
> But that is only avaialable if CORE_PRIVATE is defined... Does that mean my
> module needs to define CORE_PRIVATE in order to get access to an
> apr_socket_t? That seems dirty to me... is there some better way?

In httpd 2.0 there's no assurance that httpd is even accessed by a socket,
so of course you are rolling the dice.  For example, in mod_perchild, the
backend is a domain socket to another instance of Apache.  In mod_ftp you
would see the data socket, not the control socket, etc.  It's private for
a reason, if you know what you are doing, declare CORE_PRIVATE and use it.

Bill

Re: How to get at the apr_socket_t?

Posted by Tyler MacDonald <ty...@yi.org>.
Davi Arnaut <da...@haxent.com.br> wrote:
> >     apr_socket_t *client_socket = ap_get_module_config(r->connection->conn_config, &core_module);
> > 
> > But that is only avaialable if CORE_PRIVATE is defined... Does that mean my
> > module needs to define CORE_PRIVATE in order to get access to an
> > apr_socket_t? That seems dirty to me... is there some better way?
> How about: conn_rec->cs->pfd->desc ?

	That definately is better... so long as that's the right file
descriptor. :-) I guess that would make me ask the question, why is
mod_proxy not doing it that way?

	Thanks,
		Tyler

Re: How to get at the apr_socket_t?

Posted by Davi Arnaut <da...@haxent.com.br>.
On Thu, 11 May 2006 13:36:44 -0700
Tyler MacDonald <ty...@yi.org> wrote:

> Tyler MacDonald <ty...@yi.org> wrote:
> > 	I'm working on a raw tcp/ip handler which is going to have to do
> > nonblocking I/O. I'd like to get direct access to the apr_socket_t from the
> > request_rec/conn_rec...
> 
> OK, I found this in mod_proxy:
> 
>     apr_socket_t *client_socket = ap_get_module_config(r->connection->conn_config, &core_module);
> 
> But that is only avaialable if CORE_PRIVATE is defined... Does that mean my
> module needs to define CORE_PRIVATE in order to get access to an
> apr_socket_t? That seems dirty to me... is there some better way?
> 

How about: conn_rec->cs->pfd->desc ?

--
Davi Arnaut

Re: How to get at the apr_socket_t?

Posted by Tyler MacDonald <ty...@yi.org>.
Tyler MacDonald <ty...@yi.org> wrote:
> 	I'm working on a raw tcp/ip handler which is going to have to do
> nonblocking I/O. I'd like to get direct access to the apr_socket_t from the
> request_rec/conn_rec...

OK, I found this in mod_proxy:

    apr_socket_t *client_socket = ap_get_module_config(r->connection->conn_config, &core_module);

But that is only avaialable if CORE_PRIVATE is defined... Does that mean my
module needs to define CORE_PRIVATE in order to get access to an
apr_socket_t? That seems dirty to me... is there some better way?

		- Tyler