exiftool-vendored.exe 12.82.0 → 12.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/bin/exiftool.exe +0 -0
- package/bin/exiftool_files/Changes +37 -0
- package/bin/exiftool_files/Licenses_Strawberry_Perl.zip +0 -0
- package/bin/exiftool_files/README +3 -2
- package/bin/exiftool_files/build_geolocation +872 -0
- package/bin/exiftool_files/config_files/example.config +2 -2
- package/bin/exiftool_files/exiftool.pl +28 -6
- package/bin/exiftool_files/fmt_files/gpx.fmt +2 -1
- package/bin/exiftool_files/fmt_files/gpx_wpt.fmt +2 -1
- package/bin/exiftool_files/lib/Archive/Zip/Archive.pm +399 -65
- package/bin/exiftool_files/lib/Archive/Zip/DirectoryMember.pm +1 -1
- package/bin/exiftool_files/lib/Archive/Zip/FileMember.pm +1 -1
- package/bin/exiftool_files/lib/Archive/Zip/Member.pm +499 -195
- package/bin/exiftool_files/lib/Archive/Zip/NewFileMember.pm +1 -1
- package/bin/exiftool_files/lib/Archive/Zip/StringMember.pm +2 -2
- package/bin/exiftool_files/lib/Archive/Zip/ZipFileMember.pm +79 -20
- package/bin/exiftool_files/lib/Archive/Zip.pm +179 -29
- package/bin/exiftool_files/lib/AutoLoader.pm +453 -0
- package/bin/exiftool_files/lib/B/Deparse.pm +209 -137
- package/bin/exiftool_files/lib/B.pm +1 -1
- package/bin/exiftool_files/lib/Benchmark.pm +1123 -0
- package/bin/exiftool_files/lib/Class/Struct.pm +2 -2
- package/bin/exiftool_files/lib/Compress/Raw/Bzip2.pm +14 -9
- package/bin/exiftool_files/lib/Compress/Raw/Lzma.pm +982 -0
- package/bin/exiftool_files/lib/Compress/Raw/Zlib.pm +91 -86
- package/bin/exiftool_files/lib/Compress/Zlib.pm +105 -100
- package/bin/exiftool_files/lib/Config.pm +9 -9
- package/bin/exiftool_files/lib/Config_heavy.pl +36 -33
- package/bin/exiftool_files/lib/CryptX.pm +2 -82
- package/bin/exiftool_files/lib/Data/Dumper.pm +2 -2
- package/bin/exiftool_files/lib/Digest/MD5.pm +12 -9
- package/bin/exiftool_files/lib/Digest/Perl/MD5.pm +1 -191
- package/bin/exiftool_files/lib/Digest/base.pm +26 -20
- package/bin/exiftool_files/lib/DynaLoader.pm +7 -4
- package/bin/exiftool_files/lib/Encode.pm +3 -3
- package/bin/exiftool_files/lib/Errno.pm +13 -13
- package/bin/exiftool_files/lib/Exporter/Heavy.pm +2 -2
- package/bin/exiftool_files/lib/Exporter.pm +1 -1
- package/bin/exiftool_files/lib/ExtUtils/Command/MM.pm +323 -0
- package/bin/exiftool_files/lib/ExtUtils/Command.pm +382 -0
- package/bin/exiftool_files/lib/File/Find.pm +1 -1
- package/bin/exiftool_files/lib/File/Glob.pm +1 -8
- package/bin/exiftool_files/lib/File/GlobMapper.pm +2 -2
- package/bin/exiftool_files/lib/File/HomeDir/Darwin/Carbon.pm +2 -40
- package/bin/exiftool_files/lib/File/HomeDir/Darwin/Cocoa.pm +2 -34
- package/bin/exiftool_files/lib/File/HomeDir/Darwin.pm +2 -28
- package/bin/exiftool_files/lib/File/HomeDir/Driver.pm +2 -35
- package/bin/exiftool_files/lib/File/HomeDir/FreeDesktop.pm +2 -62
- package/bin/exiftool_files/lib/File/HomeDir/MacOS9.pm +2 -53
- package/bin/exiftool_files/lib/File/HomeDir/Test.pm +2 -43
- package/bin/exiftool_files/lib/File/HomeDir/Unix.pm +2 -53
- package/bin/exiftool_files/lib/File/HomeDir/Windows.pm +2 -69
- package/bin/exiftool_files/lib/File/HomeDir.pm +5 -416
- package/bin/exiftool_files/lib/File/Path.pm +3 -3
- package/bin/exiftool_files/lib/File/Spec/Win32.pm +2 -2
- package/bin/exiftool_files/lib/File/Temp.pm +70 -35
- package/bin/exiftool_files/lib/File/Which.pm +1 -240
- package/bin/exiftool_files/lib/File/stat.pm +3 -2
- package/bin/exiftool_files/lib/IO/Compress/Adapter/Bzip2.pm +16 -17
- package/bin/exiftool_files/lib/IO/Compress/Adapter/Deflate.pm +19 -20
- package/bin/exiftool_files/lib/IO/Compress/Base/Common.pm +5 -5
- package/bin/exiftool_files/lib/IO/Compress/Base.pm +35 -26
- package/bin/exiftool_files/lib/IO/Compress/Brotli.pm +159 -0
- package/bin/exiftool_files/lib/IO/Compress/Bzip2.pm +50 -25
- package/bin/exiftool_files/lib/IO/Compress/Gzip/Constants.pm +6 -6
- package/bin/exiftool_files/lib/IO/Compress/Gzip.pm +58 -32
- package/bin/exiftool_files/lib/IO/Compress/RawDeflate.pm +63 -38
- package/bin/exiftool_files/lib/IO/Compress/Zlib/Extra.pm +20 -20
- package/bin/exiftool_files/lib/IO/Dir.pm +1 -1
- package/bin/exiftool_files/lib/IO/File.pm +1 -1
- package/bin/exiftool_files/lib/IO/Handle.pm +1 -21
- package/bin/exiftool_files/lib/IO/Pipe.pm +1 -1
- package/bin/exiftool_files/lib/IO/Seekable.pm +1 -1
- package/bin/exiftool_files/lib/IO/Select.pm +16 -2
- package/bin/exiftool_files/lib/IO/Socket/INET.pm +14 -9
- package/bin/exiftool_files/lib/IO/Socket/UNIX.pm +17 -1
- package/bin/exiftool_files/lib/IO/Socket.pm +474 -126
- package/bin/exiftool_files/lib/IO/String.pm +425 -0
- package/bin/exiftool_files/lib/IO/Uncompress/Adapter/Inflate.pm +13 -14
- package/bin/exiftool_files/lib/IO/Uncompress/Base.pm +142 -132
- package/bin/exiftool_files/lib/IO/Uncompress/Brotli.pm +119 -0
- package/bin/exiftool_files/lib/IO/Uncompress/Gunzip.pm +43 -37
- package/bin/exiftool_files/lib/IO/Uncompress/RawInflate.pm +49 -43
- package/bin/exiftool_files/lib/IO.pm +2 -2
- package/bin/exiftool_files/lib/Image/ExifTool/Apple.pm +51 -7
- package/bin/exiftool_files/lib/Image/ExifTool/BuildTagLookup.pm +5 -2
- package/bin/exiftool_files/lib/Image/ExifTool/CanonVRD.pm +18 -5
- package/bin/exiftool_files/lib/Image/ExifTool/DJI.pm +29 -0
- package/bin/exiftool_files/lib/Image/ExifTool/Exif.pm +19 -2
- package/bin/exiftool_files/lib/Image/ExifTool/GM.pm +17 -8
- package/bin/exiftool_files/lib/Image/ExifTool/Geolocation.dat +0 -0
- package/bin/exiftool_files/lib/Image/ExifTool/Geolocation.pm +163 -101
- package/bin/exiftool_files/lib/Image/ExifTool/Geotag.pm +18 -10
- package/bin/exiftool_files/lib/Image/ExifTool/Nikon.pm +7 -6
- package/bin/exiftool_files/lib/Image/ExifTool/QuickTime.pm +6 -1
- package/bin/exiftool_files/lib/Image/ExifTool/QuickTimeStream.pl +5 -0
- package/bin/exiftool_files/lib/Image/ExifTool/Sony.pm +15 -6
- package/bin/exiftool_files/lib/Image/ExifTool/TagLookup.pm +18 -9
- package/bin/exiftool_files/lib/Image/ExifTool/TagNames.pod +24 -5
- package/bin/exiftool_files/lib/Image/ExifTool/WriteQuickTime.pl +2 -1
- package/bin/exiftool_files/lib/Image/ExifTool/Writer.pl +165 -132
- package/bin/exiftool_files/lib/Image/ExifTool/XMP2.pl +3 -0
- package/bin/exiftool_files/lib/Image/ExifTool.pm +45 -23
- package/bin/exiftool_files/lib/Image/ExifTool.pod +23 -14
- package/bin/exiftool_files/lib/List/Util.pm +97 -8
- package/bin/exiftool_files/lib/MIME/Base64.pm +5 -5
- package/bin/exiftool_files/lib/MIME/Charset/_Compat.pm +106 -0
- package/bin/exiftool_files/lib/MIME/Charset.pm +1303 -0
- package/bin/exiftool_files/lib/Math/BigFloat.pm +444 -27
- package/bin/exiftool_files/lib/Math/BigInt/Calc.pm +296 -313
- package/bin/exiftool_files/lib/Math/BigInt/FastCalc.pm +1 -1
- package/bin/exiftool_files/lib/Math/BigInt/GMP.pm +2 -115
- package/bin/exiftool_files/lib/Math/BigInt/LTM.pm +2 -24
- package/bin/exiftool_files/lib/Math/BigInt/Lib.pm +61 -32
- package/bin/exiftool_files/lib/Math/BigInt.pm +292 -107
- package/bin/exiftool_files/lib/POSIX.pm +1 -1
- package/bin/exiftool_files/lib/PerlIO/scalar.pm +41 -0
- package/bin/exiftool_files/lib/PerlIO.pm +397 -0
- package/bin/exiftool_files/lib/Portable/CPAN.pm +94 -94
- package/bin/exiftool_files/lib/Portable/Config.pm +94 -94
- package/bin/exiftool_files/lib/Portable/FileSpec.pm +180 -180
- package/bin/exiftool_files/lib/Portable/HomeDir.pm +110 -110
- package/bin/exiftool_files/lib/Portable/LoadYaml.pm +430 -430
- package/bin/exiftool_files/lib/Portable/minicpan.pm +55 -55
- package/bin/exiftool_files/lib/Portable.pm +246 -320
- package/bin/exiftool_files/lib/Scalar/Util.pm +9 -4
- package/bin/exiftool_files/lib/Socket.pm +16 -12
- package/bin/exiftool_files/lib/Storable.pm +1444 -1441
- package/bin/exiftool_files/lib/TAP/Base.pm +133 -0
- package/bin/exiftool_files/lib/TAP/Formatter/Base.pm +467 -0
- package/bin/exiftool_files/lib/TAP/Formatter/Color.pm +116 -0
- package/bin/exiftool_files/lib/TAP/Formatter/Console/ParallelSession.pm +201 -0
- package/bin/exiftool_files/lib/TAP/Formatter/Console/Session.pm +205 -0
- package/bin/exiftool_files/lib/TAP/Formatter/Console.pm +100 -0
- package/bin/exiftool_files/lib/TAP/Formatter/File/Session.pm +95 -0
- package/bin/exiftool_files/lib/TAP/Formatter/File.pm +56 -0
- package/bin/exiftool_files/lib/TAP/Formatter/Session.pm +220 -0
- package/bin/exiftool_files/lib/TAP/Harness/Beyond.pod +426 -0
- package/bin/exiftool_files/lib/TAP/Harness/Env.pm +215 -0
- package/bin/exiftool_files/lib/TAP/Harness.pm +1054 -0
- package/bin/exiftool_files/lib/TAP/Object.pm +155 -0
- package/bin/exiftool_files/lib/TAP/Parser/Aggregator.pm +414 -0
- package/bin/exiftool_files/lib/TAP/Parser/Grammar.pm +584 -0
- package/bin/exiftool_files/lib/TAP/Parser/Iterator/Array.pm +100 -0
- package/bin/exiftool_files/lib/TAP/Parser/Iterator/Process.pm +378 -0
- package/bin/exiftool_files/lib/TAP/Parser/Iterator/Stream.pm +116 -0
- package/bin/exiftool_files/lib/TAP/Parser/Iterator.pm +162 -0
- package/bin/exiftool_files/lib/TAP/Parser/IteratorFactory.pm +339 -0
- package/bin/exiftool_files/lib/TAP/Parser/Multiplexer.pm +194 -0
- package/bin/exiftool_files/lib/TAP/Parser/Result/Bailout.pm +62 -0
- package/bin/exiftool_files/lib/TAP/Parser/Result/Comment.pm +60 -0
- package/bin/exiftool_files/lib/TAP/Parser/Result/Plan.pm +119 -0
- package/bin/exiftool_files/lib/TAP/Parser/Result/Pragma.pm +62 -0
- package/bin/exiftool_files/lib/TAP/Parser/Result/Test.pm +271 -0
- package/bin/exiftool_files/lib/TAP/Parser/Result/Unknown.pm +48 -0
- package/bin/exiftool_files/lib/TAP/Parser/Result/Version.pm +62 -0
- package/bin/exiftool_files/lib/TAP/Parser/Result/YAML.pm +61 -0
- package/bin/exiftool_files/lib/TAP/Parser/Result.pm +297 -0
- package/bin/exiftool_files/lib/TAP/Parser/ResultFactory.pm +183 -0
- package/bin/exiftool_files/lib/TAP/Parser/Scheduler/Job.pm +127 -0
- package/bin/exiftool_files/lib/TAP/Parser/Scheduler/Spinner.pm +61 -0
- package/bin/exiftool_files/lib/TAP/Parser/Scheduler.pm +448 -0
- package/bin/exiftool_files/lib/TAP/Parser/Source.pm +381 -0
- package/bin/exiftool_files/lib/TAP/Parser/SourceHandler/Executable.pm +184 -0
- package/bin/exiftool_files/lib/TAP/Parser/SourceHandler/File.pm +136 -0
- package/bin/exiftool_files/lib/TAP/Parser/SourceHandler/Handle.pm +124 -0
- package/bin/exiftool_files/lib/TAP/Parser/SourceHandler/Perl.pm +370 -0
- package/bin/exiftool_files/lib/TAP/Parser/SourceHandler/RawTAP.pm +130 -0
- package/bin/exiftool_files/lib/TAP/Parser/SourceHandler.pm +191 -0
- package/bin/exiftool_files/lib/TAP/Parser/YAMLish/Reader.pm +332 -0
- package/bin/exiftool_files/lib/TAP/Parser/YAMLish/Writer.pm +254 -0
- package/bin/exiftool_files/lib/TAP/Parser.pm +1931 -0
- package/bin/exiftool_files/lib/Test/Builder/Formatter.pm +107 -0
- package/bin/exiftool_files/lib/Test/Builder/IO/Scalar.pm +659 -0
- package/bin/exiftool_files/lib/Test/Builder/Module.pm +182 -0
- package/bin/exiftool_files/lib/Test/Builder/Tester/Color.pm +51 -0
- package/bin/exiftool_files/lib/Test/Builder/Tester.pm +675 -0
- package/bin/exiftool_files/lib/Test/Builder/TodoDiag.pm +68 -0
- package/bin/exiftool_files/lib/Test/Builder.pm +2653 -0
- package/bin/exiftool_files/lib/Test/Harness.pm +618 -0
- package/bin/exiftool_files/lib/Test/More.pm +1997 -0
- package/bin/exiftool_files/lib/Test/Simple.pm +220 -0
- package/bin/exiftool_files/lib/Test/Tester/Capture.pm +241 -0
- package/bin/exiftool_files/lib/Test/Tester/CaptureRunner.pm +79 -0
- package/bin/exiftool_files/lib/Test/Tester/Delegate.pm +45 -0
- package/bin/exiftool_files/lib/Test/Tester.pm +695 -0
- package/bin/exiftool_files/lib/Test/Tutorial.pod +618 -0
- package/bin/exiftool_files/lib/Test/use/ok.pm +64 -0
- package/bin/exiftool_files/lib/Text/ParseWords.pm +303 -0
- package/bin/exiftool_files/lib/Tie/StdHandle.pm +2 -2
- package/bin/exiftool_files/lib/Time/HiRes.pm +73 -68
- package/bin/exiftool_files/lib/Time/Local.pm +82 -35
- package/bin/exiftool_files/lib/Time/Piece.pm +19 -4
- package/bin/exiftool_files/lib/Time/Seconds.pm +1 -1
- package/bin/exiftool_files/lib/UNIVERSAL.pm +203 -0
- package/bin/exiftool_files/lib/Unicode/GCString.pm +60 -0
- package/bin/exiftool_files/lib/Unicode/LineBreak/Constants.pm +68 -0
- package/bin/exiftool_files/lib/Unicode/LineBreak.pm +248 -0
- package/bin/exiftool_files/lib/Win32/API/Struct.pm +1 -177
- package/bin/exiftool_files/lib/Win32/API/Type.pm +1 -100
- package/bin/exiftool_files/lib/Win32/API.pm +1 -830
- package/bin/exiftool_files/lib/Win32/FindFile.pm +2 -123
- package/bin/exiftool_files/lib/Win32.pm +213 -89
- package/bin/exiftool_files/lib/Win32API/File.pm +1 -1
- package/bin/exiftool_files/lib/auto/B/B.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Compress/Raw/Bzip2/Bzip2.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Compress/Raw/Lzma/Lzma.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Compress/Raw/Lzma/autosplit.ix +3 -0
- package/bin/exiftool_files/lib/auto/Compress/Raw/Zlib/Zlib.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/CryptX/CryptX.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Cwd/Cwd.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Data/Dumper/Dumper.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Digest/MD5/MD5.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Digest/SHA/SHA.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Encode/Encode.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Fcntl/Fcntl.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/File/Glob/Glob.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/IO/Compress/Brotli/Brotli.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/IO/IO.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/List/Util/Util.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/MIME/Base64/Base64.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Math/BigInt/FastCalc/FastCalc.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Math/BigInt/GMP/GMP.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/POSIX/POSIX.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/PerlIO/scalar/scalar.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Socket/Socket.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Storable/Storable.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Time/HiRes/HiRes.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Time/Piece/Piece.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Unicode/LineBreak/LineBreak.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Win32/API/API.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Win32/FindFile/FindFile.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Win32/Win32.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/Win32API/File/File.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/mro/mro.xs.dll +0 -0
- package/bin/exiftool_files/lib/auto/re/re.xs.dll +0 -0
- package/bin/exiftool_files/lib/feature.pm +49 -17
- package/bin/exiftool_files/lib/mro.pm +4 -20
- package/bin/exiftool_files/lib/overload.pm +15 -15
- package/bin/exiftool_files/lib/parent.pm +10 -2
- package/bin/exiftool_files/lib/re.pm +91 -33
- package/bin/exiftool_files/lib/warnings.pm +17 -6
- package/bin/exiftool_files/libgcc_s_seh-1.dll +0 -0
- package/bin/exiftool_files/liblzma-5__.dll +0 -0
- package/bin/exiftool_files/libstdc++-6.dll +0 -0
- package/bin/exiftool_files/libwinpthread-1.dll +0 -0
- package/bin/exiftool_files/perl.exe +0 -0
- package/bin/exiftool_files/perl532.dll +0 -0
- package/package.json +6 -4
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/cs.pm +0 -978
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/de.pm +0 -1975
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/en_ca.pm +0 -44
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/en_gb.pm +0 -124
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/es.pm +0 -2921
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/fi.pm +0 -1116
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/fr.pm +0 -3171
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/it.pm +0 -2750
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/ja.pm +0 -10256
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/ko.pm +0 -4499
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/nl.pm +0 -1270
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/pl.pm +0 -3019
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/ru.pm +0 -18220
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/sk.pm +0 -441
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/sv.pm +0 -714
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/tr.pm +0 -452
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/zh_cn.pm +0 -2225
- package/bin/exiftool_files/lib/Image/ExifTool/GeoLang/zh_tw.pm +0 -72
- package/bin/exiftool_files/libgcc_s_dw2-1.dll +0 -0
- package/bin/exiftool_files/perl530.dll +0 -0
|
@@ -23,10 +23,12 @@ require IO::Socket::UNIX if ($^O ne 'epoc' && $^O ne 'symbian');
|
|
|
23
23
|
|
|
24
24
|
our @ISA = qw(IO::Handle);
|
|
25
25
|
|
|
26
|
-
our $VERSION = "1.
|
|
26
|
+
our $VERSION = "1.45";
|
|
27
27
|
|
|
28
28
|
our @EXPORT_OK = qw(sockatmark);
|
|
29
29
|
|
|
30
|
+
our $errstr;
|
|
31
|
+
|
|
30
32
|
sub import {
|
|
31
33
|
my $pkg = shift;
|
|
32
34
|
if (@_ && $_[0] eq 'sockatmark') { # not very extensible but for now, fast
|
|
@@ -82,7 +84,12 @@ sub socket {
|
|
|
82
84
|
|
|
83
85
|
${*$sock}{'io_socket_domain'} = $domain;
|
|
84
86
|
${*$sock}{'io_socket_type'} = $type;
|
|
85
|
-
|
|
87
|
+
|
|
88
|
+
# "A value of 0 for protocol will let the system select an
|
|
89
|
+
# appropriate protocol"
|
|
90
|
+
# so we need to look up what the system selected,
|
|
91
|
+
# not cache PF_UNSPEC.
|
|
92
|
+
${*$sock}{'io_socket_proto'} = $protocol if $protocol;
|
|
86
93
|
|
|
87
94
|
$sock;
|
|
88
95
|
}
|
|
@@ -115,7 +122,7 @@ sub connect {
|
|
|
115
122
|
if (defined $timeout && ($!{EINPROGRESS} || $!{EWOULDBLOCK})) {
|
|
116
123
|
require IO::Select;
|
|
117
124
|
|
|
118
|
-
my $sel =
|
|
125
|
+
my $sel = IO::Select->new( $sock );
|
|
119
126
|
|
|
120
127
|
undef $!;
|
|
121
128
|
my($r,$w,$e) = IO::Select::select(undef,$sel,$sel,$timeout);
|
|
@@ -127,11 +134,11 @@ sub connect {
|
|
|
127
134
|
# set we now emulate the behavior in Linux
|
|
128
135
|
# - Karthik Rajagopalan
|
|
129
136
|
$err = $sock->getsockopt(SOL_SOCKET,SO_ERROR);
|
|
130
|
-
$@ = "connect: $err";
|
|
137
|
+
$errstr = $@ = "connect: $err";
|
|
131
138
|
}
|
|
132
139
|
elsif(!@$w[0]) {
|
|
133
140
|
$err = $! || (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1);
|
|
134
|
-
$@ = "connect: timeout";
|
|
141
|
+
$errstr = $@ = "connect: timeout";
|
|
135
142
|
}
|
|
136
143
|
elsif (!connect($sock,$addr) &&
|
|
137
144
|
not ($!{EISCONN} || ($^O eq 'MSWin32' &&
|
|
@@ -142,12 +149,12 @@ sub connect {
|
|
|
142
149
|
# Windows sets errno to WSAEINVAL (10022) (pre-5.19.4) or
|
|
143
150
|
# EINVAL (22) (5.19.4 onwards).
|
|
144
151
|
$err = $!;
|
|
145
|
-
$@ = "connect: $!";
|
|
152
|
+
$errstr = $@ = "connect: $!";
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
155
|
elsif ($blocking || !($!{EINPROGRESS} || $!{EWOULDBLOCK})) {
|
|
149
156
|
$err = $!;
|
|
150
|
-
$@ = "connect: $!";
|
|
157
|
+
$errstr = $@ = "connect: $!";
|
|
151
158
|
}
|
|
152
159
|
}
|
|
153
160
|
|
|
@@ -179,25 +186,25 @@ sub blocking {
|
|
|
179
186
|
#
|
|
180
187
|
# which is used to set blocking behaviour.
|
|
181
188
|
|
|
182
|
-
# NOTE:
|
|
189
|
+
# NOTE:
|
|
183
190
|
# This is a little confusing, the perl keyword for this is
|
|
184
191
|
# 'blocking' but the OS level behaviour is 'non-blocking', probably
|
|
185
192
|
# because sockets are blocking by default.
|
|
186
193
|
# Therefore internally we have to reverse the semantics.
|
|
187
194
|
|
|
188
195
|
my $orig= !${*$sock}{io_sock_nonblocking};
|
|
189
|
-
|
|
196
|
+
|
|
190
197
|
return $orig unless @_;
|
|
191
198
|
|
|
192
199
|
my $block = shift;
|
|
193
|
-
|
|
200
|
+
|
|
194
201
|
if ( !$block != !$orig ) {
|
|
195
202
|
${*$sock}{io_sock_nonblocking} = $block ? 0 : 1;
|
|
196
203
|
ioctl($sock, 0x8004667e, pack("L!",${*$sock}{io_sock_nonblocking}))
|
|
197
204
|
or return undef;
|
|
198
205
|
}
|
|
199
|
-
|
|
200
|
-
return $orig;
|
|
206
|
+
|
|
207
|
+
return $orig;
|
|
201
208
|
}
|
|
202
209
|
|
|
203
210
|
|
|
@@ -238,10 +245,10 @@ sub accept {
|
|
|
238
245
|
if(defined $timeout) {
|
|
239
246
|
require IO::Select;
|
|
240
247
|
|
|
241
|
-
my $sel =
|
|
248
|
+
my $sel = IO::Select->new( $sock );
|
|
242
249
|
|
|
243
250
|
unless ($sel->can_read($timeout)) {
|
|
244
|
-
$@ = 'accept: timeout';
|
|
251
|
+
$errstr = $@ = 'accept: timeout';
|
|
245
252
|
$! = (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1);
|
|
246
253
|
return;
|
|
247
254
|
}
|
|
@@ -277,14 +284,24 @@ sub send {
|
|
|
277
284
|
@_ >= 2 && @_ <= 4 or croak 'usage: $sock->send(BUF, [FLAGS, [TO]])';
|
|
278
285
|
my $sock = $_[0];
|
|
279
286
|
my $flags = $_[2] || 0;
|
|
280
|
-
my $peer
|
|
287
|
+
my $peer;
|
|
288
|
+
|
|
289
|
+
if ($_[3]) {
|
|
290
|
+
# the caller explicitly requested a TO, so use it
|
|
291
|
+
# this is non-portable for "connected" UDP sockets
|
|
292
|
+
$peer = $_[3];
|
|
293
|
+
}
|
|
294
|
+
elsif (!defined getpeername($sock)) {
|
|
295
|
+
# we're not connected, so we require a peer from somewhere
|
|
296
|
+
$peer = $sock->peername;
|
|
281
297
|
|
|
282
|
-
|
|
283
|
-
|
|
298
|
+
croak 'send: Cannot determine peer address'
|
|
299
|
+
unless(defined $peer);
|
|
300
|
+
}
|
|
284
301
|
|
|
285
|
-
my $r =
|
|
286
|
-
|
|
287
|
-
|
|
302
|
+
my $r = $peer
|
|
303
|
+
? send($sock, $_[1], $flags, $peer)
|
|
304
|
+
: send($sock, $_[1], $flags);
|
|
288
305
|
|
|
289
306
|
# remember who we send to, if it was successful
|
|
290
307
|
${*$sock}{'io_socket_peername'} = $peer
|
|
@@ -386,185 +403,516 @@ IO::Socket - Object interface to socket communications
|
|
|
386
403
|
|
|
387
404
|
=head1 SYNOPSIS
|
|
388
405
|
|
|
389
|
-
use
|
|
406
|
+
use strict;
|
|
407
|
+
use warnings;
|
|
408
|
+
|
|
409
|
+
use IO::Socket qw(AF_INET AF_UNIX);
|
|
410
|
+
|
|
411
|
+
# create a new AF_INET socket
|
|
412
|
+
my $sock = IO::Socket->new(Domain => AF_INET);
|
|
413
|
+
# which is the same as
|
|
414
|
+
$sock = IO::Socket::INET->new();
|
|
415
|
+
|
|
416
|
+
# create a new AF_UNIX socket
|
|
417
|
+
$sock = IO::Socket->new(Domain => AF_UNIX);
|
|
418
|
+
# which is the same as
|
|
419
|
+
$sock = IO::Socket::UNIX->new();
|
|
390
420
|
|
|
391
421
|
=head1 DESCRIPTION
|
|
392
422
|
|
|
393
|
-
C<IO::Socket> provides an object interface to
|
|
394
|
-
|
|
395
|
-
|
|
423
|
+
C<IO::Socket> provides an object-oriented, L<IO::Handle>-based interface to
|
|
424
|
+
creating and using sockets via L<Socket>, which provides a near one-to-one
|
|
425
|
+
interface to the C socket library.
|
|
396
426
|
|
|
397
|
-
C<IO::Socket>
|
|
398
|
-
|
|
399
|
-
domain have methods defined in
|
|
427
|
+
C<IO::Socket> is a base class that really only defines methods for those
|
|
428
|
+
operations which are common to all types of sockets. Operations which are
|
|
429
|
+
specific to a particular socket domain have methods defined in subclasses of
|
|
430
|
+
C<IO::Socket>. See L<IO::Socket::INET>, L<IO::Socket::UNIX>, and
|
|
431
|
+
L<IO::Socket::IP> for examples of such a subclass.
|
|
400
432
|
|
|
401
433
|
C<IO::Socket> will export all functions (and constants) defined by L<Socket>.
|
|
402
434
|
|
|
403
|
-
=head1 CONSTRUCTOR
|
|
435
|
+
=head1 CONSTRUCTOR ARGUMENTS
|
|
404
436
|
|
|
405
|
-
|
|
437
|
+
Given that C<IO::Socket> doesn't have attributes in the traditional sense, the
|
|
438
|
+
following arguments, rather than attributes, can be passed into the
|
|
439
|
+
constructor.
|
|
406
440
|
|
|
407
|
-
|
|
441
|
+
Constructor arguments should be passed in C<< Key => 'Value' >> pairs.
|
|
408
442
|
|
|
409
|
-
|
|
410
|
-
newly created symbol (see the C<Symbol> package). C<new>
|
|
411
|
-
optionally takes arguments, these arguments are in key-value pairs.
|
|
412
|
-
C<new> only looks for one key C<Domain> which tells new which domain
|
|
413
|
-
the socket will be in. All other arguments will be passed to the
|
|
414
|
-
configuration method of the package for that domain, See below.
|
|
443
|
+
The only required argument is L<IO::Socket/"Domain">.
|
|
415
444
|
|
|
416
|
-
|
|
445
|
+
=head2 Blocking
|
|
417
446
|
|
|
418
|
-
|
|
419
|
-
|
|
447
|
+
my $sock = IO::Socket->new(..., Blocking => 1);
|
|
448
|
+
$sock = IO::Socket->new(..., Blocking => 0);
|
|
420
449
|
|
|
421
|
-
|
|
450
|
+
If defined but false, the socket will be set to non-blocking mode. If not
|
|
451
|
+
specified it defaults to C<1> (blocking mode).
|
|
422
452
|
|
|
423
|
-
=
|
|
453
|
+
=head2 Domain
|
|
424
454
|
|
|
425
|
-
=
|
|
455
|
+
my $sock = IO::Socket->new(Domain => IO::Socket::AF_INET);
|
|
456
|
+
$sock = IO::Socket->new(Domain => IO::Socket::AF_UNIX);
|
|
426
457
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
corresponding built-in functions:
|
|
458
|
+
The socket domain will define which subclass of C<IO::Socket> to use. The two
|
|
459
|
+
options available along with this distribution are C<AF_INET> and C<AF_UNIX>.
|
|
430
460
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
listen
|
|
435
|
-
accept
|
|
436
|
-
send
|
|
437
|
-
recv
|
|
438
|
-
peername (getpeername)
|
|
439
|
-
sockname (getsockname)
|
|
440
|
-
shutdown
|
|
461
|
+
C<AF_INET> is for the internet address family of sockets and is handled via
|
|
462
|
+
L<IO::Socket::INET>. C<AF_INET> sockets are bound to an internet address and
|
|
463
|
+
port.
|
|
441
464
|
|
|
442
|
-
|
|
443
|
-
|
|
465
|
+
C<AF_UNIX> is for the unix domain socket and is handled via
|
|
466
|
+
L<IO::Socket::UNIX>. C<AF_UNIX> sockets are bound to the file system as their
|
|
467
|
+
address name space.
|
|
444
468
|
|
|
445
|
-
|
|
469
|
+
This argument is B<required>. All other arguments are optional.
|
|
446
470
|
|
|
447
|
-
=
|
|
471
|
+
=head2 Listen
|
|
448
472
|
|
|
449
|
-
|
|
450
|
-
object. The new object will be created in the same class as the listen
|
|
451
|
-
socket, unless C<PKG> is specified. This object can be used to
|
|
452
|
-
communicate with the client that was trying to connect.
|
|
473
|
+
my $sock = IO::Socket->new(..., Listen => 5);
|
|
453
474
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
475
|
+
Listen should be an integer value or left unset.
|
|
476
|
+
|
|
477
|
+
If provided, this argument will place the socket into listening mode. New
|
|
478
|
+
connections can then be accepted using the L<IO::Socket/"accept"> method. The
|
|
479
|
+
value given is used as the C<listen(2)> queue size.
|
|
458
480
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
created behind the scenes just to do the single poll. This is
|
|
462
|
-
horrendously inefficient. Use rather true select() with a zero
|
|
463
|
-
timeout on the handle, or non-blocking IO.
|
|
481
|
+
If the C<Listen> argument is given, but false, the queue size will be set to
|
|
482
|
+
5.
|
|
464
483
|
|
|
465
|
-
=
|
|
484
|
+
=head2 Timeout
|
|
466
485
|
|
|
467
|
-
|
|
468
|
-
empty list on failure.
|
|
486
|
+
my $sock = IO::Socket->new(..., Timeout => 5);
|
|
469
487
|
|
|
470
|
-
|
|
488
|
+
The timeout value, in seconds, for this socket connection. How exactly this
|
|
489
|
+
value is utilized is defined in the socket domain subclasses that make use of
|
|
490
|
+
the value.
|
|
471
491
|
|
|
472
|
-
|
|
492
|
+
=head2 Type
|
|
473
493
|
|
|
474
|
-
=
|
|
494
|
+
my $sock = IO::Socket->new(..., Type => IO::Socket::SOCK_STREAM);
|
|
475
495
|
|
|
476
|
-
|
|
496
|
+
The socket type that will be used. These are usually C<SOCK_STREAM>,
|
|
497
|
+
C<SOCK_DGRAM>, or C<SOCK_RAW>. If this argument is left undefined an attempt
|
|
498
|
+
will be made to infer the type from the service name.
|
|
477
499
|
|
|
478
|
-
|
|
479
|
-
|
|
500
|
+
For example, you'll usually use C<SOCK_STREAM> with a C<tcp> connection and
|
|
501
|
+
C<SOCK_DGRAM> with a C<udp> connection.
|
|
502
|
+
|
|
503
|
+
=head1 CONSTRUCTORS
|
|
504
|
+
|
|
505
|
+
C<IO::Socket> extends the L<IO::Handle> constructor.
|
|
506
|
+
|
|
507
|
+
=head2 new
|
|
508
|
+
|
|
509
|
+
my $sock = IO::Socket->new();
|
|
510
|
+
|
|
511
|
+
# get a new IO::Socket::INET instance
|
|
512
|
+
$sock = IO::Socket->new(Domain => IO::Socket::AF_INET);
|
|
513
|
+
# get a new IO::Socket::UNIX instance
|
|
514
|
+
$sock = IO::Socket->new(Domain => IO::Socket::AF_UNIX);
|
|
515
|
+
|
|
516
|
+
# Domain is the only required argument
|
|
517
|
+
$sock = IO::Socket->new(
|
|
518
|
+
Domain => IO::Socket::AF_INET, # AF_INET, AF_UNIX
|
|
519
|
+
Type => IO::Socket::SOCK_STREAM, # SOCK_STREAM, SOCK_DGRAM, ...
|
|
520
|
+
Proto => 'tcp', # 'tcp', 'udp', IPPROTO_TCP, IPPROTO_UDP
|
|
521
|
+
# and so on...
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
Creates an C<IO::Socket>, which is a reference to a newly created symbol (see
|
|
525
|
+
the L<Symbol> package). C<new> optionally takes arguments, these arguments
|
|
526
|
+
are defined in L<IO::Socket/"CONSTRUCTOR ARGUMENTS">.
|
|
527
|
+
|
|
528
|
+
Any of the L<IO::Socket/"CONSTRUCTOR ARGUMENTS"> may be passed to the
|
|
529
|
+
constructor, but if any arguments are provided, then one of them must be
|
|
530
|
+
the L<IO::Socket/"Domain"> argument. The L<IO::Socket/"Domain"> argument can,
|
|
531
|
+
by default, be either C<AF_INET> or C<AF_UNIX>. Other domains can be used if a
|
|
532
|
+
proper subclass for the domain family is registered. All other arguments will
|
|
533
|
+
be passed to the C<configuration> method of the package for that domain.
|
|
534
|
+
|
|
535
|
+
If the constructor fails it will return C<undef> and set the C<$errstr> package
|
|
536
|
+
variable to contain an error message.
|
|
537
|
+
|
|
538
|
+
$sock = IO::Socket->new(...)
|
|
539
|
+
or die "Cannot create socket - $IO::Socket::errstr\n";
|
|
540
|
+
|
|
541
|
+
For legacy reasons the error message is also set into the global C<$@>
|
|
542
|
+
variable, and you may still find older code which looks here instead.
|
|
543
|
+
|
|
544
|
+
$sock = IO::Socket->new(...)
|
|
545
|
+
or die "Cannot create socket - $@\n";
|
|
546
|
+
|
|
547
|
+
=head1 METHODS
|
|
480
548
|
|
|
481
|
-
|
|
549
|
+
C<IO::Socket> inherits all methods from L<IO::Handle> and implements the
|
|
550
|
+
following new ones.
|
|
482
551
|
|
|
483
|
-
|
|
552
|
+
=head2 accept
|
|
553
|
+
|
|
554
|
+
my $client_sock = $sock->accept();
|
|
555
|
+
my $inet_sock = $sock->accept('IO::Socket::INET');
|
|
556
|
+
|
|
557
|
+
The accept method will perform the system call C<accept> on the socket and
|
|
558
|
+
return a new object. The new object will be created in the same class as the
|
|
559
|
+
listen socket, unless a specific package name is specified. This object can be
|
|
560
|
+
used to communicate with the client that was trying to connect.
|
|
561
|
+
|
|
562
|
+
This differs slightly from the C<accept> function in L<perlfunc>.
|
|
563
|
+
|
|
564
|
+
In a scalar context the new socket is returned, or C<undef> upon
|
|
565
|
+
failure. In a list context a two-element array is returned containing
|
|
566
|
+
the new socket and the peer address; the list will be empty upon failure.
|
|
567
|
+
|
|
568
|
+
=head2 atmark
|
|
569
|
+
|
|
570
|
+
my $integer = $sock->atmark();
|
|
571
|
+
# read in some data on a given socket
|
|
572
|
+
my $data;
|
|
484
573
|
$sock->read($data, 1024) until $sock->atmark;
|
|
485
574
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
abort the program.
|
|
575
|
+
# or, export the function to use:
|
|
576
|
+
use IO::Socket 'sockatmark';
|
|
577
|
+
$sock->read($data, 1024) until sockatmark($sock);
|
|
490
578
|
|
|
491
|
-
|
|
579
|
+
True if the socket is currently positioned at the urgent data mark, false
|
|
580
|
+
otherwise. If your system doesn't yet implement C<sockatmark> this will throw
|
|
581
|
+
an exception.
|
|
492
582
|
|
|
493
|
-
|
|
583
|
+
If your system does not support C<sockatmark>, the C<use> declaration will
|
|
584
|
+
fail at compile time.
|
|
494
585
|
|
|
495
|
-
|
|
496
|
-
socket function. If your system does not support sockatmark(), the
|
|
497
|
-
C<use> declaration will fail at compile time.
|
|
586
|
+
=head2 autoflush
|
|
498
587
|
|
|
499
|
-
|
|
588
|
+
# by default, autoflush will be turned on when referenced
|
|
589
|
+
$sock->autoflush(); # turns on autoflush
|
|
590
|
+
# turn off autoflush
|
|
591
|
+
$sock->autoflush(0);
|
|
592
|
+
# turn on autoflush
|
|
593
|
+
$sock->autoflush(1);
|
|
594
|
+
|
|
595
|
+
This attribute isn't overridden from L<IO::Handle>'s implementation. However,
|
|
596
|
+
since we turn it on by default, it's worth mentioning here.
|
|
597
|
+
|
|
598
|
+
=head2 bind
|
|
599
|
+
|
|
600
|
+
use Socket qw(pack_sockaddr_in);
|
|
601
|
+
my $port = 3000;
|
|
602
|
+
my $ip_address = '0.0.0.0';
|
|
603
|
+
my $packed_addr = pack_sockaddr_in($port, $ip_address);
|
|
604
|
+
$sock->bind($packed_addr);
|
|
605
|
+
|
|
606
|
+
Binds a network address to a socket, just as C<bind(2)> does. Returns true if
|
|
607
|
+
it succeeded, false otherwise. You should provide a packed address of the
|
|
608
|
+
appropriate type for the socket.
|
|
609
|
+
|
|
610
|
+
=head2 connected
|
|
611
|
+
|
|
612
|
+
my $peer_addr = $sock->connected();
|
|
613
|
+
if ($peer_addr) {
|
|
614
|
+
say "We're connected to $peer_addr";
|
|
615
|
+
}
|
|
500
616
|
|
|
501
617
|
If the socket is in a connected state, the peer address is returned. If the
|
|
502
|
-
socket is not in a connected state, undef is returned.
|
|
618
|
+
socket is not in a connected state, C<undef> is returned.
|
|
503
619
|
|
|
504
|
-
Note that
|
|
505
|
-
state". Specifically,
|
|
620
|
+
Note that this method considers a half-open TCP socket to be "in a connected
|
|
621
|
+
state". Specifically, it does not distinguish between the
|
|
506
622
|
B<ESTABLISHED> and B<CLOSE-WAIT> TCP states; it returns the peer address,
|
|
507
|
-
rather than undef
|
|
623
|
+
rather than C<undef>, in either case. Thus, in general, it cannot
|
|
508
624
|
be used to reliably learn whether the peer has initiated a graceful shutdown
|
|
509
625
|
because in most cases (see below) the local TCP state machine remains in
|
|
510
|
-
B<CLOSE-WAIT> until the local application calls shutdown
|
|
511
|
-
|
|
626
|
+
B<CLOSE-WAIT> until the local application calls L<IO::Socket/"shutdown"> or
|
|
627
|
+
C<close>. Only at that point does this function return C<undef>.
|
|
512
628
|
|
|
513
629
|
The "in most cases" hedge is because local TCP state machine behavior may
|
|
514
630
|
depend on the peer's socket options. In particular, if the peer socket has
|
|
515
|
-
SO_LINGER enabled with a zero timeout, then the peer's close
|
|
516
|
-
a RST segment
|
|
517
|
-
B<CLOSED>, and in that state,
|
|
631
|
+
C<SO_LINGER> enabled with a zero timeout, then the peer's C<close> will
|
|
632
|
+
generate a C<RST> segment. Upon receipt of that segment, the local TCP
|
|
633
|
+
transitions immediately to B<CLOSED>, and in that state, this method I<will>
|
|
634
|
+
return C<undef>.
|
|
635
|
+
|
|
636
|
+
=head2 getsockopt
|
|
637
|
+
|
|
638
|
+
my $value = $sock->getsockopt(SOL_SOCKET, SO_REUSEADDR);
|
|
639
|
+
my $buf = $socket->getsockopt(SOL_SOCKET, SO_RCVBUF);
|
|
640
|
+
say "Receive buffer is $buf bytes";
|
|
641
|
+
|
|
642
|
+
Get an option associated with the socket. Levels other than C<SOL_SOCKET>
|
|
643
|
+
may be specified here. As a convenience, this method will unpack a byte buffer
|
|
644
|
+
of the correct size back into a number.
|
|
645
|
+
|
|
646
|
+
=head2 listen
|
|
647
|
+
|
|
648
|
+
$sock->listen(5);
|
|
649
|
+
|
|
650
|
+
Does the same thing that the C<listen(2)> system call does. Returns true if it
|
|
651
|
+
succeeded, false otherwise. Listens to a socket with a given queue size.
|
|
518
652
|
|
|
519
|
-
=
|
|
653
|
+
=head2 peername
|
|
520
654
|
|
|
521
|
-
|
|
522
|
-
|
|
655
|
+
my $sockaddr_in = $sock->peername();
|
|
656
|
+
|
|
657
|
+
Returns the packed C<sockaddr> address of the other end of the socket
|
|
658
|
+
connection. It calls C<getpeername>.
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
=head2 protocol
|
|
662
|
+
|
|
663
|
+
my $proto = $sock->protocol();
|
|
664
|
+
|
|
665
|
+
Returns the number for the protocol being used on the socket, if
|
|
666
|
+
known. If the protocol is unknown, as with an C<AF_UNIX> socket, zero
|
|
523
667
|
is returned.
|
|
524
668
|
|
|
525
|
-
=
|
|
669
|
+
=head2 recv
|
|
670
|
+
|
|
671
|
+
my $buffer = "";
|
|
672
|
+
my $length = 1024;
|
|
673
|
+
my $flags = 0; # default. optional
|
|
674
|
+
$sock->recv($buffer, $length);
|
|
675
|
+
$sock->recv($buffer, $length, $flags);
|
|
526
676
|
|
|
527
|
-
|
|
528
|
-
an AF_INET socket the value of &AF_INET will be returned.
|
|
677
|
+
Similar in functionality to L<perlfunc/recv>.
|
|
529
678
|
|
|
530
|
-
|
|
679
|
+
Receives a message on a socket. Attempts to receive C<$length> characters of
|
|
680
|
+
data into C<$buffer> from the specified socket. C<$buffer> will be grown or
|
|
681
|
+
shrunk to the length actually read. Takes the same flags as the system call of
|
|
682
|
+
the same name. Returns the address of the sender if socket's protocol supports
|
|
683
|
+
this; returns an empty string otherwise. If there's an error, returns
|
|
684
|
+
C<undef>. This call is actually implemented in terms of the C<recvfrom(2)>
|
|
685
|
+
system call.
|
|
531
686
|
|
|
532
|
-
|
|
533
|
-
|
|
687
|
+
Flags are ORed together values, such as C<MSG_BCAST>, C<MSG_OOB>,
|
|
688
|
+
C<MSG_TRUNC>. The default value for the flags is C<0>.
|
|
534
689
|
|
|
535
|
-
|
|
690
|
+
The cached value of L<IO::Socket/"peername"> is updated with the result of
|
|
691
|
+
C<recv>.
|
|
536
692
|
|
|
537
|
-
|
|
538
|
-
|
|
693
|
+
B<Note:> In Perl v5.30 and newer, if the socket has been marked as C<:utf8>,
|
|
694
|
+
C<recv> will throw an exception. The C<:encoding(...)> layer implicitly
|
|
695
|
+
introduces the C<:utf8> layer. See L<perlfunc/binmode>.
|
|
539
696
|
|
|
540
|
-
|
|
697
|
+
B<Note:> In Perl versions older than v5.30, depending on the status of the
|
|
698
|
+
socket, either (8-bit) bytes or characters are received. By default all
|
|
699
|
+
sockets operate on bytes, but for example if the socket has been changed
|
|
700
|
+
using L<perlfunc/binmode> to operate with the C<:encoding(UTF-8)> I/O layer
|
|
701
|
+
(see the L<perlfunc/open> pragma), the I/O will operate on UTF8-encoded
|
|
702
|
+
Unicode characters, not bytes. Similarly for the C<:encoding> layer: in
|
|
703
|
+
that case pretty much any characters can be read.
|
|
541
704
|
|
|
542
|
-
|
|
543
|
-
may be specified here.
|
|
705
|
+
=head2 send
|
|
544
706
|
|
|
545
|
-
=
|
|
707
|
+
my $message = "Hello, world!";
|
|
708
|
+
my $flags = 0; # defaults to zero
|
|
709
|
+
my $to = '0.0.0.0'; # optional destination
|
|
710
|
+
my $sent = $sock->send($message);
|
|
711
|
+
$sent = $sock->send($message, $flags);
|
|
712
|
+
$sent = $sock->send($message, $flags, $to);
|
|
546
713
|
|
|
547
|
-
|
|
548
|
-
a SOCK_STREAM socket the value of &SOCK_STREAM will be returned.
|
|
714
|
+
Similar in functionality to L<perlfunc/send>.
|
|
549
715
|
|
|
550
|
-
|
|
716
|
+
Sends a message on a socket. Attempts to send the scalar message to the
|
|
717
|
+
socket. Takes the same flags as the system call of the same name. On
|
|
718
|
+
unconnected sockets, you must specify a destination to send to, in which case
|
|
719
|
+
it does a C<sendto(2)> syscall. Returns the number of characters sent, or
|
|
720
|
+
C<undef> on error. The C<sendmsg(2)> syscall is currently unimplemented.
|
|
721
|
+
|
|
722
|
+
The C<flags> option is optional and defaults to C<0>.
|
|
723
|
+
|
|
724
|
+
After a successful send with C<$to>, further calls to C<send> on an
|
|
725
|
+
unconnected socket without C<$to> will send to the same address, and C<$to>
|
|
726
|
+
will be used as the result of L<IO::Socket/"peername">.
|
|
727
|
+
|
|
728
|
+
B<Note:> In Perl v5.30 and newer, if the socket has been marked as C<:utf8>,
|
|
729
|
+
C<send> will throw an exception. The C<:encoding(...)> layer implicitly
|
|
730
|
+
introduces the C<:utf8> layer. See L<perlfunc/binmode>.
|
|
731
|
+
|
|
732
|
+
B<Note:> In Perl versions older than v5.30, depending on the status of the
|
|
733
|
+
socket, either (8-bit) bytes or characters are sent. By default all
|
|
734
|
+
sockets operate on bytes, but for example if the socket has been changed
|
|
735
|
+
using L<perlfunc/binmode> to operate with the C<:encoding(UTF-8)> I/O layer
|
|
736
|
+
(see the L<perlfunc/open> pragma), the I/O will operate on UTF8-encoded
|
|
737
|
+
Unicode characters, not bytes. Similarly for the C<:encoding> layer: in
|
|
738
|
+
that case pretty much any characters can be sent.
|
|
739
|
+
|
|
740
|
+
=head2 setsockopt
|
|
741
|
+
|
|
742
|
+
$sock->setsockopt(SOL_SOCKET, SO_REUSEADDR, 1);
|
|
743
|
+
$sock->setsockopt(SOL_SOCKET, SO_RCVBUF, 64*1024);
|
|
744
|
+
|
|
745
|
+
Set option associated with the socket. Levels other than C<SOL_SOCKET>
|
|
746
|
+
may be specified here. As a convenience, this method will convert a number
|
|
747
|
+
into a packed byte buffer.
|
|
748
|
+
|
|
749
|
+
=head2 shutdown
|
|
750
|
+
|
|
751
|
+
$sock->shutdown(SHUT_RD); # we stopped reading data
|
|
752
|
+
$sock->shutdown(SHUT_WR); # we stopped writing data
|
|
753
|
+
$sock->shutdown(SHUT_RDWR); # we stopped using this socket
|
|
754
|
+
|
|
755
|
+
Shuts down a socket connection in the manner indicated by the value passed in,
|
|
756
|
+
which has the same interpretation as in the syscall of the same name.
|
|
757
|
+
|
|
758
|
+
This is useful with sockets when you want to tell the other side you're done
|
|
759
|
+
writing but not done reading, or vice versa. It's also a more insistent form
|
|
760
|
+
of C<close> because it also disables the file descriptor in any
|
|
761
|
+
forked copies in other processes.
|
|
762
|
+
|
|
763
|
+
Returns C<1> for success; on error, returns C<undef> if the socket is
|
|
764
|
+
not a valid filehandle, or returns C<0> and sets C<$!> for any other failure.
|
|
765
|
+
|
|
766
|
+
=head2 sockdomain
|
|
767
|
+
|
|
768
|
+
my $domain = $sock->sockdomain();
|
|
769
|
+
|
|
770
|
+
Returns the number for the socket domain type. For example, for
|
|
771
|
+
an C<AF_INET> socket the value of C<&AF_INET> will be returned.
|
|
772
|
+
|
|
773
|
+
=head2 socket
|
|
774
|
+
|
|
775
|
+
my $sock = IO::Socket->new(); # no values given
|
|
776
|
+
# now let's actually get a socket with the socket method
|
|
777
|
+
# domain, type, and protocol are required
|
|
778
|
+
$sock = $sock->socket(AF_INET, SOCK_STREAM, 'tcp');
|
|
779
|
+
|
|
780
|
+
Opens a socket of the specified kind and returns it. Domain, type, and
|
|
781
|
+
protocol are specified the same as for the syscall of the same name.
|
|
782
|
+
|
|
783
|
+
=head2 socketpair
|
|
784
|
+
|
|
785
|
+
my ($r, $w) = $sock->socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC);
|
|
786
|
+
($r, $w) = IO::Socket::UNIX
|
|
787
|
+
->socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC);
|
|
788
|
+
|
|
789
|
+
Will return a list of two sockets created (read and write), or an empty list
|
|
790
|
+
on failure.
|
|
791
|
+
|
|
792
|
+
Differs slightly from C<socketpair> in L<perlfunc> in that the argument list
|
|
793
|
+
is a bit simpler.
|
|
794
|
+
|
|
795
|
+
=head2 sockname
|
|
796
|
+
|
|
797
|
+
my $packed_addr = $sock->sockname();
|
|
798
|
+
|
|
799
|
+
Returns the packed C<sockaddr> address of this end of the connection. It's the
|
|
800
|
+
same as C<getsockname(2)>.
|
|
801
|
+
|
|
802
|
+
=head2 sockopt
|
|
803
|
+
|
|
804
|
+
my $value = $sock->sockopt(SO_REUSEADDR);
|
|
805
|
+
$sock->sockopt(SO_REUSEADDR, 1);
|
|
806
|
+
|
|
807
|
+
Unified method to both set and get options in the C<SOL_SOCKET> level. If
|
|
808
|
+
called with one argument then L<IO::Socket/"getsockopt"> is called, otherwise
|
|
809
|
+
L<IO::Socket/"setsockopt"> is called.
|
|
810
|
+
|
|
811
|
+
=head2 socktype
|
|
812
|
+
|
|
813
|
+
my $type = $sock->socktype();
|
|
814
|
+
|
|
815
|
+
Returns the number for the socket type. For example, for
|
|
816
|
+
a C<SOCK_STREAM> socket the value of C<&SOCK_STREAM> will be returned.
|
|
817
|
+
|
|
818
|
+
=head2 timeout
|
|
819
|
+
|
|
820
|
+
my $seconds = $sock->timeout();
|
|
821
|
+
my $old_val = $sock->timeout(5); # set new and return old value
|
|
551
822
|
|
|
552
823
|
Set or get the timeout value (in seconds) associated with this socket.
|
|
553
824
|
If called without any arguments then the current setting is returned. If
|
|
554
825
|
called with an argument the current setting is changed and the previous
|
|
555
826
|
value returned.
|
|
556
827
|
|
|
557
|
-
|
|
828
|
+
This method is available to all C<IO::Socket> implementations but may or may
|
|
829
|
+
not be used by the individual domain subclasses.
|
|
830
|
+
|
|
831
|
+
=head1 EXAMPLES
|
|
832
|
+
|
|
833
|
+
Let's create a TCP server on C<localhost:3333>.
|
|
834
|
+
|
|
835
|
+
use strict;
|
|
836
|
+
use warnings;
|
|
837
|
+
use feature 'say';
|
|
838
|
+
|
|
839
|
+
use IO::Socket qw(AF_INET AF_UNIX SOCK_STREAM SHUT_WR);
|
|
840
|
+
|
|
841
|
+
my $server = IO::Socket->new(
|
|
842
|
+
Domain => AF_INET,
|
|
843
|
+
Type => SOCK_STREAM,
|
|
844
|
+
Proto => 'tcp',
|
|
845
|
+
LocalHost => '0.0.0.0',
|
|
846
|
+
LocalPort => 3333,
|
|
847
|
+
ReusePort => 1,
|
|
848
|
+
Listen => 5,
|
|
849
|
+
) || die "Can't open socket: $IO::Socket::errstr";
|
|
850
|
+
say "Waiting on 3333";
|
|
851
|
+
|
|
852
|
+
while (1) {
|
|
853
|
+
# waiting for a new client connection
|
|
854
|
+
my $client = $server->accept();
|
|
855
|
+
|
|
856
|
+
# get information about a newly connected client
|
|
857
|
+
my $client_address = $client->peerhost();
|
|
858
|
+
my $client_port = $client->peerport();
|
|
859
|
+
say "Connection from $client_address:$client_port";
|
|
860
|
+
|
|
861
|
+
# read up to 1024 characters from the connected client
|
|
862
|
+
my $data = "";
|
|
863
|
+
$client->recv($data, 1024);
|
|
864
|
+
say "received data: $data";
|
|
865
|
+
|
|
866
|
+
# write response data to the connected client
|
|
867
|
+
$data = "ok";
|
|
868
|
+
$client->send($data);
|
|
869
|
+
|
|
870
|
+
# notify client that response has been sent
|
|
871
|
+
$client->shutdown(SHUT_WR);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
$server->close();
|
|
875
|
+
|
|
876
|
+
A client for such a server could be
|
|
877
|
+
|
|
878
|
+
use strict;
|
|
879
|
+
use warnings;
|
|
880
|
+
use feature 'say';
|
|
881
|
+
|
|
882
|
+
use IO::Socket qw(AF_INET AF_UNIX SOCK_STREAM SHUT_WR);
|
|
883
|
+
|
|
884
|
+
my $client = IO::Socket->new(
|
|
885
|
+
Domain => AF_INET,
|
|
886
|
+
Type => SOCK_STREAM,
|
|
887
|
+
proto => 'tcp',
|
|
888
|
+
PeerPort => 3333,
|
|
889
|
+
PeerHost => '0.0.0.0',
|
|
890
|
+
) || die "Can't open socket: $IO::Socket::errstr";
|
|
891
|
+
|
|
892
|
+
say "Sending Hello World!";
|
|
893
|
+
my $size = $client->send("Hello World!");
|
|
894
|
+
say "Sent data of length: $size";
|
|
895
|
+
|
|
896
|
+
$client->shutdown(SHUT_WR);
|
|
897
|
+
|
|
898
|
+
my $buffer;
|
|
899
|
+
$client->recv($buffer, 1024);
|
|
900
|
+
say "Got back $buffer";
|
|
901
|
+
|
|
902
|
+
$client->close();
|
|
903
|
+
|
|
558
904
|
|
|
559
905
|
=head1 LIMITATIONS
|
|
560
906
|
|
|
561
|
-
On some systems, for an IO::Socket object created with new_from_fd
|
|
562
|
-
or created with accept
|
|
563
|
-
sockdomain
|
|
907
|
+
On some systems, for an IO::Socket object created with C<new_from_fd>,
|
|
908
|
+
or created with L<IO::Socket/"accept"> from such an object, the
|
|
909
|
+
L<IO::Socket/"protocol">, L<IO::Socket/"sockdomain"> and
|
|
910
|
+
L<IO::Socket/"socktype"> methods may return C<undef>.
|
|
564
911
|
|
|
565
912
|
=head1 SEE ALSO
|
|
566
913
|
|
|
567
|
-
L<Socket>, L<IO::Handle>, L<IO::Socket::INET>, L<IO::Socket::UNIX
|
|
914
|
+
L<Socket>, L<IO::Handle>, L<IO::Socket::INET>, L<IO::Socket::UNIX>,
|
|
915
|
+
L<IO::Socket::IP>
|
|
568
916
|
|
|
569
917
|
=head1 AUTHOR
|
|
570
918
|
|