From owner-freebsd-questions@FreeBSD.ORG Tue May 1 15:05:38 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 73B6A16A410 for ; Tue, 1 May 2007 15:05:38 +0000 (UTC) (envelope-from greenwood.andy@gmail.com) Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.183]) by mx1.freebsd.org (Postfix) with ESMTP id 3336013C4BA for ; Tue, 1 May 2007 15:05:37 +0000 (UTC) (envelope-from greenwood.andy@gmail.com) Received: by py-out-1112.google.com with SMTP id f31so1617451pyh for ; Tue, 01 May 2007 08:05:37 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=iGkfxtorLGV27vqzlP4hiw878JfYtrojNJrZ77xexcjCd+dPyOD/q6zExuBN6Qg2rrKL6pnQQZF2ntty0UjBX4tjrmtISdy0SKdLnb7NTCWRfa3isPNh7C053DTthv4PKqvkQqFV2lz9otzXSd+uf4+29lYH11u5QIh8JWa5k04= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=L7rKt9d8woU9KwMA1pLHB/uS9XKe2+pAnYxPhlYHSSzZsA4ROCC8pOKbU16/29rNoN72JBlXwRU3RghZznOG4w6WoS967NYzThpFxzKFTh8QKgq42/BadfULVlc171/OmknN5uVwvmF+j+jydyXPjdZTT8C5q/XzEKP5/yeKNaU= Received: by 10.64.27.13 with SMTP id a13mr13876491qba.1178031936575; Tue, 01 May 2007 08:05:36 -0700 (PDT) Received: by 10.64.24.7 with HTTP; Tue, 1 May 2007 08:05:36 -0700 (PDT) Message-ID: <3ee9ca710705010805n47ea5fc9o89e7440d349a62a@mail.gmail.com> Date: Tue, 1 May 2007 11:05:36 -0400 From: "Andy Greenwood" To: "FreeBSD Questions" In-Reply-To: <3ee9ca710704121230j519cce16ic0009d07d33bae5b@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <3ee9ca710704121230j519cce16ic0009d07d33bae5b@mail.gmail.com> Subject: Re: send error with perl and unix domain sockets X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 May 2007 15:05:38 -0000 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 [andy@zeus 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: ".@socket_strerror($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: ".@socket_strerror($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=0&sc=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 toor@zeus.agreenftp.no-ip.com:/usr/obj/usr/src/sys/ZEUS i386 -- -- I'm nerdy in the extreme and whiter than sour cream