Mihai
Mihai

Reputation: 29

HTTP::Daemon and debug error codes

How can I debug error codes when the daemon itself can not be initialized:

my $d = HTTP::Daemon->new(LocalAddr=>$ae::Settings{ip},
                       LocalPort=>$ae::Settings{port},
                       ReuseAddr=>'1') || die "error";

What I would like is more specific error codes instead of a simple 'die'. For example if I can't bind to certain ports, etc.

Upvotes: 1

Views: 108

Answers (2)

G. Cito
G. Cito

Reputation: 6388

If I'm not root and I run this against a privileged ( < 1024 ) port or against a higher port that is already in use:

#!perl
# HTTP_daemon.pl 

use HTTP::Daemon;      
use warnings;      
my $d = HTTP::Daemon->new(LocalAddr=>"127.0.0.1", 
                       LocalPort=>"88",     
                       ReuseAddr=>'1') || die "$!";

I get:

Permission denied at HTTP_daemon.pl line 4.

For errors and status codes related to HTTP use HTTP::Status.

Upvotes: 0

Steffen Ullrich
Steffen Ullrich

Reputation: 123561

You can just check $! (i.e. the errno from the underlying system call) for problems while initializing the underlying socket. And more than creating the listener is not done inside HTTP::Daemon::new

HTTP::Daemon->new(...) or die "error: $!"

Upvotes: 1

Related Questions