Re: send error with perl and unix domain sockets

2007-05-01 Thread Andy Greenwood

Sent this a while back and never got a response. Any ideas would be
very appreciated!

Thanks!

I'm working on getting a script to work (see below). It is a perl
daemon associated with a bittorent client that I am helping develop.
The daemon uses unix domain sockets to commincate with the php pages.
However, anytime a message is sent via php, the script dies with

send: Cannot determine peer address at
/usr/local/www/root/tf-b4rt/trunk/html/bin/fluxd/fluxd.pl line 1256

I did some reasearch and found a similar problem with OpenBSD's perl
http://www.nntp.perl.org/group/perl.perl5.porters/2007/02/msg121151.html

and tried to apply that fix to my own Socket.pm's. I modified these files
[EMAIL PROTECTED] p5-IO]$ locate Socket.pm
/usr/home/andy/.cpan/build/IO-1.2301/IO/Socket.pm
/usr/home/andy/.cpan/build/IO-1.2301/blib/lib/IO/Socket.pm
/usr/local/lib/perl5/5.8.8/mach/IO/Socket.pm
/usr/local/lib/perl5/5.8.8/mach/Socket.pm

and re-started my process, but no effect. the bug report above
suggests that this was a problem for OpenBSD due to differences in
struct sockaddr_un. Could that be a problem here as well?

the php code which communicates with the socket is below

-begin php--
   /**
* send command
*
* @param $command
* @param $read does this command return something ?
* @return string with retval or null if error
*/
   function instance_sendCommand($command, $read = 0) {
   if ($this-state == FLUXD_STATE_RUNNING) {
   // create socket
   $socket = -1;
   $socket = @socket_create(AF_UNIX, SOCK_STREAM, 0);
   if ($socket  0) {
   array_push($this-messages , socket_create() failed:
reason: [EMAIL PROTECTED]($socket));
   $this-state = FLUXD_STATE_ERROR;
   return null;
   }
   //timeout after n seconds
   @socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,
array('sec' = $this-_socketTimeout, 'usec' = 0));
   // connect
   $result = -1;
   $result = @socket_connect($socket, $this-_pathSocket);
   if ($result  0) {
   array_push($this-messages , socket_connect() failed:
reason: [EMAIL PROTECTED]($result));
   $this-state = FLUXD_STATE_ERROR;
   return null;
   }
   // write command
   @socket_write($socket, $command.\n);
   // read retval
   $return = ;
   if ($read != 0) {
   do {
   // read data
   $data = @socket_read($socket,
4096, PHP_BINARY_READ);
   $return .= $data;
   } while (isset($data)  ($data != ));
   }
   // close socket
   @socket_close($socket);
   // return
   return $return;
   } else { // fluxd not running
   return null;
   }
   }
-end php---

and the perl daemon's socket code is below

--begin perl--
sub checkConnections {
   # Get the readable handles. timeout is 0, only process stuff that can be
   # read NOW.
   my $return = ;
   my @ready = $select-can_read(0);
   foreach my $socket (@ready) {
   if ($socket == $server) {
  my $new = $socket-accept();
   $select-add($new);
   } else {
   my $buf = ;
   my $char = getc($socket);
   while ((defined($char))  ($char ne \n)) {
   $buf .= $char;
   $char = getc($socket);
   }
   $return = processRequest($buf);
   $socket-send($return);
   $select-remove($socket);
   close($socket);
   }
   }
}
-end perl--

I can provide the full text of the appropriate files on request or you
can view them at
http://svn.berlios.de/wsvn/tf-b4rt/trunk/?rev=0sc=0

perl-5.8.8
apache-2.2.4_2
php5-5.2.1_3
php5-gd-5.2.1_3
php5-pcre-5.2.1_5
php5-pgsql-5.2.1_3
php5-posix-5.2.1_3
php5-session-5.2.1_3
php5-simplexml-5.2.1_3
php5-sockets-5.2.1_3
php5-spl-5.2.1_3
php5-sqlite-5.2.1_3

FreeBSD zeus.agreenftp.no-ip.com 6.2-STABLE FreeBSD 6.2-STABLE #0: Sat
Mar 31 23:12:40 EDT 2007
[EMAIL PROTECTED]:/usr/obj/usr/src/sys/ZEUS  i386

--
--
I'm nerdy in the extreme and whiter than sour cream
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: send error with perl and unix domain sockets

2007-05-01 Thread Theorem

Andy Greenwood wrote:

Sent this a while back and never got a response. Any ideas would be
very appreciated!


Because it's too long, I don't know what you're asking and it's also perl/php, 
not FreeBSD.



I'm working on getting a script to work (see below). It is a perl
daemon associated with a bittorent client that I am helping develop.
The daemon uses unix domain sockets to commincate with the php pages.
However, anytime a message is sent via php, the script dies with

send: Cannot determine peer address at
/usr/local/www/root/tf-b4rt/trunk/html/bin/fluxd/fluxd.pl line 1256

I did some research and found a similar problem with OpenBSD's perl
http://www.nntp.perl.org/group/perl.perl5.porters/2007/02/msg121151.html


Yes, but aren't you having a problem with php ?

*SNIP*

 the bug report above
suggests that this was a problem for OpenBSD due to differences in
struct sockaddr_un. Could that be a problem here as well?


try :  EFNet #perlhep   or freenode #perl or #perlhelp  Unfortunately I can't 
find a decent perl mailing list for you.  Also look on line 1256.


But If you're really asking a php question try #php in either location.   Might 
I suggest rewriting it in perl instead ?


*SNIP END*
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]