Indeed, I should have mentioned that alarm doesn't work on Windows. This is brought up in the perlfaq that I mentioned, and I thought about mentioning it, but for some reason never did.

As for your comment about avoiding things "that are not cross-platform," I agree and disagree. In this case, using socket options to set a timeout is clearly the better option. I think so not just because it's cross-platform, but also because it's a mechanism already there. I see writing one's own timeout when a builtin timeout is supplied is reinventing the wheel.

I think we should be careful about being cross-platform to a fault, though. If one was trying to make a timeout for a system call that didn't have its own way of doing so, I would recommend using alarm. Always aiming for complete portability is, in my mind, somewhat akin to premature optimization. If something can be written much cleaner, simpler, and better with an unportable method, then I wouldn't immediately frown on it. Just as in the case of optimizing things before an actual performance problem is encountered, I think it's bad to make things highly portable before the need to do so is encountered.

That's not to say I wouldn't choose the portable method with all other things being equal, but portability often requires a bit of hoop-jumping that can be a problem. Just like most decisions of this nature, there is a balance that needs to be considered. Making a statement that you "try to avoid things that are not cross-platform" is a generalization that gets bandied about a lot, and while it is a noble goal, isn't always practical.


In reply to Re: Re: Re: Making Timeout for Yourself by revdiablo
in thread Making Timeout for Yourself by mcogan1966

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.