Hello!
I am trying to understand the best way to tell if a socket connection read operation has timed out. I have include snippets of a much bigger program to best explain my delema.
Do i have to test for an empty array or will the program exit with an error status? or something else all together.
fyi $CONF is a configuration file holding values for the program.
### Open a server socket and await incoming connections.
### The IO::Socket::INET module is used instead of theSocket
### module to simplify the code.
my $sockfd = IO::Socket::INET->new(LocalPort => $CONF:
ort,
Type => SOCK_STREAM,
Reuse => 1,
Listen => SOMAXCONN)
or die ("MAIN FATAL: Could not open TCP socket on port $CONF:
ort: $@\n"
;
### Await incoming connections
CONNECTION:
while (my $connfd = $sockfd->accept())
{
### Fork a child process
if ((my $chldpid = fork()) != 0)
{
###This is the parent. Close the connected socket
###and await the next client connection.
close ($connfd);
next CONNECTION;
}
### The child will close listening socket.
close ($sockfd);
### Use select to place a time out on socket reads
my $select = IO::Select->new();
$select->add($connfd);
my @read_from = $select->can_read($CONF::timeout);
$connfd = $read_from[0];
### What happens here if the connection times out
### Do i have to test for something?
(etc...)
}
I am trying to understand the best way to tell if a socket connection read operation has timed out. I have include snippets of a much bigger program to best explain my delema.
Do i have to test for an empty array or will the program exit with an error status? or something else all together.
fyi $CONF is a configuration file holding values for the program.
### Open a server socket and await incoming connections.
### The IO::Socket::INET module is used instead of theSocket
### module to simplify the code.
my $sockfd = IO::Socket::INET->new(LocalPort => $CONF:
Type => SOCK_STREAM,
Reuse => 1,
Listen => SOMAXCONN)
or die ("MAIN FATAL: Could not open TCP socket on port $CONF:
### Await incoming connections
CONNECTION:
while (my $connfd = $sockfd->accept())
{
### Fork a child process
if ((my $chldpid = fork()) != 0)
{
###This is the parent. Close the connected socket
###and await the next client connection.
close ($connfd);
next CONNECTION;
}
### The child will close listening socket.
close ($sockfd);
### Use select to place a time out on socket reads
my $select = IO::Select->new();
$select->add($connfd);
my @read_from = $select->can_read($CONF::timeout);
$connfd = $read_from[0];
### What happens here if the connection times out
### Do i have to test for something?
(etc...)
}