<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    I don't think I would call it a "race condition", but if the
    IO::Socket dies for some other reason before the timeout, you
    wouldn't want the alarm to still be pending.<br>
    <br>
      - Brian<br>
    <br>
    On 2011-07-06 10:01, Sean Blanton wrote:
    <blockquote
cite="mid:CAD0pDW7H4Ypns3NGzYBeH3UdNpKRDpbFJ2ypdFV0DNO284uQpw@mail.gmail.com"
      type="cite">
      <div>Below is some sample code I came across in its entirety. I'm
        looking for some clarification.</div>
      <div><br>
      </div>
      <div>There is a comment on the first statement after the eval,
        "race condition protection". What exactly is the race condition
        its referring to?</div>
      <div><br>
      </div>
      <div>
        <meta http-equiv="content-type" content="text/html;
          charset=ISO-8859-1">
        <div>#------------------------</div>
      </div>
      <div><br>
      </div>
      <div>eval { </div>
      <blockquote class="webkit-indent-blockquote" style="margin: 0 0 0
        40px; border: none; padding: 0px;">
        <div>local $SIG{ALRM} = sub { die 'Timed Out'; }; </div>
        <div>alarm 3; </div>
        <div>my $sock = IO::Socket::INET->new( </div>
      </blockquote>
      <blockquote class="webkit-indent-blockquote" style="margin: 0 0 0
        40px; border: none; padding: 0px;">
        <blockquote class="webkit-indent-blockquote" style="margin: 0 0
          0 40px; border: none; padding: 0px;">
          <div>PeerAddr => inet_ntoa( gethostbyname($host) ), </div>
        </blockquote>
        <blockquote class="webkit-indent-blockquote" style="margin: 0 0
          0 40px; border: none; padding: 0px;">
          <div>PeerPort => 'whois', </div>
        </blockquote>
        <blockquote class="webkit-indent-blockquote" style="margin: 0 0
          0 40px; border: none; padding: 0px;">
          <div>Proto => 'tcp', </div>
        </blockquote>
        <blockquote class="webkit-indent-blockquote" style="margin: 0 0
          0 40px; border: none; padding: 0px;">
          <div>## Timeout => , </div>
        </blockquote>
      </blockquote>
      <blockquote class="webkit-indent-blockquote" style="margin: 0 0 0
        40px; border: none; padding: 0px;">
        <div>); </div>
        <div><br>
        </div>
        <div>$sock->autoflush; </div>
        <div>
          print $sock "$qry\015\012"; </div>
        <div>undef $/; $data = <$sock>; $/ = "\n"; </div>
        <div>alarm 0; </div>
      </blockquote>
      <div>}; </div>
      <div><br>
      </div>
      <div>alarm 0; # race condition protection  <<<*********</div>
      <div><br>
      </div>
      <div>return "Error: Timeout." if ( $@ && $@ =~ /Timed Out/
        ); </div>
      <div>return "Error: Eval corrupted: $@" if $@;</div>
      <div><br>
      </div>
      <div>#------------------------</div>
      <div><br>
      </div>
      Thanks,<br>
      Sean<br>
      <br>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Chicago-talk mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a>
<a class="moz-txt-link-freetext" href="http://mail.pm.org/mailman/listinfo/chicago-talk">http://mail.pm.org/mailman/listinfo/chicago-talk</a></pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Brian Katzung, Kappa Computer Solutions, LLC
Leveraging UNIX, GNU/Linux, open source, and custom
software solutions for business and beyond
Phone: 877.367.8837 x1  <a class="moz-txt-link-freetext" href="http://www.kappacs.com">http://www.kappacs.com</a></pre>
  </body>
</html>