Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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)?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(MeowChow) Re: porting this 'setnonblocking' subroutine to Windows
by MeowChow (Vicar) on Dec 30, 2001 at 00:55 UTC | |
by Anonymous Monk on Dec 30, 2001 at 20:54 UTC | |
by Veachian64 (Scribe) on Dec 31, 2001 at 02:46 UTC | |
by MeowChow (Vicar) on Dec 31, 2001 at 06:53 UTC | |
by tilly (Archbishop) on Jan 06, 2002 at 00:24 UTC | |
|
Re: porting this 'setnonblocking' subroutine to Windows
by chromatic (Archbishop) on Dec 29, 2001 at 23:50 UTC |