From owner-freebsd-questions@FreeBSD.ORG Thu Apr 12 19:30:52 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 0EE3816A402 for ; Thu, 12 Apr 2007 19:30:52 +0000 (UTC) (envelope-from greenwood.andy@gmail.com) Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.180]) by mx1.freebsd.org (Postfix) with ESMTP id C4FEA13C4B7 for ; Thu, 12 Apr 2007 19:30:51 +0000 (UTC) (envelope-from greenwood.andy@gmail.com) Received: by py-out-1112.google.com with SMTP id f31so530719pyh for ; Thu, 12 Apr 2007 12:30:51 -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:mime-version:content-type:content-transfer-encoding:content-disposition; b=a9z70ao9FJ8bZ1MdfUy/OTvAfasAmLSYb+F9Mh1jC/Ujf5wZSCrILle23rij95N1GEB/DgWay697ReXWN1WlJFAvZB1y4RJAx3XS2cxRCXsSF7H2FU0perR9JmVSPnw+CnsLzH2UOzkyXCffvYSgoIEhzS/jaaM5Ttkap4b1p48= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=YYvJn6JjYjedBZthsoYqBLHHa2v6OBw9LCXq7T/p4bibHtynIxMMZupgKxyR75PFpji8Pkq0hu4FK7llNTTuqguwnBrN7qxPm0jt2Odkbf0qx/BYtZelaigy1/0Fy5mpzq3RNIiBBMn/bs4gKgXsFJI39X0ej0yt2dZ3XTEk8Pc= Received: by 10.64.148.8 with SMTP id v8mr4564269qbd.1176406250046; Thu, 12 Apr 2007 12:30:50 -0700 (PDT) Received: by 10.64.47.18 with HTTP; Thu, 12 Apr 2007 12:30:49 -0700 (PDT) Message-ID: <3ee9ca710704121230j519cce16ic0009d07d33bae5b@mail.gmail.com> Date: Thu, 12 Apr 2007 15:30:49 -0400 From: "Andy Greenwood" To: "FreeBSD Questions" MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: 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: Thu, 12 Apr 2007 19:30:52 -0000 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