/[cwmp]/google/trunk/lib/CWMP/Session.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 /google/trunk/lib/CWMP/Session.pm

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

google/lib/CWMP/Server.pm revision 77 by dpavlin, Fri Jun 22 13:09:08 2007 UTC google/lib/CWMP/Session.pm revision 84 by dpavlin, Fri Jun 22 18:25:24 2007 UTC
# Line 1  Line 1 
1  # Dobrica Pavlinusic, <dpavlin@rot13.org> 06/18/07 10:19:50 CEST  # Dobrica Pavlinusic, <dpavlin@rot13.org> 06/18/07 10:19:50 CEST
2  package CWMP::Server;  package CWMP::Session;
3    
4  use strict;  use strict;
5  use warnings;  use warnings;
# Line 7  use warnings; Line 7  use warnings;
7  use base qw/Class::Accessor/;  use base qw/Class::Accessor/;
8  __PACKAGE__->mk_accessors( qw/  __PACKAGE__->mk_accessors( qw/
9  debug  debug
 port  
10  store_path  store_path
11    
12  sock  sock
# Line 26  use CWMP::Store; Line 25  use CWMP::Store;
25    
26  =head1 NAME  =head1 NAME
27    
28  CWMP::Server - implement logic of CWMP protocol  CWMP::Session - implement logic of CWMP protocol
29    
30  =head1 METHODS  =head1 METHODS
31    
32  =head2 new  =head2 new
33    
34    my $server = CWMP::Server->new({    my $server = CWMP::Session->new({
35          port => 3333,          sock => $io_socket_object,
36          store_path => 'state.db',          store_path => 'state.db',
37            queue => [ qw/GetRPCMethods GetParameterNames/ ],
38          debug => 1,          debug => 1,
39    });    });
40    
 =head2 run  
   
   $server->run();  
41    
42  =cut  =cut
43    
44  sub run {  sub new {
45          my $self = shift;          my $class = shift;
46            my $self = $class->SUPER::new( @_ );
47    
48          my $listen = IO::Socket::INET->new(          confess "need sock" unless $self->sock;
                 Listen    => 5,  
 #               LocalAddr => 'localhost',  
                 LocalPort => $self->port,  
                 Proto     => 'tcp',  
                 Blocking  => 1,  
                 ReuseAddr => 1,  
         );  
   
         warn "ACS waiting for request on port ", $self->port,  
                 $self->queue ? " queue ( " . join(",",@{$self->queue}) . " )" : "",  
                 "\n";  
49    
50          $self->debug( 0 ) unless $self->debug;          $self->debug( 0 ) unless $self->debug;
51          warn "## debug level: ", $self->debug, "\n" if $self->debug;  
52            warn "created ", __PACKAGE__, "(", dump( @_ ), ") for ", $self->sock->peerhost, "\n" if $self->debug;
53    
54          $self->store( CWMP::Store->new({          $self->store( CWMP::Store->new({
55                  debug => $self->debug,                  debug => $self->debug,
56                  path => $self->store_path,                  path => $self->store_path,
57          }) );          }) );
         croak "can't open ", $self->store_path, ": $!" unless $self->store;  
58    
59          while ( my $sock = $listen->accept ) {          croak "can't open ", $self->store_path, ": $!" unless $self->store;
                 $sock->autoflush(1);  
   
                 warn "connection from ", $sock->peerhost, "\n" if $self->debug;  
   
                 $self->sock( $sock );   # FIXME this will not work for multiple clients  
                 while ( $self->process_request ) {  
                         warn "...another one bites the dust...\n";  
                 }  
60    
61                  warn "...returning to accepting new connections\n";          return $self;
         }  
62  }  }
63    
64  =head2 process_request  =head2 process_request
# Line 96  sub process_request { Line 74  sub process_request {
74    
75          my $sock = $self->sock || die "no sock?";          my $sock = $self->sock || die "no sock?";
76    
77          die "not IO::Socket::INET but ", ref( $sock ) unless ( ref($sock) eq 'IO::Socket::INET' );          die "not IO::Socket::INET but ", ref( $sock ) unless ( ref($sock) eq 'Net::Server::Proto::TCP' );
78    
79          if ( ! $sock->connected ) {          if ( ! $sock->connected ) {
80                  warn "SOCKET NOT CONNECTED\n";                  warn "SOCKET NOT CONNECTED\n";
# Line 181  sub process_request { Line 159  sub process_request {
159                          warn "## acquired state = ", dump( $state ), "\n";                          warn "## acquired state = ", dump( $state ), "\n";
160    
161                          $self->state( $state );                          $self->state( $state );
162                            $self->store->update_state( $state->{ID} => $state );
163    
164                  } else {                  } else {
165                          warn "## empty request\n";                          warn "## empty request\n";

Legend:
Removed from v.77  
changed lines
  Added in v.84

  ViewVC Help
Powered by ViewVC 1.1.26