Skip Menu |

This queue is for tickets about the Net-Server CPAN distribution.

Report information
The Basics
Id: 18706
Status: resolved
Priority: 0/
Queue: Net-Server

People
Owner: Nobody in particular
Requestors: seeskokeed [...] hotmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.93
Fixed in: (no value)



Subject: check for port value is broken
One way: my $srv = bless{'port' => 11111}, 'R2D2'; $srv->run(); Other way: R2D2->run({port => 11111}); Yet the other way, using the configure_hook: #--------------------------------------------------------------------------- sub configure_hook { my $self = shift; my $root = $self->{server_root} = "/tmp"; $self->{server}->{port} = "11111"; # port and addr to bind $self->{server}->{user} = 'r2d2'; # user to run as $self->{server}->{group} = 'r2d2'; # group to run as $self->{server}->{setsid} = 1; # daemonize $self->{server}->{log_file} = "$root/server.log"; $self->{document_root} = "$root/www"; $self->{access_log} = "$root/access.log"; $self->{error_log} = "$root/error.log"; } Tried these things, but no luck, the default port is always used, see code below. The first check for defined is ok but the other two will break since $prop->{port} is just a scalar. Code fix or doc fix (probably both, but maybe not...) 295 ### set a default port, host, and proto 296 if( ! defined( $prop->{port} ) 297 || ! ref( $prop->{port} ) 298 || ! @{ $prop->{port} } ){ 299 $self->log(2,"Port Not Defined. Defaulting to '20203'\n"); 300 $prop->{port} = [ 20203 ]; 301 } 302 Linux localhost 2.6.12-10-686 #1 Sat Mar 11 16:22:51 UTC 2006 i686 GNU/Linux This is perl, v5.8.7 built for i486-linux-gnu-thread-multi
A quick note before any of the other explanations - Net::Server allows for you to bind to multiple hosts on multiple ports with multiple protocols (udp and tcp) - therefore, port is stored in the Net::Server object as an array. Show quoted text
> my $srv = bless{'port' => 11111}, 'R2D2'; > $srv->run();
If you are not using the new method, the correct way to do it is like this: my $srv = bless {server => {port => [11111]}}, 'R2D2'; Show quoted text
> Other way: > > R2D2->run({port => 11111});
Run does not take a hashref (prior to 0.94). The correct way to do that one is: R2D2->run(port => 11111); Show quoted text
> Yet the other way, using the configure_hook: > $self->{server}->{port} = "11111"; # port and addr to bind
If you are going to use the internals directly - you will need to treat the port as an arrayref like this: $self->{server}->{port} = ['11111']; Show quoted text
> Tried these things, but no luck, the default port is > always used, see code below. The first check > for defined is ok but the other two will break since > $prop->{port} is just a scalar. Code fix or doc fix > (probably both, but maybe not...)
The checks are all accurate. The configurations to this point aren't. Additionally you could do: R2D2->new({port => 11111})->run; R2D2->new({port => [11111]})->run; R2D2->run(port => 11111); It is sort of unfortunate that new takes a hashref while run takes a hash. I'll update 0.94 to let both run and new take a hash or a hashref. Paul