Author: spadkins
Date: Fri Jul 10 05:59:28 2009
New Revision: 13035

Modified:
   p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm

Log:
added a storable option (poe_storable) to allow for communicating more than 
just a string value back and forth between parent and child processes

Modified: p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm        (original)
+++ p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm        Fri Jul 10 
05:59:28 2009
@@ -26,6 +26,7 @@
 use POE::Component::IKC::Server;
 use HTTP::Status qw/RC_OK/;
 use Socket qw(INADDR_ANY);
+use Storable qw(lock_store lock_retrieve);
 
 sub _init {
     &App::sub_entry if ($App::trace);
@@ -528,6 +529,7 @@
         my $event_token = $self->send_async_event_in_process($event, 
$callback_event);
     }
     else {
+        ### TODO: potentially use POE child processes instead
         my $pid = $self->fork();
         if (!$pid) {   # running in child
             my $exitval = 0;
@@ -539,13 +541,21 @@
                 @results = ($@);
             }
             if ($#results > -1 && defined $results[0] && $results[0] ne "") {
-                my $textfile = $self->{options}{prefix} . 
"/data/app/Context/$$";
-                if (open(FILE, "> $textfile")) {
-                    print App::Context::POE::Server::FILE @results;
-                    close(App::Context::POE::Server::FILE);
+                my $ipc_file = $self->{options}{prefix} . 
"/data/app/Context/$$";
+                ### Use Storable as IPC
+                if ($self->{options}{poe_storable_ipc}) {
+                    my $results = (@results == 1) ? $results[0] : \...@results;
+                    my $success = lock_store($results, $ipc_file);
                 }
+                ### Use a string value as IPC
                 else {
-                    $exitval = 1;
+                    if (open(FILE, "> $ipc_file")) {
+                            print App::Context::POE::Server::FILE @results;
+                            close(App::Context::POE::Server::FILE);
+                    }
+                    else {
+                        $exitval = 1;
+                    }
                 }
             }
             $self->shutdown();
@@ -614,13 +624,21 @@
     if ($async_event) {
         my ($event, $callback_event) = @$async_event;
         my $returnval = "";
-        my $returnvalfile = $self->{options}{prefix} . 
"/data/app/Context/$pid";
-        if (open(FILE, $returnvalfile)) {
-            if ($callback_event) {
-                $returnval = join("",<App::Context::POE::Server::FILE>);
+        my $ipc_file = $self->{options}{prefix} . "/data/app/Context/$pid";
+        ### Use Storable as IPC
+        if ($self->{options}{poe_storable_ipc}) {
+            $returnval = lock_retrieve($ipc_file);
+            unlink($ipc_file);
+        }
+        ### Use a string value as IPC
+        else {
+            if (open(FILE, $ipc_file)) {
+                if ($callback_event) {
+                    $returnval = join("",<App::Context::POE::Server::FILE>);
+                }
+                close(App::Context::POE::Server::FILE);
+                unlink($ipc_file);
             }
-            close(App::Context::POE::Server::FILE);
-            unlink($returnvalfile);
         }
 
         my $destination = $event->{destination} || "local";
@@ -1160,8 +1178,8 @@
     my ($self, $kernel, $args) = @_[OBJECT, KERNEL, ARG0];
     $self->profile_start("poe_remote_async_event_finished") if 
$self->{poe_profile};
     $self->log({level=>3},"POE: poe_remote_async_event_finished enter\n") if 
$self->{poe_trace};
-    my ($runtime_event_token, $callback_args) = @$args;
 
+    my ($runtime_event_token, $callback_args) = @$args;
     my $async_event = $self->{running_async_event}{$runtime_event_token};
     if ($async_event) {
         my ($event, $callback_event) = @$async_event;

Reply via email to