/[Frey]/trunk/lib/Frey/Server.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/Server.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 36 by dpavlin, Mon Jun 30 07:13:35 2008 UTC revision 42 by dpavlin, Mon Jun 30 20:02:16 2008 UTC
# Line 17  use vars qw( $repl $server ); Line 17  use vars qw( $repl $server );
17    
18  #$repl = Continuity::REPL->new;  #$repl = Continuity::REPL->new;
19  $server = Continuity->new(  $server = Continuity->new(
20    port => 16001,          port => 16001,
21    path_session => 1,          path_session => 1,
22    cookie_session => 'sid',          cookie_session => 'sid',
23    callback => \&main,          callback => \&main,
24            debug_level => 1,
25  );  );
 $server->debug_level( 2 );  
 sub run {  
26    
27    sub run {
28          $server->loop;          $server->loop;
29  }  }
30    
 my @callbacks;  
 my $callback_count;  
   
 sub gen_link {  
         my ($text, $code) = @_;  
         $callbacks[$callback_count++] = $code;  
         return qq{<a href="?cb=$callback_count">$text</a>};  
 }  
   
 sub process_links {  
         my $request = shift;  
         my $cb = $request->param('cb');  
         if (exists $callbacks[$cb]) {  
                 $callbacks[$cb]->($request);  
                 delete $callbacks[$cb];  
         }  
 }  
   
31  # This is the main entrypoint. We are looking for one of three things -- a  # This is the main entrypoint. We are looking for one of three things -- a
32  # pushstream, a sent message, or a request for the main HTML. We delegate each  # pushstream, a sent message, or a request for the main HTML. We delegate each
33  # of these cases, none of which will return (they all loop forever).  # of these cases, none of which will return (they all loop forever).
34  sub main {  sub main {
35    my ($req) = @_;          my ($req) = @_;
36        
37    my $path = $req->request->url->path;          my $path = $req->request->url->path;
38    warn "REQUEST: $path\n";          warn "REQUEST: $path\n";
39    
40          warn $req->request->header('User_Agent');          warn $req->request->header('User_Agent');
41  #warn dump( $req );  #warn dump( $req );
42    
43    # If this is a request for the pushtream, then give them that          # If this is a request for the pushtream, then give them that
44    if($path =~ /pushstream/) {          if($path =~ /pushstream/) {
45          pushstream($req);                  pushstream($req);
46    }          }
47        
48    # If they are sending us a message, we give them a thread for that too          # If they are sending us a message, we give them a thread for that too
49    if($path =~ /sendmessage/) {          if($path =~ /sendmessage/) {
50          send_message($req);                  send_message($req);
51    }          }
52    
53    # Otherwise, lets give them page          # Otherwise, lets give them page
54    send_page($req);          send_page($req);
55  }  }
56    
57  # Here we accept a connection to the browser, and keep it open. Meanwhile we  # Here we accept a connection to the browser, and keep it open. Meanwhile we

Legend:
Removed from v.36  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26