I'm trying to port a Unix Perl IRC daemon (Pircd) to Windows 2000 (Active Perl 5.6).

I think maybe the only thing that I cannot handle is this thing about setting the socket (of a new client connection) to 'non-blocking'.

The orginal code refers to a setnonblocking() subroutine. See below.

foreach $client ($select->can_read(1)) { if($serversocks{$client}) { # Activity on the listening socket means we have a new # client attempting to connect. # Get ahold of the new socket, assign it to all the whatnot, etc $client = $client->accept; $select->add($client); &setnonblocking($client); # <--- SEE HERE $connections{$client} = Connection->new($client, \%outbuffer, $U +tils::thisserver); $unfinished{$client} = $connections{$client}; }

The problem is that the setnonblocking() subroutine uses some functions that are not available on Windows 2000 (namely F_GETFL and F_SETFL). Here is the subroutine.

sub setnonblocking { my $sock = shift; # Get the current state of the socket.. my $flags = fcntl($sock, F_GETFL, 0) or die "Can't get the flags on socket: $!\n"; # ..and then add O_NONBLOCK (nonblocking-ness) on to it. fcntl($sock, F_SETFL, $flags | O_NONBLOCK) or die "Can't set socket non-blocking: $!\n"; }

So the big question is:

How can I rewrite this subroutine so that it will work on Windows 2000 and accomplish the same purpose (set the socket to be non-blocking)?


In reply to porting this 'setnonblocking' subroutine to 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.