Log error before croaking and include port# in the error message

This commit is contained in:
Isaac Connor 2016-02-19 11:04:02 -05:00
parent 327a01cb20
commit 64c5b64068
1 changed files with 15 additions and 6 deletions

View File

@ -61,12 +61,21 @@ sub open
{ {
my $self = shift; my $self = shift;
local *sfh; local *sfh;
my $saddr = sockaddr_in( $self->{port}, INADDR_ANY ); if ( ! socket( *sfh, PF_INET, SOCK_STREAM, getprotobyname('tcp') ) ) {
socket( *sfh, PF_INET, SOCK_STREAM, getprotobyname('tcp') ) Error( "Can't open socket: $!" );
or croak( "Can't open socket: $!" ); croak( "Can't open socket: $!" );
}
setsockopt( *sfh, SOL_SOCKET, SO_REUSEADDR, 1 ); setsockopt( *sfh, SOL_SOCKET, SO_REUSEADDR, 1 );
bind( *sfh, $saddr ) or croak( "Can't bind: $!" );
listen( *sfh, SOMAXCONN ) or croak( "Can't listen: $!" ); my $saddr = sockaddr_in( $self->{port}, INADDR_ANY );
if ( ! bind( *sfh, $saddr ) ) {
Error( "Can't bind to port $$self{port}: $!" );
croak( "Can't bind to port $$self{port}: $!" );
}
if ( ! listen( *sfh, SOMAXCONN ) ) {
Error( "Can't listen: $!" );
croak( "Can't listen: $!" );
}
$self->{state} = 'open'; $self->{state} = 'open';
$self->{handle} = *sfh; $self->{handle} = *sfh;
} }
@ -95,7 +104,7 @@ __END__
=head1 NAME =head1 NAME
ZoneMinder::Database - Perl extension for blah blah blah ZoneMinder::Trigger::Channel::Inet
=head1 SYNOPSIS =head1 SYNOPSIS