Hello,
Im trying to write a server which accepts any number of strings which will processed and an answer will be sent.
the string I get has a header which contains the length of the string so I should know how much data I will get.
now Id like to have a timeout if no data was sent in a specific time.....eg when the length is higher than the sent string.
thats how I tried it. but the string could be like 10MB in the worst case and it doesnt make sense to increase the timeout just to be able to read the biggest possible string.
I also tried to part data_length in 10kb parts and read it part for part......but for some reason it stops reading after a few loops....no idea why. all I need is a timeout which starts counting as soon as no data is sent anymore. :) btw Im using Net::Server::PreFork and this snipplet is part of my process_request{} hook
eval { local $SIG{ALRM} = sub { die "timeout" }; my $prev_alarm = alarm($prop->{timeout}); while( $data_length = readheader()){ $data = ""; alarm($prop->{timeout}); read STDIN, $data, $data_length, 0; alarm($prop->{timeout}); $modul_result = $modul_handle->process_xml($data); send_response($modul_result); } alarm($prev_alarm); }; if( $@ =~ /^timeout/ ){ $self->log(4, "Connection timed out.\n"); }
Thanks! :)

In reply to how can I timeout a function like "read" when reading from a socket by Goatee

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.