Re: How to access client socket from a protocol handler
On Fri, 22 Oct 2010 23:54:17 +0200 Ben Noordhuis wrote: > On Fri, Oct 22, 2010 at 23:08, Alexander Farber > wrote: > > Unfortunately there aren't many example for the protocol handlers > > on the web or in Nick's book. I've come up with the following, > > but don't know how to get the client socket via conn_rec? > > apr_socket_t *client = ap_get_module_config(conn->conn_config, &core_module); > > But note that in most cases direct socket I/O is a bad idea. I use that to get the socket so I can poll for it to have data in it, and do other things while I'm waiting. Is there a better alternative for that, or is this an exception? http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
Bad file descriptor: apr_socket_accept: (client socket) on graceful-stop
Hi, I am new to this group, so please be gentle :) Recently, I installed apache 2.2.3 on a Crux 2.1 (Linux Kernel 2.6.11.7). Now, every time I do an apachectl graceful or apachectl graceful-stop I get "[error] (9)Bad file descriptor: apr_socket_accept: (client socket)" in the apache error log file. I am running: libapreq2-2.08 mod_perl-2.0.2 apache 2.2.3 Compiled in modules: core.c mod_authn_file.c mod_authn_default.c mod_authz_host.c mod_authz_groupfile.c mod_authz_user.c mod_authz_default.c mod_auth_basic.c mod_file_cache.c mod_cache.c mod_disk_cache.c mod_filter.c mod_deflate.c mod_log_config.c mod_env.c mod_headers.c mod_setenvif.c mod_proxy.c mod_proxy_http.c mod_proxy_ajp.c mod_proxy_balancer.c mod_ssl.c prefork.c http_core.c mod_mime.c mod_status.c mod_actions.c mod_alias.c mod_so.c I searched in Google could not find anything. I posted a message on the apache users group, but got no response. Anyone have any ideas what causes this error, and what can I do to prevent it? Thanks, Tal -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.408 / Virus Database: 268.13.2/472 - Release Date: 10/11/2006
Re: Client socket
On Thu, May 30, 2002 at 03:00:21PM +0530, Vinod Panicker wrote: > I feel like kicking myself! Forgot all that I had learnt abt sockets! > > What I actually wanted was the ability to use the socket from another > process. I obviously cant do that in this case since the socket that > has been opened is local to the process (DUH!) > > Now I want to pass this socket to another application, which can write > to it when required. I'm sitting with stevens right now, hunting for > ways in which I can pass open file descriptors to another process :) > > Any help would be welcome. Unix domain sockets can be used to pass file descriptors, as can doors and stream pipes (see Advanced Programming in the Unix Environment, by W. Richard Stevens, Chapter 15, p. 475 for the domain sockets/stream pipes). Others and I have been working on adding this functionality to APR so that it will be available across unix platforms as well as Windows and others, FWIW. -aaron
RE: Client socket
I feel like kicking myself! Forgot all that I had learnt abt sockets! What I actually wanted was the ability to use the socket from another process. I obviously cant do that in this case since the socket that has been opened is local to the process (DUH!) Now I want to pass this socket to another application, which can write to it when required. I'm sitting with stevens right now, hunting for ways in which I can pass open file descriptors to another process :) Any help would be welcome. I don't require the input filters, since I want to write to the socket of a keep-alive connection later. Was just wondering if I can do it in a simple way, or I'll have to use libnet to do it Tx, Vinod. --- Vinod Panicker <[EMAIL PROTECTED]> Sr. Software Designer Geodesic Information Systems Ltd. -Original Message- From: Sander Striker [mailto:[EMAIL PROTECTED]] Sent: Thursday, May 30, 2002 2:54 PM To: [EMAIL PROTECTED]; Vinod Panicker Subject: RE: Client socket > From: Tony Finch [mailto:[EMAIL PROTECTED]]On Behalf Of > 'Tony Finch' > Sent: 30 May 2002 11:01 > On Thu, May 30, 2002 at 11:03:05AM +0530, Vinod Panicker wrote: > > > > I need the actual socket that apache uses to communicate with the > > client in the php module. Is it available somewhere in the > > request_rec structure? > > You've already found it in r->connection->client->fd. Question: why do you need the socket? Staying away from the socket is in general a better idea. You get all the data through the input filters, bypassing those means you lose out on a lot of functionality. Sander
RE: Client socket
> From: Tony Finch [mailto:[EMAIL PROTECTED]]On Behalf Of 'Tony > Finch' > Sent: 30 May 2002 11:01 > On Thu, May 30, 2002 at 11:03:05AM +0530, Vinod Panicker wrote: > > > > I need the actual socket that apache uses to communicate with the client > > in the php module. Is it available somewhere in the request_rec > > structure? > > You've already found it in r->connection->client->fd. Question: why do you need the socket? Staying away from the socket is in general a better idea. You get all the data through the input filters, bypassing those means you lose out on a lot of functionality. Sander
Re: Client socket
On Thu, May 30, 2002 at 11:03:05AM +0530, Vinod Panicker wrote: > > I need the actual socket that apache uses to communicate with the client > in the php module. Is it available somewhere in the request_rec > structure? You've already found it in r->connection->client->fd. Tony. -- f.a.n.finch <[EMAIL PROTECTED]> http://dotat.at/ SOUTH FITZROY: NORTH OR NORTHEAST 4 OR 5, OCCASIONALLY 6 NEAR CAPE FINISTERRE. FAIR. GOOD.
RE: Client socket
Tx a million for your reply. I need the actual socket that apache uses to communicate with the client in the php module. Is it available somewhere in the request_rec structure? I've been trying to get this for ages now. Tx, Vinod. --- Vinod Panicker <[EMAIL PROTECTED]> Sr. Software Designer Geodesic Information Systems Ltd. -Original Message- From: Tony Finch [mailto:[EMAIL PROTECTED]] On Behalf Of Tony Finch Sent: Wednesday, May 29, 2002 9:33 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Client socket On Wed, May 29, 2002 at 04:27:59PM +0530, Vinod Panicker wrote: > > This script I call from the browser, and everytime it displays a '3'. > I even called it from different browser windows, still the same. > > That cant be alright since if the fd is 3 as shown in one browser > window, it has to be something different in the other window since the > browser defaults to a keep-alive connection, and the fd's have to be > different. Each connection is handled in a different process and each process's fd 3 is different. If a process fork()s two children and each child accept()s a connection they will each receive a different connection but it will be allocated the same fd number in each child. Tony. -- f.a.n.finch <[EMAIL PROTECTED]> http://dotat.at/ CROMARTY: SOUTHEASTERLY VEERING SOUTHWESTERLY 5 OR 6, DECREASING 4. RAIN THEN SHOWERS. MODERATE BECOMING GOOD.
Re: Client socket
On Wed, May 29, 2002 at 04:27:59PM +0530, Vinod Panicker wrote: > > This script I call from the browser, and everytime it displays a '3'. I > even called it from different browser windows, still the same. > > That cant be alright since if the fd is 3 as shown in one browser > window, it has to be something different in the other window since the > browser defaults to a keep-alive connection, and the fd's have to be > different. Each connection is handled in a different process and each process's fd 3 is different. If a process fork()s two children and each child accept()s a connection they will each receive a different connection but it will be allocated the same fd number in each child. Tony. -- f.a.n.finch <[EMAIL PROTECTED]> http://dotat.at/ CROMARTY: SOUTHEASTERLY VEERING SOUTHWESTERLY 5 OR 6, DECREASING 4. RAIN THEN SHOWERS. MODERATE BECOMING GOOD.
RE: Client socket
Hi Jeff, Thanks for your reply... Let me explain what exactly I did. I made changes to the php_apache.c file and added a new php function of my own, which is supposed to return the client socket when called from a php script. Here is the code for the function - --- /* {{{ proto int apache_client_socket() Get the client socket */ PHP_FUNCTION(apache_client_socket) { RETURN_LONG(((request_rec *)SG(server_context))->connection->client->fd); } --- I recompiled php and made a module out of it. Worked perfectly. Now, I wrote a php script with the following code - --- --- This script I call from the browser, and everytime it displays a '3'. I even called it from different browser windows, still the same. That cant be alright since if the fd is 3 as shown in one browser window, it has to be something different in the other window since the browser defaults to a keep-alive connection, and the fd's have to be different. I'll would tell you why I need the socket, but I've described it so many times that I'm gonna die :( I'll forward you a mail if you are really interested. Tx, Vinod. --- Vinod Panicker <[EMAIL PROTECTED]> Sr. Software Designer Geodesic Information Systems Ltd. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Jeff Trawick Sent: Wednesday, May 29, 2002 4:19 PM To: [EMAIL PROTECTED] Subject: Re: Client socket "Vinod Panicker" <[EMAIL PROTECTED]> writes: > Hi, > > Where is the client socket fd stored in the request_rec structure? > > Is it either of the r->connection->client->fd or the > r->connection->client->fd_in variables? > > I tried accessing the values, but both the variables show the value > '3' for every request passed to the php module. Why is 3 incorrect? Did you do lsof on your httpd process while stopped in the debugger to verify that 3 is (or is not) the connection to the client? Why do you need access to the socket? -- Jeff Trawick | [EMAIL PROTECTED] Born in Roswell... married an alien...
Re: Client socket
"Vinod Panicker" <[EMAIL PROTECTED]> writes: > Hi, > > Where is the client socket fd stored in the request_rec structure? > > Is it either of the r->connection->client->fd or the > r->connection->client->fd_in variables? > > I tried accessing the values, but both the variables show the value '3' > for every request passed to the php module. Why is 3 incorrect? Did you do lsof on your httpd process while stopped in the debugger to verify that 3 is (or is not) the connection to the client? Why do you need access to the socket? -- Jeff Trawick | [EMAIL PROTECTED] Born in Roswell... married an alien...
Client socket
Hi, Where is the client socket fd stored in the request_rec structure? Is it either of the r->connection->client->fd or the r->connection->client->fd_in variables? I tried accessing the values, but both the variables show the value '3' for every request passed to the php module. Tx, Vinod. --- Vinod Panicker <[EMAIL PROTECTED]> Sr. Software Designer Geodesic Information Systems Ltd.