Use sysread and alarm to time out the client if necesary. The example below is pretty much straight from the alarm entry in perlfunc.
#!/usr/bin/perl -w use strict; use IO::Socket; my $server = IO::Socket::INET->new(LocalPort => 6969, Type => SOCK_STREAM, Proto => 'tcp', Reuse => 1, Listen => 10, ) or die "Can't create listener socket: $!\n"; while ( my $client = $server->accept() ) { my ($data, $buf); my $timeout = 10; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; while (sysread $client, $buf, 1024) { $data .= $buf; last if $data =~ /(?:\015?\012){2}/; # reset timeout if we read data alarm $timeout; } alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; } # do stuff with $data print ">>$data<<\n"; }
I imagine HTTP::Daemon would do all this stuff for you.

Of course, a line without the \015\012 (or at least \012) terminator isn't a valid HTTP request, so you shouldn't bother looking at it.


In reply to Re: about read HTTP header. by takshaka
in thread about read HTTP header. by iic

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.