Hi monks
i have a forking server that is accepting connections, writing a log and then closing
The proble i have is that sometimes, the client does not send data
and this is keeping the connection open,
is there some way that i can close the connection say after 2 min if there is no data sent?
below is a snippet of what i currently have
while(my $connection = $server->accept){
my $name = $connection->peerhost;
my $port = $connection->peerport;
if (my $pid = fork){
close $connection;
next; # on to the next connection
}else{
# child process - handle connection
print $connection "You're connected to the server!\n";
while (<$connection>){
use HTTP::Date;
my ($date, $time) = split(" ", HTTP::Date::time2iso());
my ($hour, $min) = split(":", $time);
open (my $log, '+>>',"../../home/freetrac/public_html/logs/$po
+rt $date.txt")
|| die "Couldn't open log.txt: $!";
print $log $_;
close $log;
exit(0);
}
$connection->shutdown(SHUT_RDWR);
exit;
}
}
Any help would be great
Thanks
K-
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.