/[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 37 by dpavlin, Mon Jun 30 20:02:06 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  );  );
25  $server->debug_level( 2 );  $server->debug_level( 2 );
 sub run {  
26    
27    sub run {
28          $server->loop;          $server->loop;
29  }  }
30    
# Line 33  my $callback_count; Line 33  my $callback_count;
33    
34  sub gen_link {  sub gen_link {
35          my ($text, $code) = @_;          my ($text, $code) = @_;
36          $callbacks[$callback_count++] = $code;          $callbacks[$callback_count] = $code;
37          return qq{<a href="?cb=$callback_count">$text</a>};          my $out = qq{<a href="?cb=$callback_count">$text</a>};
38            $callback_count++;
39            return $out;
40  }  }
41    
42  sub process_links {  sub process_links {
# Line 42  sub process_links { Line 44  sub process_links {
44          my $cb = $request->param('cb');          my $cb = $request->param('cb');
45          if (exists $callbacks[$cb]) {          if (exists $callbacks[$cb]) {
46                  $callbacks[$cb]->($request);                  $callbacks[$cb]->($request);
47                  delete $callbacks[$cb];  #               delete $callbacks[$cb];
48          }          }
49  }  }
50    
# Line 50  sub process_links { Line 52  sub process_links {
52  # 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
53  # of these cases, none of which will return (they all loop forever).  # of these cases, none of which will return (they all loop forever).
54  sub main {  sub main {
55    my ($req) = @_;          my ($req) = @_;
56        
57    my $path = $req->request->url->path;          my $path = $req->request->url->path;
58    warn "REQUEST: $path\n";          warn "REQUEST: $path\n";
59    
60          warn $req->request->header('User_Agent');          warn $req->request->header('User_Agent');
61  #warn dump( $req );  #warn dump( $req );
62    
63    # If this is a request for the pushtream, then give them that          # If this is a request for the pushtream, then give them that
64    if($path =~ /pushstream/) {          if($path =~ /pushstream/) {
65          pushstream($req);                  pushstream($req);
66    }          }
67        
68    # 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
69    if($path =~ /sendmessage/) {          if($path =~ /sendmessage/) {
70          send_message($req);                  send_message($req);
71    }          }
72    
73            if ( $path =~ m/test/ ) {
74                    use Data::Dumper;
75                    $Data::Dumper::Deparse = 1;
76    
77                    my $x = 0;
78                    my $continue = 1;
79                    my $link1 = gen_link('+' => sub { $x++ });
80                    my $link2 = gen_link('-' => sub { $x-- });
81                    my $out = gen_link('X' => sub { $continue = 0 });
82                    while ( $continue ) {
83                            warn "## x = $x ",dump( $req->params );
84                            $req->print("\$x is now: $x");
85                            $req->print($link1, ' ', $link2, ' ', $out);
86                            $req->print('<pre>'.Dumper( @callbacks ).'</pre>');
87                            $req->next;
88                            process_links($req);
89                    }
90            }
91    
92    # Otherwise, lets give them page          # Otherwise, lets give them page
93    send_page($req);          send_page($req);
94  }  }
95    
96  # 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.37

  ViewVC Help
Powered by ViewVC 1.1.26