in reply to Re^3: Any event modules that support STDIN polling for Windows?
in thread Any event modules that support STDIN polling for Windows?
While the script is running, I can even hit Backspace to erase the contents on the screen!#!/usr/bin/perl use strict; use warnings; use Carp; use English '-no_match_vars'; use charnames ':full'; use Readonly; use Readonly::XS; use threads; use IO::Socket; use version; Readonly::Scalar our $VERSION => qv(0.0_1); $OUTPUT_AUTOFLUSH = 1; # IOCTL code to enable or disable non-blocking mode on a socket Readonly::Scalar my $FIONBIO => 0x80_046_67e; # Create a UDP server socket as input??? Pick a random port number my $in_sock = IO::Socket::INET->new( LocalAddr => 'localhost', LocalPort => 0, Proto => 'udp' ) or croak 'Failed to open port'; # Enable the newly created input socket's non-blocking mode my $true = 1; ( ioctl $in_sock, $FIONBIO, \$true ) or croak $ERRNO; # Create a UDP client socket as output??? Bind it to the input socket +created # earlier my $out_sock = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => $in_sock->sockport(), Proto => 'udp' ) or croak "Failed to bind remote port $in_sock->sockport()"; # Don't really get the mechanics behind these. Just copy and apply for + now threads::async { while (<>) { $out_sock->send($_); } } ->threads::detach; # A simple test to prove that it is non-blocking while (1) { sleep 1; print "\N{FULL STOP}"; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Any event modules that support STDIN polling for Windows?
by BrowserUk (Patriarch) on Aug 30, 2010 at 18:51 UTC | |
|
Re^5: Any event modules that support STDIN polling for Windows?
by BrowserUk (Patriarch) on Sep 08, 2010 at 09:36 UTC |