I have a program that reads from a socket I created with IO::Socket::INET. Most of the time, I want the calls to sysread and $sock->accept() to block. But just one time I need to check if I've received anything over the socket. If there is nothing there, I don't want it to block forever, I want it to move on. In Windows, I think the only way to get a non-blocking socket is to use the ioctl function like:
my $true = 1; ioctl($sock,0x8004667e,\$true);
I found this lovely gem on this site and it's worked well. My first thought to solve my problem was to make my socket non-blocking with ioctl, read from it, then change it back to blocking with a similar ioctl call. Unfortunately, this doesn't work. I tried setting $true to 0, -1, and undef and all have the same effect, they make the socket non-blocking. So my question is this: Is there any way to reverse the non-blockingness caused by an ioctl call? I have tried other methods (like an alarm), but these don't work in Windows. When perl is blocked in a sysread, I can't get it to catch sig int or sig alrm. Please help!

In reply to ioctl for non-blocking and blocking in Windows by Anonymous Monk

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.