Last active
November 7, 2015 18:35
-
-
Save nabe-abk/ab944576eb8bebcfcfb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# Nonblocking io for perl/socket (PDS) | |
################################################################################ | |
sub set_block { | |
my $sock = shift; | |
return &set_nonblock($sock, 1); | |
} | |
sub set_nonblock { | |
my $sock = shift; | |
my $block = shift; | |
if ($^O eq 'MSWin32') { | |
my $f = 0x8004667e; # FIONBIO for windows | |
my $v = pack("L", $block ? 0 : 1); | |
ioctl($sock, $f, $v); | |
return; | |
} | |
my $flags = fcntl($sock, F_GETFL, 0); | |
if ($block) { | |
$flags &= ~O_NONBLOCK; | |
} else { | |
$flags |= O_NONBLOCK; | |
} | |
fcntl($sock, F_SETFL, $flags); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment