| 1 | package IO::Stream::const; | ||
| 2 | |||
| 3 | 28 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 28 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 28 | ▶ | use version; our $VERSION = qv('1.0.9'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | # update DEPENDENCIES in POD & Makefile.PL & README | ||
| 9 | 28 | ▶ | use Scalar::Util qw( dualvar ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 28 | ▶ | use Errno qw( EAGAIN ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 28 | ▶ | use Fcntl (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 28 | ▶ | use Socket (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | |||
| 15 | 28 | ▶ | use constant WIN32 => 0; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 28 | ▶ | use constant BUFSIZE => 8192; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | |||
| 18 | # Events: | ||
| 19 | 28 | ▶ | use constant RESOLVED => 1<<0; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 28 | ▶ | use constant CONNECTED => 1<<1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 28 | ▶ | use constant IN => 1<<2; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 28 | ▶ | use constant OUT => 1<<3; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | 28 | ▶ | use constant EOF => 1<<4; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | 28 | ▶ | use constant SENT => 1<<5; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | |||
| 26 | # Timeouts: | ||
| 27 | 28 | ▶ | use constant TOCONNECT => 30; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 28 | 28 | ▶ | use constant TOWRITE => 30; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | |||
| 30 | # Custom errors: | ||
| 31 | 28 | ▶ | use constant EINBUFLIMIT => dualvar(-100, 'in_buf_limit reached'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 32 | 28 | ▶ | use constant ETORESOLVE => dualvar(-101, 'dns timeout'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 33 | 28 | ▶ | use constant ETOCONNECT => dualvar(-102, 'connect timeout'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 34 | 28 | ▶ | use constant ETOWRITE => dualvar(-103, 'write timeout'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 35 | 28 | ▶ | use constant EDNS => dualvar(-200, 'dns error'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 36 | 28 | ▶ | use constant EDNSNXDOMAIN => dualvar(-201, 'dns nxdomain'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 37 | 28 | ▶ | use constant EDNSNODATA => dualvar(-202, 'dns nodata'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 38 | 28 | ▶ | use constant EREQINBUFLIMIT => dualvar(-300, 'in_buf_limit required'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 39 | 28 | ▶ | use constant EREQINEOF => dualvar(-301, 'IN or EOF required in wait_for'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 40 | |||
| 41 | # Cache for speed: | ||
| 42 | ## no critic | ||
| 43 | 28 | ▶ | BEGIN { if (!WIN32) { eval ' |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 44 | use constant F_SETFL => Fcntl::F_SETFL(); | ||
| 45 | use constant O_NONBLOCK => Fcntl::O_NONBLOCK(); | ||
| 46 | '} else { eval ' | ||
| 47 | use constant FIONBIO => 0x8004667E; | ||
| 48 | '}} | ||
| 49 | ## use critic | ||
| 50 | 28 | ▶ | use constant PROTO_TCP => scalar getprotobyname 'tcp'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 51 | 28 | ▶ | use constant AF_INET => Socket::AF_INET(); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 52 | 28 | ▶ | use constant SOCK_STREAM => Socket::SOCK_STREAM(); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 53 | |||
| 54 | |||
| 55 | sub import { | ||
| 56 | 56 | ▶ | my $pkg = caller; |
|
Subroutine
import: called CC=2 SCAR=6.9
| |||
| 57 | 28 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 58 | 56 | for my $const (qw( | |
| 59 | |||
| 60 | WIN32 BUFSIZE | ||
| 61 | |||
| 62 | EAGAIN | ||
| 63 | |||
| 64 | RESOLVED CONNECTED IN OUT EOF SENT | ||
| 65 | |||
| 66 | TOCONNECT TOWRITE | ||
| 67 | |||
| 68 | EINBUFLIMIT ETORESOLVE ETOCONNECT ETOWRITE | ||
| 69 | EDNS EDNSNXDOMAIN EDNSNODATA | ||
| 70 | EREQINBUFLIMIT EREQINEOF | ||
| 71 | |||
| 72 | F_SETFL O_NONBLOCK FIONBIO PROTO_TCP AF_INET SOCK_STREAM | ||
| 73 | |||
| 74 | )) { | ||
| 75 | 1456 | *{"${pkg}::$const"} = \&{$const}; | |
| 76 | } | ||
| 77 | 56 | return; | |
| 78 | } | ||
| 79 | |||
| 80 | |||
| 81 | 28 | 1; | |