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 |
32 |
=head2 new |
=head2 new |
33 |
|
|
34 |
my $server = CWMP::Session->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; |
warn "created ", __PACKAGE__, "(", dump( @_ ), ") for ", $self->sock->peerhost, "\n" if $self->debug; |
|
warn "## debug level: ", $self->debug, "\n" if $self->debug; |
|
51 |
|
|
52 |
$self->store( CWMP::Store->new({ |
$self->store( CWMP::Store->new({ |
53 |
debug => $self->debug, |
debug => $self->debug, |
54 |
path => $self->store_path, |
path => $self->store_path, |
55 |
}) ); |
}) ); |
|
croak "can't open ", $self->store_path, ": $!" unless $self->store; |
|
|
|
|
|
while ( my $sock = $listen->accept ) { |
|
|
$sock->autoflush(1); |
|
56 |
|
|
57 |
warn "connection from ", $sock->peerhost, "\n" if $self->debug; |
croak "can't open ", $self->store_path, ": $!" unless $self->store; |
|
|
|
|
$self->sock( $sock ); # FIXME this will not work for multiple clients |
|
|
while ( $self->process_request ) { |
|
|
warn "...another one bites the dust...\n"; |
|
|
} |
|
58 |
|
|
59 |
warn "...returning to accepting new connections\n"; |
return $self; |
|
} |
|
60 |
} |
} |
61 |
|
|
62 |
=head2 process_request |
=head2 process_request |