Non-Blocking I/O in Perl - an Example
- Presented by Barry Brevik
- Presentation at: http://manicreader.com/perl/socktalk.html
- Code at: http://manicreader.com/perl/socketprint.txt
Non-Blocking I/O in Perl - an Example
- use IO::Handle;
- use IO::Socket;
# Imports IO::Handle.
- use IO::Socket::INET;
# Imports IO::Socket.
- Book: Network Programming with Perl by Lincoln Stein,
Addison Wesley ISBN 0-201-61571-1.
- Book: Perl Cookbook by Christiansen & Torkington,
O'Reilly ISBN 1-56592-243-3.
Non-Blocking I/O in Perl - an Example
- use Socket;
# Native Perl.
- my $printProtocol = (getprotobyname('tcp'))[2];
- my $binaryIP = pack('C4', split(/\./, '10.18.0.30')); or
my $binaryIP = inet_aton('10.18.0.30')
- socket(PRINTER, AF_INET, SOCK_STREAM, $printProtocol);
- connect(PRINTER, pack('Sna4x8', AF_INET, 9100, $binaryIP));
Non-Blocking I/O in Perl - an Example
- Four argument select statement
ready file descriptors
.
- vec($readyOut, fileno(PRINTER), 1) = 1;
- select $readyIn, $readyOut, $exceptIn, <timeout>;
- $readyIn = is your file descriptor ready to send data?
- $readyOut = is your file descriptor ready to receive data?
- $readyExcept = is your file descriptor trying to send you
an exception such as an out of band or urgent msg?