Re: NetServer::Portal 1.04

[email protected] (Joshua N Pritikin)
Newsgroups perl.loop
Message-ID <[email protected]>
On Fri, Mar 10, 2000 at 09:38:54AM +0000, [email protected] wrote:
> Great I will take a look at this. I would have to look at the code
> to see I what I currently do still works, but you might want to
> think about adding this.
> 
> We have several daemons which have a command interface via a socket.
> I did not what to have to create a new socket for NetServer::ProcessTop 
> so I did this.

Oh!  No problem:

==== //depot/D/NetServer-Portal/lib/NetServer/Portal.pm#4 - /cache/D/NetServer-Portal/lib/NetServer/Portal.pm ====
--- /tmp/tmp.19802.0	Fri Mar 10 07:44:43 2000
+++ /cache/D/NetServer-Portal/lib/NetServer/Portal.pm	Fri Mar 10 07:44:16 2000
@@ -40,16 +40,31 @@
     require NetServer::Portal::Top;
     require NetServer::Portal::Pi;
     eval {
-	NetServer::Portal->start();
+	my $sock = NetServer::Portal->new_socket();
+	NetServer::Portal->start($sock);
 #	warn "Listening on ".(7000+($$%1000))."\n";
     };
     if ($@) { warn; return }
 }
 
-sub start {
+sub new_socket {
     my ($class, $port) = @_;
     $Port = $port || $BasePort + $$ % 1000;
     
+    # Mostly snarfed from perlipc example; thanks!
+    my $proto = getprotobyname('tcp');
+    my $sock = gensym;
+    socket($sock, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
+    setsockopt($sock, SOL_SOCKET, SO_REUSEADDR, pack('l', 1))
+	or die "setsockopt: $!";
+    bind($sock, sockaddr_in($Port, INADDR_ANY)) or die "bind: $!";
+    listen($sock, SOMAXCONN);
+    $sock;
+}
+
+sub start {
+    my ($class, $sock) = @_;
+    
     eval { $StoreTop = retrieve($StoreFile) };
     if ($@) {
 	if ($@ =~ /No such file/) {
@@ -64,15 +79,6 @@
 		    min => 15, max => 300, nice => 1, cb => sub {
 			store $StoreTop, $StoreFile;
 		    });
-
-    # Mostly snarfed from perlipc example; thanks!
-    my $proto = getprotobyname('tcp');
-    my $sock = gensym;
-    socket($sock, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
-    setsockopt($sock, SOL_SOCKET, SO_REUSEADDR, pack('l', 1))
-	or die "setsockopt: $!";
-    bind($sock, sockaddr_in($Port, INADDR_ANY)) or die "bind: $!";
-    listen($sock, SOMAXCONN);
 
     Event->io(fd => $sock, nice => NICE, cb => \&service_client,
 	      desc => "NetServer::Portal");

-- 
"Never ascribe to malice that which can be explained by stupidity."
                           via, but not speaking for Deutsche Bank
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.