win32-ipc 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a0fb961ace49570d4c0c84673bc43605f28ae19
4
- data.tar.gz: b54367734e092429c80446442234a8fe7256053a
3
+ metadata.gz: 944acf1e2f12b1cc3846b14d327ce6661876b820
4
+ data.tar.gz: 8b75202d9ded7365795ad9cd06aac0cad9c0b8c1
5
5
  SHA512:
6
- metadata.gz: ace9c431153c0423a37e08d4f9ba38691408afba3c2c30099105ccee29cb8461f09d01e20498121dee6d5c29e60ca437a44ac5febf180e962b1f5d4e87ac1124
7
- data.tar.gz: f0b04fe9a4fd2deb0ea157882f0e3d58fa944bfe3857d59387553fb86d08a1766516fc39b3f141a6dc791445cf588c7f6ba3c455fa99fae5add1c324446328f2
6
+ metadata.gz: e649133be67ba41f5fd9227d66362eb7a95588c9fb26cd3b426cf70065ed759f09c9fd7b7ab542d37671e203a7f1d47da8f4d08e50692509186d27aa78d5d787
7
+ data.tar.gz: 9b3502e7f1418861f83c0558b7d72073082467a38fa675a3584c0bc635a650bfdade68abe5b86089cf09b112f3c8c80e987bfad8d8e39d97742d93e513d30606
@@ -0,0 +1 @@
1
+ �f�=5-��I�՘�\��ac~Y��?8 etn�w�����nd7�A�<����ɄR�KPe`���k���K�l+�a<��P���\���O* ��C�~bN!`�����������//�M�Q]Ie��inhd�\&�����D�z��|Ҏ���ߜ oP)v|ު�oP!㵂JX����+K뇐7�:V�$�L]��H]N��R ��MQ�}'�N�T�v�Nq�D�
@@ -0,0 +1,4 @@
1
+ �a�M�'�ۗ�����Ck�ڀn`�9�}�uq�����&���
2
+ �tM�~8�+��k�
3
+ ���{����҉Uۘuks����R'�
4
+ �+�iӆR�D�[�)��B�k���=D�K��ٟ��V�C�ɓ���m�ʐ�N��g{���!&U�4X>���*T%��C����2�i�몆����(�űݮC<����C���L�Y�b_�IO�W���{ ή5�$�$Pw#U��Fk�z]�M�����?֯�x�����
data/CHANGES CHANGED
@@ -1,89 +1,93 @@
1
- == 0.6.5 - 7-Jul-2015
2
- * Fixed the wait_for_multiple method for x64 platforms. Thanks go to Rafal
3
- Bigaj for the spot and patch.
4
-
5
- == 0.6.4 - 1-Jul-2015
6
- * Fixed boolean argument type parameter. Thanks go to Rafal Bigaj for the patch.
7
- * Updates to gemspec and Rakefile.
8
-
9
- == 0.6.3 - 10-Jan-2015
10
- * Declare the FFI prototype for WaitForSingleObject as blocking.
11
-
12
- == 0.6.2 - 10-Jan-2015
13
- * Declare the FFI prototype for WaitForMultipleObjects as blocking.
14
-
15
- == 0.6.1 - 9-Apr-2013
16
- * Updated the HANDLE function prototypes in the underlying FFI code. This
17
- affects 64 bit versions of Ruby.
18
-
19
- == 0.6.0 - 8-Jul-2012
20
- * Now uses FFI instead of win32-api.
21
- * The #signaled? method now has a meaningful default implementation.
22
- * If an internal C function fails it raises a SystemCallError (Errno) instead
23
- of an Ipc::Error.
24
- * The Ipc::Error class, although defined for those who wish to still use it
25
- in inherited classes, is no longer used internally.
26
-
27
- == 0.5.3 - 19-Apr-2010
28
- * Added a few gem related tasks to the Rakefile, and removed an old install
29
- task.
30
- * Removed the inline gem building code from the gemspec. That's now handled
31
- by a Rake task.
32
- * Some cosmetic changes to the source code.
33
-
34
- == 0.5.2 - 6-Aug-2009
35
- * License changed to Artistic 2.0.
36
- * Some gemspec updates, including an updated description and adding a
37
- license attribute.
38
- * Renamed the test file to test_win32_ipc.rb.
39
-
40
- == 0.5.1 - 1-Jan-2008
41
- * Fixed bugs in the private wait_for_multiple method. Thanks go to an
42
- anonymous user for the spot and the patch.
43
- * Removed the install.rb file. Installation was merged into the Rakefile.
44
- * Updated the MANIFEST.
45
-
46
- == 0.5.0 - 30-Apr-2007
47
- * Now pure Ruby.
48
- * Ipc.new no longer accepts a block.
49
- * Changed IpcError to Ipc::Error.
50
- * Removed the 'doc' directory. The documentation is now inlined via rdoc.
51
- * Added a gemspec.
52
- * Added a Rakefile, including tasks for installation and testing.
53
-
54
- == 0.4.1 - 23-Jan-2005
55
- * Minor internal modifications for handling block arguments.
56
-
57
- == 0.4.0 - 16-Dec-2004
58
- * Changed the timeout from milliseconds to seconds. This wasn't documented,
59
- and I'm guessing most people didn't know that they were passing milliseconds
60
- instead of seconds. But, I've bumped the version number, just in case.
61
-
62
- == 0.3.1 - 11-Dec-2004
63
- * Fixed a bug in Ipc#wait where a segfault would occur if a block was not
64
- provided.
65
- * Moved the 'examples' directory to the toplevel directory.
66
-
67
- == 0.3.0 - 31-Oct-2004
68
- * The constructor now takes an optional block. Instance objects will call
69
- that block if they are signaled.
70
- * Added the 'block' method (read-only). Allows you to access the block
71
- provided to the constructor.
72
- * Modified the 'wait' instance method to take an optional block. This block
73
- will be called if the object is signaled. Overrides the block to the
74
- constructor for that instance object (only).
75
- * Added the 'signaled?' instance method to indicate if the object is in the
76
- signaled state or not.
77
- * Modified all methods to raise an IpcError if an error occurs (instead of
78
- simply returning nil).
79
- * Added internal comments in order to make the code rdoc friendly, including
80
- changes to the README file.
81
-
82
- == 0.2.0 - 15-Jul-2004
83
- * Updated to use the newer allocation framework. This means that as of
84
- version 0.2.0, this package requires Ruby 1.8.0 or later.
85
- * Moved the test.rb script to docs/examples.
86
- * Minor code cleanup
87
-
88
- == 0.1.0 - 30-Apr-2004
89
- * Initial release
1
+ == 0.6.6 - 13-Sep-2015
2
+ * The gem is now signed.
3
+ * Added the win32-ipc.rb file for convenience.
4
+
5
+ == 0.6.5 - 7-Jul-2015
6
+ * Fixed the wait_for_multiple method for x64 platforms. Thanks go to Rafal
7
+ Bigaj for the spot and patch.
8
+
9
+ == 0.6.4 - 1-Jul-2015
10
+ * Fixed boolean argument type parameter. Thanks go to Rafal Bigaj for the patch.
11
+ * Updates to gemspec and Rakefile.
12
+
13
+ == 0.6.3 - 10-Jan-2015
14
+ * Declare the FFI prototype for WaitForSingleObject as blocking.
15
+
16
+ == 0.6.2 - 10-Jan-2015
17
+ * Declare the FFI prototype for WaitForMultipleObjects as blocking.
18
+
19
+ == 0.6.1 - 9-Apr-2013
20
+ * Updated the HANDLE function prototypes in the underlying FFI code. This
21
+ affects 64 bit versions of Ruby.
22
+
23
+ == 0.6.0 - 8-Jul-2012
24
+ * Now uses FFI instead of win32-api.
25
+ * The #signaled? method now has a meaningful default implementation.
26
+ * If an internal C function fails it raises a SystemCallError (Errno) instead
27
+ of an Ipc::Error.
28
+ * The Ipc::Error class, although defined for those who wish to still use it
29
+ in inherited classes, is no longer used internally.
30
+
31
+ == 0.5.3 - 19-Apr-2010
32
+ * Added a few gem related tasks to the Rakefile, and removed an old install
33
+ task.
34
+ * Removed the inline gem building code from the gemspec. That's now handled
35
+ by a Rake task.
36
+ * Some cosmetic changes to the source code.
37
+
38
+ == 0.5.2 - 6-Aug-2009
39
+ * License changed to Artistic 2.0.
40
+ * Some gemspec updates, including an updated description and adding a
41
+ license attribute.
42
+ * Renamed the test file to test_win32_ipc.rb.
43
+
44
+ == 0.5.1 - 1-Jan-2008
45
+ * Fixed bugs in the private wait_for_multiple method. Thanks go to an
46
+ anonymous user for the spot and the patch.
47
+ * Removed the install.rb file. Installation was merged into the Rakefile.
48
+ * Updated the MANIFEST.
49
+
50
+ == 0.5.0 - 30-Apr-2007
51
+ * Now pure Ruby.
52
+ * Ipc.new no longer accepts a block.
53
+ * Changed IpcError to Ipc::Error.
54
+ * Removed the 'doc' directory. The documentation is now inlined via rdoc.
55
+ * Added a gemspec.
56
+ * Added a Rakefile, including tasks for installation and testing.
57
+
58
+ == 0.4.1 - 23-Jan-2005
59
+ * Minor internal modifications for handling block arguments.
60
+
61
+ == 0.4.0 - 16-Dec-2004
62
+ * Changed the timeout from milliseconds to seconds. This wasn't documented,
63
+ and I'm guessing most people didn't know that they were passing milliseconds
64
+ instead of seconds. But, I've bumped the version number, just in case.
65
+
66
+ == 0.3.1 - 11-Dec-2004
67
+ * Fixed a bug in Ipc#wait where a segfault would occur if a block was not
68
+ provided.
69
+ * Moved the 'examples' directory to the toplevel directory.
70
+
71
+ == 0.3.0 - 31-Oct-2004
72
+ * The constructor now takes an optional block. Instance objects will call
73
+ that block if they are signaled.
74
+ * Added the 'block' method (read-only). Allows you to access the block
75
+ provided to the constructor.
76
+ * Modified the 'wait' instance method to take an optional block. This block
77
+ will be called if the object is signaled. Overrides the block to the
78
+ constructor for that instance object (only).
79
+ * Added the 'signaled?' instance method to indicate if the object is in the
80
+ signaled state or not.
81
+ * Modified all methods to raise an IpcError if an error occurs (instead of
82
+ simply returning nil).
83
+ * Added internal comments in order to make the code rdoc friendly, including
84
+ changes to the README file.
85
+
86
+ == 0.2.0 - 15-Jul-2004
87
+ * Updated to use the newer allocation framework. This means that as of
88
+ version 0.2.0, this package requires Ruby 1.8.0 or later.
89
+ * Moved the test.rb script to docs/examples.
90
+ * Minor code cleanup
91
+
92
+ == 0.1.0 - 30-Apr-2004
93
+ * Initial release
data/MANIFEST CHANGED
@@ -1,7 +1,7 @@
1
- * CHANGES
2
- * MANIFEST
3
- * README
4
- * Rakefile
5
- * win32-ipc.gemspec
6
- * lib/win32/ipc.rb
1
+ * CHANGES
2
+ * MANIFEST
3
+ * README
4
+ * Rakefile
5
+ * win32-ipc.gemspec
6
+ * lib/win32/ipc.rb
7
7
  * test/test_win32_ipc.rb
data/README CHANGED
@@ -1,33 +1,33 @@
1
- = Description
2
- An abstract base class for Windows synchronization objects.
3
-
4
- = Installation
5
- gem install win32-ipc
6
-
7
- = Synopsis
8
- There is no synopsis. Don't use this library directly. It is used as the basis
9
- for other libraries, such as win32-mutex, etc. Think of it as an interface.
10
-
11
- = Notes
12
- Originally based on the Win32::Ipc Perl module by Gurusamy Sarathy.
13
-
14
- This library is a prerequisite for several other IPC related Windows gems.
15
-
16
- = Known Bugs
17
- None that I know of. Please log any other bug reports on the project page
18
- at https://github.com/djberg96/win32-ipc.
19
-
20
- = License
21
- Artistic 2.0
22
-
23
- = Copyright
24
- (C) 2003-2015 Daniel J. Berger, All Rights Reserved
25
-
26
- = Warranty
27
- This package is provided "as is" and without any express or
28
- implied warranties, including, without limitation, the implied
29
- warranties of merchantability and fitness for a particular purpose.
30
-
31
- = Authors
32
- * Park Heesob
33
- * Daniel J. Berger
1
+ = Description
2
+ An abstract base class for Windows synchronization objects.
3
+
4
+ = Installation
5
+ gem install win32-ipc
6
+
7
+ = Synopsis
8
+ There is no synopsis. Don't use this library directly. It is used as the basis
9
+ for other libraries, such as win32-mutex, etc. Think of it as an interface.
10
+
11
+ = Notes
12
+ Originally based on the Win32::Ipc Perl module by Gurusamy Sarathy.
13
+
14
+ This library is a prerequisite for several other IPC related Windows gems.
15
+
16
+ = Known Bugs
17
+ None that I know of. Please log any other bug reports on the project page
18
+ at https://github.com/djberg96/win32-ipc.
19
+
20
+ = License
21
+ Artistic 2.0
22
+
23
+ = Copyright
24
+ (C) 2003-2015 Daniel J. Berger, All Rights Reserved
25
+
26
+ = Warranty
27
+ This package is provided "as is" and without any express or
28
+ implied warranties, including, without limitation, the implied
29
+ warranties of merchantability and fitness for a particular purpose.
30
+
31
+ = Authors
32
+ * Park Heesob
33
+ * Daniel J. Berger
data/Rakefile CHANGED
@@ -1,27 +1,28 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/clean'
4
-
5
- CLEAN.include("**/*.gem", "**/*.rbc")
6
-
7
- namespace 'gem' do
8
- desc 'Create the win32-ipc gem'
9
- task :create => [:clean] do
10
- require 'rubygems/package'
11
- spec = eval(IO.read('win32-ipc.gemspec'))
12
- Gem::Package.build(spec)
13
- end
14
-
15
- desc 'Install the win32-ipc gem'
16
- task :install => [:create] do
17
- file = Dir['*.gem'].first
18
- sh "gem install -l #{file}"
19
- end
20
- end
21
-
22
- Rake::TestTask.new do |t|
23
- t.verbose = true
24
- t.warning = true
25
- end
26
-
27
- task :default => :test
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+
5
+ CLEAN.include("**/*.gem", "**/*.rbc")
6
+
7
+ namespace 'gem' do
8
+ desc 'Create the win32-ipc gem'
9
+ task :create => [:clean] do
10
+ require 'rubygems/package'
11
+ spec = eval(IO.read('win32-ipc.gemspec'))
12
+ spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
+ Gem::Package.build(spec)
14
+ end
15
+
16
+ desc 'Install the win32-ipc gem'
17
+ task :install => [:create] do
18
+ file = Dir['*.gem'].first
19
+ sh "gem install -l #{file}"
20
+ end
21
+ end
22
+
23
+ Rake::TestTask.new do |t|
24
+ t.verbose = true
25
+ t.warning = true
26
+ end
27
+
28
+ task :default => :test
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkamJl
3
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
4
+ MB4XDTE1MDkwMjIwNDkxOFoXDTE2MDkwMTIwNDkxOFowPzERMA8GA1UEAwwIZGpi
5
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
6
+ bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyTkvXqRp6hLs9eoJOS
7
+ Hmi8kRYbq9Vkf15/hMxJpotYMgJVHHWrmDcC5Dye2PbnXjTkKf266Zw0PtT9h+lI
8
+ S3ts9HO+vaCFSMwFFZmnWJSpQ3CNw2RcHxjWkk9yF7imEM8Kz9ojhiDXzBetdV6M
9
+ gr0lV/alUr7TNVBDngbXEfTWscyXh1qd7xZ4EcOdsDktCe5G45N/o3662tPQvJsi
10
+ FOF0CM/KuBsa/HL1/eoEmF4B3EKIRfTHrQ3hu20Kv3RJ88QM4ec2+0dd97uX693O
11
+ zv6981fyEg+aXLkxrkViM/tz2qR2ZE0jPhHTREPYeMEgptRkTmWSKAuLVWrJEfgl
12
+ DtkCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFEwe
13
+ nn6bfJADmuIDiMSOzedOrL+xMB0GA1UdEQQWMBSBEmRqYmVyZzk2QGdtYWlsLmNv
14
+ bTAdBgNVHRIEFjAUgRJkamJlcmc5NkBnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD
15
+ ggEBAHmNOCWoDVD75zHFueY0viwGDVP1BNGFC+yXcb7u2GlK+nEMCORqzURbYPf7
16
+ tL+/hzmePIRz7i30UM//64GI1NLv9jl7nIwjhPpXpf7/lu2I9hOTsvwSumb5UiKC
17
+ /sqBxI3sfj9pr79Wpv4MuikX1XPik7Ncb7NPsJPw06Lvyc3Hkg5X2XpPtLtS+Gr2
18
+ wKJnmzb5rIPS1cmsqv0M9LPWflzfwoZ/SpnmhagP+g05p8bRNKjZSA2iImM/GyYZ
19
+ EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
20
+ tGSHgAmcLlkdGgan182qsE/4kKM=
21
+ -----END CERTIFICATE-----
@@ -0,0 +1 @@
1
+ require_relative 'win32/ipc'
@@ -1,185 +1,185 @@
1
- require 'ffi'
2
-
3
- # The Win32 module serves as a namespace only.
4
- module Win32
5
-
6
- # This is a an abstract base class for IPC related classes, such as
7
- # Events and Semaphores.
8
- #
9
- class Ipc
10
- extend FFI::Library
11
- typedef :ulong, :dword
12
- typedef :uintptr_t, :handle
13
-
14
- ffi_lib :kernel32
15
-
16
- attach_function :CloseHandle, [:handle], :bool
17
- attach_function :WaitForSingleObject, [:handle, :dword], :dword, :blocking => true
18
- attach_function :WaitForMultipleObjects, [:dword, :pointer, :bool, :dword], :dword, :blocking => true
19
-
20
- private_class_method :CloseHandle, :WaitForSingleObject, :WaitForMultipleObjects
21
-
22
- # The version of the win32-ipc library
23
- VERSION = '0.6.5'
24
-
25
- SIGNALED = 1
26
- ABANDONED = -1
27
- TIMEOUT = 0
28
- INFINITE = 0xFFFFFFFF
29
-
30
- WAIT_OBJECT_0 = 0
31
- WAIT_TIMEOUT = 0x102
32
- WAIT_ABANDONED = 128
33
- WAIT_ABANDONED_0 = WAIT_ABANDONED
34
- WAIT_FAILED = 0xFFFFFFFF
35
-
36
- # The HANDLE object (an unsigned long value). Mostly provided for
37
- # subclasses to use internally when needed.
38
- #
39
- attr_reader :handle
40
-
41
- # Creates and returns a new IPC object. Since the IPC class is meant
42
- # as an abstract base class, you should never call this method directly.
43
- #
44
- def initialize(handle)
45
- @handle = handle
46
- @signaled = false
47
- end
48
-
49
- # Closes the handle object provided in the constructor.
50
- #
51
- def close
52
- CloseHandle(@handle)
53
- end
54
-
55
- # Returns whether or not the IPC object is in a signaled state.
56
- #--
57
- # This method assumes a single object. You may need to redefine this
58
- # to suit your needs in your subclass.
59
- #
60
- def signaled?
61
- state = WaitForSingleObject(@handle, 0)
62
-
63
- if state == WAIT_FAILED
64
- raise SystemCallError.new("WaitForSingleObject", FFI.errno)
65
- elsif state == WAIT_OBJECT_0
66
- @signaled = true
67
- else
68
- @signaled = false
69
- end
70
-
71
- @signaled
72
- end
73
-
74
- # call-seq:
75
- # Ipc#wait(timeout)
76
- # Ipc#wait(timeout){ block called when signaled }
77
- #
78
- # Waits for the calling object to be signaled. The +timeout+ value is
79
- # the maximum time to wait, in seconds. A timeout of 0 returns immediately.
80
- #
81
- # Returns SIGNALED (1), ABANDONED (-1) or TIMEOUT (0). Raises a
82
- # SystemCallError (Errno) if the wait fails for some reason.
83
- #
84
- def wait(timeout = INFINITE)
85
- timeout *= 1000 if timeout && timeout != INFINITE
86
-
87
- wait = WaitForSingleObject(@handle, timeout)
88
-
89
- case wait
90
- when WAIT_FAILED
91
- raise SystemCallError.new("WaitForSingleObject", FFI.errno)
92
- when WAIT_OBJECT_0
93
- @signaled = true
94
- yield if block_given?
95
- return SIGNALED
96
- when WAIT_ABANDONED
97
- return ABANDONED
98
- when WAIT_TIMEOUT
99
- return TIMEOUT
100
- else
101
- raise SystemCallError.new("WaitForSingleObject", FFI.errno)
102
- end
103
- end
104
-
105
- # :call-seq:
106
- # IPC#wait_any([ipc_objects], timeout = INFINITE)
107
- #
108
- # Waits for at least one of the +ipc_objects+ to be signaled. The
109
- # +timeout+ value is maximum time to wait in seconds. A timeout of 0
110
- # returns immediately.
111
- #
112
- # Returns the index+1 of the object that was signaled. If multiple
113
- # objects are signaled, the one with the lowest index is returned.
114
- # Returns 0 if no objects are signaled.
115
- #
116
- def wait_any(ipc_objects, timeout=INFINITE)
117
- timeout *= 1000 if timeout && timeout != INFINITE
118
- wait_for_multiple(ipc_objects, false, timeout)
119
- end
120
-
121
- # :call-seq:
122
- # IPC#wait_all([ipc_objects], timeout = INFINITE)
123
- #
124
- # Identical to IPC#wait_any, except that it waits for all +ipc_objects+
125
- # to be signaled instead of just one.
126
- #
127
- # Returns the index of the last object signaled. If at least one of the
128
- # objects is an abandoned mutex, the return value is negative.
129
- #
130
- def wait_all(ipc_objects, timeout=INFINITE)
131
- timeout *= 1000 if timeout && timeout != INFINITE
132
- wait_for_multiple(ipc_objects, true, timeout)
133
- end
134
-
135
- private
136
-
137
- # Waits until one or all (depending on the value of +wait_all+) of the
138
- # +ipc_objects+ are in the signaled state or the +timeout+ interval
139
- # elapses.
140
- #
141
- def wait_for_multiple(ipc_objects, wait_all=false, timeout=INFINITE)
142
- unless ipc_objects.is_a?(Array)
143
- msg = 'invalid argument - must be an array of Ipc objects'
144
- raise TypeError, msg
145
- end
146
-
147
- length = ipc_objects.size
148
-
149
- if length == 0
150
- raise ArgumentError, 'no objects to wait for'
151
- end
152
-
153
- ptr = FFI::MemoryPointer.new(:pointer, length)
154
-
155
- handles = ipc_objects.map(&:handle)
156
- ptr.write_array_of_pointer(handles)
157
-
158
- wait = WaitForMultipleObjects(
159
- length,
160
- ptr,
161
- wait_all,
162
- timeout
163
- )
164
-
165
- if wait == WAIT_FAILED
166
- raise SystemCallError.new("WaitForMultipleObjects", FFI.errno)
167
- end
168
-
169
- # signaled
170
- if (wait >= WAIT_OBJECT_0) && (wait < WAIT_OBJECT_0 + length)
171
- return wait - WAIT_OBJECT_0 + 1
172
- end
173
-
174
- # abandoned mutex - return negative value
175
- if (wait >= WAIT_ABANDONED) && (wait < WAIT_ABANDONED + length)
176
- return -wait - WAIT_ABANDONED + 1
177
- end
178
-
179
- # timed out
180
- return 0 if wait == WAIT_TIMEOUT
181
-
182
- nil
183
- end
184
- end
185
- end
1
+ require 'ffi'
2
+
3
+ # The Win32 module serves as a namespace only.
4
+ module Win32
5
+
6
+ # This is a an abstract base class for IPC related classes, such as
7
+ # Events and Semaphores.
8
+ #
9
+ class Ipc
10
+ extend FFI::Library
11
+ typedef :ulong, :dword
12
+ typedef :uintptr_t, :handle
13
+
14
+ ffi_lib :kernel32
15
+
16
+ attach_function :CloseHandle, [:handle], :bool
17
+ attach_function :WaitForSingleObject, [:handle, :dword], :dword, :blocking => true
18
+ attach_function :WaitForMultipleObjects, [:dword, :pointer, :bool, :dword], :dword, :blocking => true
19
+
20
+ private_class_method :CloseHandle, :WaitForSingleObject, :WaitForMultipleObjects
21
+
22
+ # The version of the win32-ipc library
23
+ VERSION = '0.6.6'
24
+
25
+ SIGNALED = 1
26
+ ABANDONED = -1
27
+ TIMEOUT = 0
28
+ INFINITE = 0xFFFFFFFF
29
+
30
+ WAIT_OBJECT_0 = 0
31
+ WAIT_TIMEOUT = 0x102
32
+ WAIT_ABANDONED = 128
33
+ WAIT_ABANDONED_0 = WAIT_ABANDONED
34
+ WAIT_FAILED = 0xFFFFFFFF
35
+
36
+ # The HANDLE object (an unsigned long value). Mostly provided for
37
+ # subclasses to use internally when needed.
38
+ #
39
+ attr_reader :handle
40
+
41
+ # Creates and returns a new IPC object. Since the IPC class is meant
42
+ # as an abstract base class, you should never call this method directly.
43
+ #
44
+ def initialize(handle)
45
+ @handle = handle
46
+ @signaled = false
47
+ end
48
+
49
+ # Closes the handle object provided in the constructor.
50
+ #
51
+ def close
52
+ CloseHandle(@handle)
53
+ end
54
+
55
+ # Returns whether or not the IPC object is in a signaled state.
56
+ #--
57
+ # This method assumes a single object. You may need to redefine this
58
+ # to suit your needs in your subclass.
59
+ #
60
+ def signaled?
61
+ state = WaitForSingleObject(@handle, 0)
62
+
63
+ if state == WAIT_FAILED
64
+ raise SystemCallError.new("WaitForSingleObject", FFI.errno)
65
+ elsif state == WAIT_OBJECT_0
66
+ @signaled = true
67
+ else
68
+ @signaled = false
69
+ end
70
+
71
+ @signaled
72
+ end
73
+
74
+ # call-seq:
75
+ # Ipc#wait(timeout)
76
+ # Ipc#wait(timeout){ block called when signaled }
77
+ #
78
+ # Waits for the calling object to be signaled. The +timeout+ value is
79
+ # the maximum time to wait, in seconds. A timeout of 0 returns immediately.
80
+ #
81
+ # Returns SIGNALED (1), ABANDONED (-1) or TIMEOUT (0). Raises a
82
+ # SystemCallError (Errno) if the wait fails for some reason.
83
+ #
84
+ def wait(timeout = INFINITE)
85
+ timeout *= 1000 if timeout && timeout != INFINITE
86
+
87
+ wait = WaitForSingleObject(@handle, timeout)
88
+
89
+ case wait
90
+ when WAIT_FAILED
91
+ raise SystemCallError.new("WaitForSingleObject", FFI.errno)
92
+ when WAIT_OBJECT_0
93
+ @signaled = true
94
+ yield if block_given?
95
+ return SIGNALED
96
+ when WAIT_ABANDONED
97
+ return ABANDONED
98
+ when WAIT_TIMEOUT
99
+ return TIMEOUT
100
+ else
101
+ raise SystemCallError.new("WaitForSingleObject", FFI.errno)
102
+ end
103
+ end
104
+
105
+ # :call-seq:
106
+ # IPC#wait_any([ipc_objects], timeout = INFINITE)
107
+ #
108
+ # Waits for at least one of the +ipc_objects+ to be signaled. The
109
+ # +timeout+ value is maximum time to wait in seconds. A timeout of 0
110
+ # returns immediately.
111
+ #
112
+ # Returns the index+1 of the object that was signaled. If multiple
113
+ # objects are signaled, the one with the lowest index is returned.
114
+ # Returns 0 if no objects are signaled.
115
+ #
116
+ def wait_any(ipc_objects, timeout=INFINITE)
117
+ timeout *= 1000 if timeout && timeout != INFINITE
118
+ wait_for_multiple(ipc_objects, false, timeout)
119
+ end
120
+
121
+ # :call-seq:
122
+ # IPC#wait_all([ipc_objects], timeout = INFINITE)
123
+ #
124
+ # Identical to IPC#wait_any, except that it waits for all +ipc_objects+
125
+ # to be signaled instead of just one.
126
+ #
127
+ # Returns the index of the last object signaled. If at least one of the
128
+ # objects is an abandoned mutex, the return value is negative.
129
+ #
130
+ def wait_all(ipc_objects, timeout=INFINITE)
131
+ timeout *= 1000 if timeout && timeout != INFINITE
132
+ wait_for_multiple(ipc_objects, true, timeout)
133
+ end
134
+
135
+ private
136
+
137
+ # Waits until one or all (depending on the value of +wait_all+) of the
138
+ # +ipc_objects+ are in the signaled state or the +timeout+ interval
139
+ # elapses.
140
+ #
141
+ def wait_for_multiple(ipc_objects, wait_all=false, timeout=INFINITE)
142
+ unless ipc_objects.is_a?(Array)
143
+ msg = 'invalid argument - must be an array of Ipc objects'
144
+ raise TypeError, msg
145
+ end
146
+
147
+ length = ipc_objects.size
148
+
149
+ if length == 0
150
+ raise ArgumentError, 'no objects to wait for'
151
+ end
152
+
153
+ ptr = FFI::MemoryPointer.new(:pointer, length)
154
+
155
+ handles = ipc_objects.map(&:handle)
156
+ ptr.write_array_of_pointer(handles)
157
+
158
+ wait = WaitForMultipleObjects(
159
+ length,
160
+ ptr,
161
+ wait_all,
162
+ timeout
163
+ )
164
+
165
+ if wait == WAIT_FAILED
166
+ raise SystemCallError.new("WaitForMultipleObjects", FFI.errno)
167
+ end
168
+
169
+ # signaled
170
+ if (wait >= WAIT_OBJECT_0) && (wait < WAIT_OBJECT_0 + length)
171
+ return wait - WAIT_OBJECT_0 + 1
172
+ end
173
+
174
+ # abandoned mutex - return negative value
175
+ if (wait >= WAIT_ABANDONED) && (wait < WAIT_ABANDONED + length)
176
+ return -wait - WAIT_ABANDONED + 1
177
+ end
178
+
179
+ # timed out
180
+ return 0 if wait == WAIT_TIMEOUT
181
+
182
+ nil
183
+ end
184
+ end
185
+ end
@@ -1,88 +1,88 @@
1
- ##########################################################################
2
- # test_win32_ipc.rb
3
- #
4
- # Test case for the Win32::Ipc class. Note that this class is rather
5
- # difficult to test directly since it is meant to be subclassed, not
6
- # used directly.
7
- #
8
- # You should run this test via the 'rake test' task.
9
- ##########################################################################
10
- require 'win32/ipc'
11
- require 'test-unit'
12
- include Win32
13
-
14
- class TC_Win32_Ipc < Test::Unit::TestCase
15
- def setup
16
- @ipc = Ipc.new(1)
17
- end
18
-
19
- test "version is set to expected value" do
20
- assert_equal('0.6.5', Ipc::VERSION)
21
- end
22
-
23
- test "handle method basic functionality" do
24
- assert_respond_to(@ipc, :handle)
25
- assert_equal(1, @ipc.handle)
26
- end
27
-
28
- test "signaled? method is defined" do
29
- assert_respond_to(@ipc, :signaled?)
30
- end
31
-
32
- test "wait method is defined" do
33
- assert_respond_to(@ipc, :wait)
34
- end
35
-
36
- test "wait raises ENXIO if handle is invalid" do
37
- assert_raises(Errno::ENXIO){ @ipc.wait }
38
- end
39
-
40
- test "wait accepts a maximum of one argument" do
41
- assert_raises(ArgumentError){ @ipc.wait(1,2) }
42
- end
43
-
44
- test "wait_any method is defined" do
45
- assert_respond_to(@ipc, :wait_any)
46
- end
47
-
48
- test "wait_any raises an ArgumentError if the array is empty" do
49
- assert_raises(ArgumentError){ @ipc.wait_any([]) }
50
- end
51
-
52
- test "wait_any only accepts an array" do
53
- assert_raises(TypeError){ @ipc.wait_any(1,2) }
54
- end
55
-
56
- test "wait_all method is defined" do
57
- assert_respond_to(@ipc, :wait_all)
58
- end
59
-
60
- test "wait_all raises an ArgumentError if the array is empty" do
61
- assert_raises(ArgumentError){ @ipc.wait_all([]) }
62
- end
63
-
64
- test "wait_all only accepts an array" do
65
- assert_raises(TypeError){ @ipc.wait_all(1,2) }
66
- end
67
-
68
- test "close method basic functionality" do
69
- assert_respond_to(@ipc, :close)
70
- assert_nothing_raised{ @ipc.close }
71
- end
72
-
73
- test "expected constants are defined" do
74
- assert_not_nil(Ipc::SIGNALED)
75
- assert_not_nil(Ipc::ABANDONED)
76
- assert_not_nil(Ipc::TIMEOUT)
77
- end
78
-
79
- test "ffi functions are private" do
80
- assert_not_respond_to(Ipc, :CloseHandle)
81
- assert_not_respond_to(Ipc, :WaitForSingleObject)
82
- assert_not_respond_to(Ipc, :WaitForMultipleObjects)
83
- end
84
-
85
- def teardown
86
- @ipc = nil
87
- end
88
- end
1
+ ##########################################################################
2
+ # test_win32_ipc.rb
3
+ #
4
+ # Test case for the Win32::Ipc class. Note that this class is rather
5
+ # difficult to test directly since it is meant to be subclassed, not
6
+ # used directly.
7
+ #
8
+ # You should run this test via the 'rake test' task.
9
+ ##########################################################################
10
+ require 'win32/ipc'
11
+ require 'test-unit'
12
+ include Win32
13
+
14
+ class TC_Win32_Ipc < Test::Unit::TestCase
15
+ def setup
16
+ @ipc = Ipc.new(1)
17
+ end
18
+
19
+ test "version is set to expected value" do
20
+ assert_equal('0.6.6', Ipc::VERSION)
21
+ end
22
+
23
+ test "handle method basic functionality" do
24
+ assert_respond_to(@ipc, :handle)
25
+ assert_equal(1, @ipc.handle)
26
+ end
27
+
28
+ test "signaled? method is defined" do
29
+ assert_respond_to(@ipc, :signaled?)
30
+ end
31
+
32
+ test "wait method is defined" do
33
+ assert_respond_to(@ipc, :wait)
34
+ end
35
+
36
+ test "wait raises ENXIO if handle is invalid" do
37
+ assert_raises(Errno::ENXIO){ @ipc.wait }
38
+ end
39
+
40
+ test "wait accepts a maximum of one argument" do
41
+ assert_raises(ArgumentError){ @ipc.wait(1,2) }
42
+ end
43
+
44
+ test "wait_any method is defined" do
45
+ assert_respond_to(@ipc, :wait_any)
46
+ end
47
+
48
+ test "wait_any raises an ArgumentError if the array is empty" do
49
+ assert_raises(ArgumentError){ @ipc.wait_any([]) }
50
+ end
51
+
52
+ test "wait_any only accepts an array" do
53
+ assert_raises(TypeError){ @ipc.wait_any(1,2) }
54
+ end
55
+
56
+ test "wait_all method is defined" do
57
+ assert_respond_to(@ipc, :wait_all)
58
+ end
59
+
60
+ test "wait_all raises an ArgumentError if the array is empty" do
61
+ assert_raises(ArgumentError){ @ipc.wait_all([]) }
62
+ end
63
+
64
+ test "wait_all only accepts an array" do
65
+ assert_raises(TypeError){ @ipc.wait_all(1,2) }
66
+ end
67
+
68
+ test "close method basic functionality" do
69
+ assert_respond_to(@ipc, :close)
70
+ assert_nothing_raised{ @ipc.close }
71
+ end
72
+
73
+ test "expected constants are defined" do
74
+ assert_not_nil(Ipc::SIGNALED)
75
+ assert_not_nil(Ipc::ABANDONED)
76
+ assert_not_nil(Ipc::TIMEOUT)
77
+ end
78
+
79
+ test "ffi functions are private" do
80
+ assert_not_respond_to(Ipc, :CloseHandle)
81
+ assert_not_respond_to(Ipc, :WaitForSingleObject)
82
+ assert_not_respond_to(Ipc, :WaitForMultipleObjects)
83
+ end
84
+
85
+ def teardown
86
+ @ipc = nil
87
+ end
88
+ end
@@ -1,24 +1,25 @@
1
- require 'rubygems'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'win32-ipc'
5
- spec.version = '0.6.5'
6
- spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
- spec.license = 'Artistic 2.0'
8
- spec.email = 'djberg96@gmail.com'
9
- spec.homepage = 'http://github.com/djberg96/win32-ipc'
10
- spec.summary = 'An abstract base class for Windows synchronization objects.'
11
- spec.test_file = 'test/test_win32_ipc.rb'
12
- spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
-
14
- spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
15
-
16
- spec.add_dependency('ffi')
17
- spec.add_development_dependency('test-unit')
18
-
19
- spec.description = <<-EOF
20
- The win32-ipc library provides the Win32::IPC class. This is meant to
21
- serve as an abstract base class for other IPC related libraries for MS
22
- Windows, such as win32-semaphore, win32-event, and so on.
23
- EOF
24
- end
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-ipc'
5
+ spec.version = '0.6.6'
6
+ spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://github.com/djberg96/win32-ipc'
10
+ spec.summary = 'An abstract base class for Windows synchronization objects.'
11
+ spec.test_file = 'test/test_win32_ipc.rb'
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
+ spec.cert_chain = ['certs/djberg96_pub.pem']
14
+
15
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
+
17
+ spec.add_dependency('ffi')
18
+ spec.add_development_dependency('test-unit')
19
+
20
+ spec.description = <<-EOF
21
+ The win32-ipc library provides the Win32::IPC class. This is meant to
22
+ serve as an abstract base class for other IPC related libraries for MS
23
+ Windows, such as win32-semaphore, win32-event, and so on.
24
+ EOF
25
+ end
metadata CHANGED
@@ -1,15 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-ipc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  - Park Heesob
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain: []
12
- date: 2015-07-07 00:00:00.000000000 Z
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkamJl
15
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
16
+ MB4XDTE1MDkwMjIwNDkxOFoXDTE2MDkwMTIwNDkxOFowPzERMA8GA1UEAwwIZGpi
17
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
18
+ bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyTkvXqRp6hLs9eoJOS
19
+ Hmi8kRYbq9Vkf15/hMxJpotYMgJVHHWrmDcC5Dye2PbnXjTkKf266Zw0PtT9h+lI
20
+ S3ts9HO+vaCFSMwFFZmnWJSpQ3CNw2RcHxjWkk9yF7imEM8Kz9ojhiDXzBetdV6M
21
+ gr0lV/alUr7TNVBDngbXEfTWscyXh1qd7xZ4EcOdsDktCe5G45N/o3662tPQvJsi
22
+ FOF0CM/KuBsa/HL1/eoEmF4B3EKIRfTHrQ3hu20Kv3RJ88QM4ec2+0dd97uX693O
23
+ zv6981fyEg+aXLkxrkViM/tz2qR2ZE0jPhHTREPYeMEgptRkTmWSKAuLVWrJEfgl
24
+ DtkCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFEwe
25
+ nn6bfJADmuIDiMSOzedOrL+xMB0GA1UdEQQWMBSBEmRqYmVyZzk2QGdtYWlsLmNv
26
+ bTAdBgNVHRIEFjAUgRJkamJlcmc5NkBnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD
27
+ ggEBAHmNOCWoDVD75zHFueY0viwGDVP1BNGFC+yXcb7u2GlK+nEMCORqzURbYPf7
28
+ tL+/hzmePIRz7i30UM//64GI1NLv9jl7nIwjhPpXpf7/lu2I9hOTsvwSumb5UiKC
29
+ /sqBxI3sfj9pr79Wpv4MuikX1XPik7Ncb7NPsJPw06Lvyc3Hkg5X2XpPtLtS+Gr2
30
+ wKJnmzb5rIPS1cmsqv0M9LPWflzfwoZ/SpnmhagP+g05p8bRNKjZSA2iImM/GyYZ
31
+ EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
32
+ tGSHgAmcLlkdGgan182qsE/4kKM=
33
+ -----END CERTIFICATE-----
34
+ date: 2015-09-13 00:00:00.000000000 Z
13
35
  dependencies:
14
36
  - !ruby/object:Gem::Dependency
15
37
  name: ffi
@@ -55,6 +77,8 @@ files:
55
77
  - MANIFEST
56
78
  - README
57
79
  - Rakefile
80
+ - certs/djberg96_pub.pem
81
+ - lib/win32-ipc.rb
58
82
  - lib/win32/ipc.rb
59
83
  - test/test_win32_ipc.rb
60
84
  - win32-ipc.gemspec
@@ -78,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
102
  version: '0'
79
103
  requirements: []
80
104
  rubyforge_project:
81
- rubygems_version: 2.4.6
105
+ rubygems_version: 2.4.5
82
106
  signing_key:
83
107
  specification_version: 4
84
108
  summary: An abstract base class for Windows synchronization objects.
@@ -0,0 +1 @@
1
+ <V��ubCmS(=.��I�zZ�kehغ��.^���'%��n�+�T'3o