win32-nio 0.1.1 → 0.1.2
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.
- checksums.yaml +7 -0
- data/CHANGES +27 -21
- data/MANIFEST +13 -13
- data/README +72 -72
- data/Rakefile +51 -46
- data/benchmarks/win32_nio_benchmarks.rb +113 -113
- data/lib/win32/nio.rb +200 -200
- data/lib/win32/windows/constants.rb +72 -72
- data/lib/win32/windows/functions.rb +27 -27
- data/lib/win32/windows/macros.rb +7 -7
- data/lib/win32/windows/structs.rb +39 -39
- data/test/test_win32_nio_read.rb +81 -82
- data/test/test_win32_nio_readlines.rb +66 -66
- data/win32-nio.gemspec +28 -28
- metadata +18 -25
@@ -1,27 +1,27 @@
|
|
1
|
-
require 'ffi'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
module Functions
|
5
|
-
extend FFI::Library
|
6
|
-
typedef :ulong, :dword
|
7
|
-
typedef :uintptr_t, :handle
|
8
|
-
typedef :pointer, :ptr
|
9
|
-
|
10
|
-
ffi_lib :kernel32
|
11
|
-
ffi_convention :stdcall
|
12
|
-
|
13
|
-
attach_function :CloseHandle, [:handle], :bool
|
14
|
-
attach_function :CreateFileA, [:string, :dword, :dword, :ptr, :dword, :dword, :handle], :handle
|
15
|
-
attach_function :CreateFileW, [:buffer_in, :dword, :dword, :ptr, :dword, :dword, :handle], :handle
|
16
|
-
attach_function :GetOverlappedResult, [:handle, :ptr, :ptr, :bool], :bool
|
17
|
-
attach_function :GetSystemInfo, [:ptr], :void
|
18
|
-
attach_function :ReadFile, [:handle, :buffer_out, :dword, :ptr, :ptr], :bool
|
19
|
-
attach_function :ReadFileScatter, [:handle, :ptr, :dword, :ptr, :ptr], :bool
|
20
|
-
attach_function :SleepEx, [:dword, :bool], :dword
|
21
|
-
attach_function :VirtualAlloc, [:ptr, :size_t, :dword, :dword], :dword
|
22
|
-
attach_function :VirtualFree, [:dword, :size_t, :dword], :bool
|
23
|
-
|
24
|
-
callback :completion_function, [:dword, :dword, :ptr], :void
|
25
|
-
attach_function :ReadFileEx, [:handle, :buffer_out, :dword, :ptr, :completion_function], :bool
|
26
|
-
end
|
27
|
-
end
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module Functions
|
5
|
+
extend FFI::Library
|
6
|
+
typedef :ulong, :dword
|
7
|
+
typedef :uintptr_t, :handle
|
8
|
+
typedef :pointer, :ptr
|
9
|
+
|
10
|
+
ffi_lib :kernel32
|
11
|
+
ffi_convention :stdcall
|
12
|
+
|
13
|
+
attach_function :CloseHandle, [:handle], :bool
|
14
|
+
attach_function :CreateFileA, [:string, :dword, :dword, :ptr, :dword, :dword, :handle], :handle
|
15
|
+
attach_function :CreateFileW, [:buffer_in, :dword, :dword, :ptr, :dword, :dword, :handle], :handle
|
16
|
+
attach_function :GetOverlappedResult, [:handle, :ptr, :ptr, :bool], :bool
|
17
|
+
attach_function :GetSystemInfo, [:ptr], :void
|
18
|
+
attach_function :ReadFile, [:handle, :buffer_out, :dword, :ptr, :ptr], :bool
|
19
|
+
attach_function :ReadFileScatter, [:handle, :ptr, :dword, :ptr, :ptr], :bool
|
20
|
+
attach_function :SleepEx, [:dword, :bool], :dword
|
21
|
+
attach_function :VirtualAlloc, [:ptr, :size_t, :dword, :dword], :dword
|
22
|
+
attach_function :VirtualFree, [:dword, :size_t, :dword], :bool
|
23
|
+
|
24
|
+
callback :completion_function, [:dword, :dword, :ptr], :void
|
25
|
+
attach_function :ReadFileEx, [:handle, :buffer_out, :dword, :ptr, :completion_function], :bool
|
26
|
+
end
|
27
|
+
end
|
data/lib/win32/windows/macros.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
module Windows
|
2
|
-
module Macros
|
3
|
-
def HasOverlappedIoCompleted(overlapped)
|
4
|
-
overlapped[:Internal] != 259 # STATUS_PENDING
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
1
|
+
module Windows
|
2
|
+
module Macros
|
3
|
+
def HasOverlappedIoCompleted(overlapped)
|
4
|
+
overlapped[:Internal] != 259 # STATUS_PENDING
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
@@ -1,39 +1,39 @@
|
|
1
|
-
require 'ffi'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
module Structs
|
5
|
-
extend FFI::Library
|
6
|
-
|
7
|
-
# I'm assuming the anonymous struct for the internal union here.
|
8
|
-
class Overlapped < FFI::Struct
|
9
|
-
layout(
|
10
|
-
:Internal, :
|
11
|
-
:InternalHigh, :
|
12
|
-
:Offset, :ulong,
|
13
|
-
:OffsetHigh, :ulong,
|
14
|
-
:hEvent, :
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
# dwOemId is deprecated. Just assume the nested struct.
|
19
|
-
class SystemInfo < FFI::Struct
|
20
|
-
layout(
|
21
|
-
:wProcessorArchitecture, :ushort,
|
22
|
-
:wReserved, :ushort,
|
23
|
-
:dwPageSize, :ulong,
|
24
|
-
:lpMinimumApplicationAddress, :pointer,
|
25
|
-
:lpMaximumApplicationAddress, :pointer,
|
26
|
-
:dwActiveProcessorMask, :pointer,
|
27
|
-
:dwNumberOfProcessors, :ulong,
|
28
|
-
:dwProcessorType, :ulong,
|
29
|
-
:dwAllocationGranularity, :ulong,
|
30
|
-
:wProcessorLevel, :ushort,
|
31
|
-
:wProcessorRevision, :ushort
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
class FileSegmentElement < FFI::Union
|
36
|
-
layout(:Buffer, :pointer, :Alignment, :uint64)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module Structs
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
# I'm assuming the anonymous struct for the internal union here.
|
8
|
+
class Overlapped < FFI::Struct
|
9
|
+
layout(
|
10
|
+
:Internal, :uintptr_t,
|
11
|
+
:InternalHigh, :uintptr_t,
|
12
|
+
:Offset, :ulong,
|
13
|
+
:OffsetHigh, :ulong,
|
14
|
+
:hEvent, :uintptr_t
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
# dwOemId is deprecated. Just assume the nested struct.
|
19
|
+
class SystemInfo < FFI::Struct
|
20
|
+
layout(
|
21
|
+
:wProcessorArchitecture, :ushort,
|
22
|
+
:wReserved, :ushort,
|
23
|
+
:dwPageSize, :ulong,
|
24
|
+
:lpMinimumApplicationAddress, :pointer,
|
25
|
+
:lpMaximumApplicationAddress, :pointer,
|
26
|
+
:dwActiveProcessorMask, :pointer,
|
27
|
+
:dwNumberOfProcessors, :ulong,
|
28
|
+
:dwProcessorType, :ulong,
|
29
|
+
:dwAllocationGranularity, :ulong,
|
30
|
+
:wProcessorLevel, :ushort,
|
31
|
+
:wProcessorRevision, :ushort
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
class FileSegmentElement < FFI::Union
|
36
|
+
layout(:Buffer, :pointer, :Alignment, :uint64)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/test/test_win32_nio_read.rb
CHANGED
@@ -1,82 +1,81 @@
|
|
1
|
-
########################################################################
|
2
|
-
# test_win32_nio_read.rb
|
3
|
-
#
|
4
|
-
# Tests for the NIO.read method.
|
5
|
-
########################################################################
|
6
|
-
require 'test-unit'
|
7
|
-
require 'win32/nio'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@@
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
p
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
assert_equal('
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
assert_equal('
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
assert_raise(
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
assert_raise(
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
@@
|
80
|
-
|
81
|
-
|
82
|
-
end
|
1
|
+
########################################################################
|
2
|
+
# test_win32_nio_read.rb
|
3
|
+
#
|
4
|
+
# Tests for the NIO.read method.
|
5
|
+
########################################################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'win32/nio'
|
8
|
+
include Win32
|
9
|
+
|
10
|
+
class TC_Win32_NIO_Read < Test::Unit::TestCase
|
11
|
+
def self.startup
|
12
|
+
Dir.chdir(File.expand_path(File.dirname(__FILE__)))
|
13
|
+
|
14
|
+
@@file = 'read_test.txt'
|
15
|
+
@@text = "The quick brown fox jumped over the lazy dog's back"
|
16
|
+
|
17
|
+
File.open(@@file, 'w'){ |fh|
|
18
|
+
100.times{ |n| fh.puts @@text + ": #{n}" }
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@size = File.size(@@file)
|
24
|
+
end
|
25
|
+
|
26
|
+
test "version number is set to expected value" do
|
27
|
+
assert_equal('0.1.2', Win32::NIO::VERSION)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "read method basic functionality" do
|
31
|
+
assert_respond_to(NIO, :read)
|
32
|
+
assert_nothing_raised{ NIO.read(@@file) }
|
33
|
+
end
|
34
|
+
|
35
|
+
test "read method accepts a file name and returns a string of the expected size" do
|
36
|
+
assert_kind_of(String, NIO.read(@@file))
|
37
|
+
p @size
|
38
|
+
p NIO.read(@@file).size
|
39
|
+
assert_true(NIO.read(@@file).size == @size)
|
40
|
+
end
|
41
|
+
|
42
|
+
test "read method accepts a length argument and returns a string of that length" do
|
43
|
+
assert_nothing_raised{ NIO.read(@@file, 19) }
|
44
|
+
assert_equal('The quick brown fox', NIO.read(@@file, 19))
|
45
|
+
assert_equal('', NIO.read(@@file, 0))
|
46
|
+
end
|
47
|
+
|
48
|
+
test "read method accepts an offset and returns a string between offset and length" do
|
49
|
+
assert_nothing_raised{ NIO.read(@@file, 19, 4) }
|
50
|
+
assert_equal('quick brown fox', NIO.read(@@file, 15, 4))
|
51
|
+
assert_equal("lazy dog's back: 99\r\n", NIO.read(@@file, nil, @size-21))
|
52
|
+
end
|
53
|
+
|
54
|
+
test "read method requires at least one argument" do
|
55
|
+
assert_raise(ArgumentError){ NIO.read }
|
56
|
+
end
|
57
|
+
|
58
|
+
test "length parameter must be a positive number" do
|
59
|
+
assert_raise(ArgumentError){ NIO.read(@@file, -1) }
|
60
|
+
assert_raise(TypeError){ NIO.read(@@file, 'foo') }
|
61
|
+
end
|
62
|
+
|
63
|
+
test "offset parameter must be a positive number" do
|
64
|
+
assert_raise(Errno::EINVAL, Errno::ENAMETOOLONG){ NIO.read(@@file, 1, -1) }
|
65
|
+
assert_raise(TypeError){ NIO.read(@@file, 1, 'foo') }
|
66
|
+
end
|
67
|
+
|
68
|
+
test "options parameter must be a hash" do
|
69
|
+
assert_raise(TypeError){ NIO.read(@@file, 1, 1, 'foo') }
|
70
|
+
end
|
71
|
+
|
72
|
+
def teardown
|
73
|
+
@size = nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.shutdown
|
77
|
+
File.delete(@@file) if File.exists?(@@file)
|
78
|
+
@@file = nil
|
79
|
+
@@text = nil
|
80
|
+
end
|
81
|
+
end
|
@@ -1,66 +1,66 @@
|
|
1
|
-
#######################################################################
|
2
|
-
# test_win32_nio_readlines.rb
|
3
|
-
#
|
4
|
-
# Test case for the Win32::NIO.readlines method.
|
5
|
-
#######################################################################
|
6
|
-
require 'test-unit'
|
7
|
-
require 'win32/nio'
|
8
|
-
include Win32
|
9
|
-
|
10
|
-
class TC_Win32_NIO_Readlines < Test::Unit::TestCase
|
11
|
-
def self.startup
|
12
|
-
@@line = "The quick brown fox jumped over the lazy dog's back"
|
13
|
-
@@file = "readlines_test.txt"
|
14
|
-
@@size = 10
|
15
|
-
|
16
|
-
File.open(@@file, 'w'){ |fh|
|
17
|
-
1.upto(@@size){ |n|
|
18
|
-
fh.puts @@line + ": #{n}"
|
19
|
-
fh.puts if n % 3 == 0
|
20
|
-
}
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
def setup
|
25
|
-
@array = nil
|
26
|
-
end
|
27
|
-
|
28
|
-
test "readlines method basic functionality" do
|
29
|
-
assert_respond_to(NIO, :readlines)
|
30
|
-
assert_nothing_raised{ NIO.readlines(@@file) }
|
31
|
-
end
|
32
|
-
|
33
|
-
test "readlines returns an array" do
|
34
|
-
assert_kind_of(Array, NIO.readlines(@@file))
|
35
|
-
end
|
36
|
-
|
37
|
-
test "readlines returns an array of the expected size" do
|
38
|
-
assert_equal(@@size + 3, NIO.readlines(@@file).size)
|
39
|
-
assert_equal(@@line + ': 1', NIO.readlines(@@file).first)
|
40
|
-
end
|
41
|
-
|
42
|
-
test "readlines treats an empty second argument as a paragraph separator" do
|
43
|
-
assert_nothing_raised{ NIO.readlines(@@file, '') }
|
44
|
-
assert_kind_of(Array, NIO.readlines(@@file, ''))
|
45
|
-
assert_equal(4, NIO.readlines(@@file, '').size)
|
46
|
-
end
|
47
|
-
|
48
|
-
test "readlines expects at least one argument" do
|
49
|
-
assert_raise(ArgumentError){ NIO.readlines }
|
50
|
-
end
|
51
|
-
|
52
|
-
test "readlines accepts a maximum of two arguments" do
|
53
|
-
assert_raise(ArgumentError){ NIO.readlines(@@file, '', true) }
|
54
|
-
end
|
55
|
-
|
56
|
-
def teardown
|
57
|
-
@array = nil
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.shutdown
|
61
|
-
File.delete(@@file) if File.exists?(@@file)
|
62
|
-
@@file = nil
|
63
|
-
@@size = nil
|
64
|
-
@@line = nil
|
65
|
-
end
|
66
|
-
end
|
1
|
+
#######################################################################
|
2
|
+
# test_win32_nio_readlines.rb
|
3
|
+
#
|
4
|
+
# Test case for the Win32::NIO.readlines method.
|
5
|
+
#######################################################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'win32/nio'
|
8
|
+
include Win32
|
9
|
+
|
10
|
+
class TC_Win32_NIO_Readlines < Test::Unit::TestCase
|
11
|
+
def self.startup
|
12
|
+
@@line = "The quick brown fox jumped over the lazy dog's back"
|
13
|
+
@@file = "readlines_test.txt"
|
14
|
+
@@size = 10
|
15
|
+
|
16
|
+
File.open(@@file, 'w'){ |fh|
|
17
|
+
1.upto(@@size){ |n|
|
18
|
+
fh.puts @@line + ": #{n}"
|
19
|
+
fh.puts if n % 3 == 0
|
20
|
+
}
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@array = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
test "readlines method basic functionality" do
|
29
|
+
assert_respond_to(NIO, :readlines)
|
30
|
+
assert_nothing_raised{ NIO.readlines(@@file) }
|
31
|
+
end
|
32
|
+
|
33
|
+
test "readlines returns an array" do
|
34
|
+
assert_kind_of(Array, NIO.readlines(@@file))
|
35
|
+
end
|
36
|
+
|
37
|
+
test "readlines returns an array of the expected size" do
|
38
|
+
assert_equal(@@size + 3, NIO.readlines(@@file).size)
|
39
|
+
assert_equal(@@line + ': 1', NIO.readlines(@@file).first)
|
40
|
+
end
|
41
|
+
|
42
|
+
test "readlines treats an empty second argument as a paragraph separator" do
|
43
|
+
assert_nothing_raised{ NIO.readlines(@@file, '') }
|
44
|
+
assert_kind_of(Array, NIO.readlines(@@file, ''))
|
45
|
+
assert_equal(4, NIO.readlines(@@file, '').size)
|
46
|
+
end
|
47
|
+
|
48
|
+
test "readlines expects at least one argument" do
|
49
|
+
assert_raise(ArgumentError){ NIO.readlines }
|
50
|
+
end
|
51
|
+
|
52
|
+
test "readlines accepts a maximum of two arguments" do
|
53
|
+
assert_raise(ArgumentError){ NIO.readlines(@@file, '', true) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def teardown
|
57
|
+
@array = nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.shutdown
|
61
|
+
File.delete(@@file) if File.exists?(@@file)
|
62
|
+
@@file = nil
|
63
|
+
@@size = nil
|
64
|
+
@@line = nil
|
65
|
+
end
|
66
|
+
end
|
data/win32-nio.gemspec
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = 'win32-nio'
|
5
|
-
spec.version = '0.1.
|
6
|
-
spec.author = 'Daniel J. Berger'
|
7
|
-
spec.license = 'Artistic 2.0'
|
8
|
-
spec.email = 'djberg96@gmail.com'
|
9
|
-
spec.homepage = 'https://github.com/djberg96/win32-nio'
|
10
|
-
spec.summary = 'Native IO for MS Windows'
|
11
|
-
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
12
|
-
|
13
|
-
spec.rubyforge_project = 'Win32Utils'
|
14
|
-
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
15
|
-
spec.required_ruby_version = '> 1.9.0'
|
16
|
-
|
17
|
-
spec.add_dependency('ffi')
|
18
|
-
spec.add_dependency('win32-event', '>= 0.6.0')
|
19
|
-
|
20
|
-
spec.add_development_dependency('test-unit')
|
21
|
-
|
22
|
-
spec.description = <<-EOF
|
23
|
-
The win32-nio library implements certain IO methods using native
|
24
|
-
Windows function calls rather than using the POSIX compatibility
|
25
|
-
layer that MRI typically uses. In addition, some methods provide
|
26
|
-
additional event handling capability.
|
27
|
-
EOF
|
28
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'win32-nio'
|
5
|
+
spec.version = '0.1.2'
|
6
|
+
spec.author = 'Daniel J. Berger'
|
7
|
+
spec.license = 'Artistic 2.0'
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'https://github.com/djberg96/win32-nio'
|
10
|
+
spec.summary = 'Native IO for MS Windows'
|
11
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
12
|
+
|
13
|
+
spec.rubyforge_project = 'Win32Utils'
|
14
|
+
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
15
|
+
spec.required_ruby_version = '> 1.9.0'
|
16
|
+
|
17
|
+
spec.add_dependency('ffi')
|
18
|
+
spec.add_dependency('win32-event', '>= 0.6.0')
|
19
|
+
|
20
|
+
spec.add_development_dependency('test-unit')
|
21
|
+
|
22
|
+
spec.description = <<-EOF
|
23
|
+
The win32-nio library implements certain IO methods using native
|
24
|
+
Windows function calls rather than using the POSIX compatibility
|
25
|
+
layer that MRI typically uses. In addition, some methods provide
|
26
|
+
additional event handling capability.
|
27
|
+
EOF
|
28
|
+
end
|