#!/usr/bin/perl -w use IO::Socket; use IO::Select; use Fcntl; $s = IO::Socket::UNIX->new; socket($s, PF_UNIX, SOCK_STREAM, 0) or print $!; $sel = IO::Select->new; $sel->add($s); non_block($s); fcntl($s, F_GETFL, 0); connect($s, sockaddr_un("/tmp/sock")) or print $!; if ($sel->can_write(0)) { print "can_write\n"; } sleep 1; if ($sel->can_write(0)) { print "can_write\n"; } sub non_block { my $handle = shift; my $flags; $flags = fcntl($handle, F_GETFL, 0) and fcntl($handle, F_SETFL, $flags | O_NONBLOCK) or die "non_block: $!"; }