I discovered that you can actually do non-blocking connects without patching the Perl source, and fairly portably too, so long as you set up a few OS-dependant constants and subs. Here's some code I wrote a while back for just this purpose. If you ask nicely, you might just coax an explanation out of me too (that is, after I've figured out how it works again :-)
package Portable::NonBlock; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK); require Exporter; use POSIX; use Socket; use Symbol; @EXPORT = qw(); @EXPORT_OK = qw(setnonblock FIONBIO EAGAIN); @ISA = qw(Exporter); ### Default ### *setsocknonblock = sub { my $sock = shift; my $flags = fcntl($sock, F_GETFL, 0) or warn "Can't get the fcntl flags on socket: $!\n"; fcntl($sock, F_SETFL, $flags | O_NONBLOCK) or warn "Can't fcntl socket to non-blocking: $!\n"; }; ### Win32 ### sub SO_OPENTYPE { 0x7008 } if ($^O eq 'MSWin32') { *POSIX::FIONBIO = sub { 0x8004667E }; # Gleaned from VC++ winso +ck2.h (\x8004667E) *POSIX::EAGAIN = sub { 10035; }; # Gleaned by forcing a no +n-blocking send # Total *HACK* to allow winsock connect() to work on non-blocking so +ckets # Culprit is in perl source /win32/win32sck.c function set_socktype. + We undo # the result of this function. See MSDN support on overlapped I/O fo +r background # info: http://support.microsoft.com/support/kb/articles/Q181/6/11.A +SP my $sock = gensym(); socket($sock, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or print "PORTABLE::BEGIN ERROR - can't create socket\n"; setsockopt($sock, SOL_SOCKET, SO_OPENTYPE, 0) or print "PORTABLE::BEGIN ERROR - Can't setsockopt to overlapped: $!\ +n"; close $sock; # Can't fcntl in windows, so we ioctlsocket. my $truevalue = 1; *setsocknonblock = sub { my $sock = shift; ioctl($sock, POSIX::FIONBIO(), \$truevalue) or warn "Can't ioctl socket to non-blocking: $!\n"; }; }
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

In reply to Re: (to be updated) (tye)Re: Non blocking socket open by MeowChow
in thread Non blocking socket open by jepri

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.