win32-ipc 0.6.3 → 0.6.4

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.
Files changed (9) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +85 -81
  3. data/MANIFEST +6 -6
  4. data/README +33 -33
  5. data/Rakefile +27 -26
  6. data/lib/win32/ipc.rb +185 -185
  7. data/test/test_win32_ipc.rb +88 -88
  8. data/win32-ipc.gemspec +24 -25
  9. metadata +18 -23
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7fa41b850054530d530ac127f6b41f1c5c5a5c1e
4
+ data.tar.gz: c6cc87600d3944de6c081d74daf51ecab219f1f9
5
+ SHA512:
6
+ metadata.gz: 9fe27428dfaf4c9ccb8e3a57a02ffda16653bd65d76869983e2a6a6db7d5c74a32249bc85c5d3e35247de39b6140306cf880294b163667b7bdb5b8fe269879f6
7
+ data.tar.gz: 1dcdf0ebe52ae2ba677f123d9a22e8a77c29be75daea31a19f7bad0aec32eef04f9bec1d12b6bea057ff24068905d5bb8f0397c067871651797b18ae36e8aafb
data/CHANGES CHANGED
@@ -1,81 +1,85 @@
1
- == 0.6.3 - 10-Jan-2015
2
- * Declare the FFI prototype for WaitForSingleObject as blocking.
3
-
4
- == 0.6.2 - 10-Jan-2015
5
- * Declare the FFI prototype for WaitForMultipleObjects as blocking.
6
-
7
- == 0.6.1 - 9-Apr-2013
8
- * Updated the HANDLE function prototypes in the underlying FFI code. This
9
- affects 64 bit versions of Ruby.
10
-
11
- == 0.6.0 - 8-Jul-2012
12
- * Now uses FFI instead of win32-api.
13
- * The #signaled? method now has a meaningful default implementation.
14
- * If an internal C function fails it raises a SystemCallError (Errno) instead
15
- of an Ipc::Error.
16
- * The Ipc::Error class, although defined for those who wish to still use it
17
- in inherited classes, is no longer used internally.
18
-
19
- == 0.5.3 - 19-Apr-2010
20
- * Added a few gem related tasks to the Rakefile, and removed an old install
21
- task.
22
- * Removed the inline gem building code from the gemspec. That's now handled
23
- by a Rake task.
24
- * Some cosmetic changes to the source code.
25
-
26
- == 0.5.2 - 6-Aug-2009
27
- * License changed to Artistic 2.0.
28
- * Some gemspec updates, including an updated description and adding a
29
- license attribute.
30
- * Renamed the test file to test_win32_ipc.rb.
31
-
32
- == 0.5.1 - 1-Jan-2008
33
- * Fixed bugs in the private wait_for_multiple method. Thanks go to an
34
- anonymous user for the spot and the patch.
35
- * Removed the install.rb file. Installation was merged into the Rakefile.
36
- * Updated the MANIFEST.
37
-
38
- == 0.5.0 - 30-Apr-2007
39
- * Now pure Ruby.
40
- * Ipc.new no longer accepts a block.
41
- * Changed IpcError to Ipc::Error.
42
- * Removed the 'doc' directory. The documentation is now inlined via rdoc.
43
- * Added a gemspec.
44
- * Added a Rakefile, including tasks for installation and testing.
45
-
46
- == 0.4.1 - 23-Jan-2005
47
- * Minor internal modifications for handling block arguments.
48
-
49
- == 0.4.0 - 16-Dec-2004
50
- * Changed the timeout from milliseconds to seconds. This wasn't documented,
51
- and I'm guessing most people didn't know that they were passing milliseconds
52
- instead of seconds. But, I've bumped the version number, just in case.
53
-
54
- == 0.3.1 - 11-Dec-2004
55
- * Fixed a bug in Ipc#wait where a segfault would occur if a block was not
56
- provided.
57
- * Moved the 'examples' directory to the toplevel directory.
58
-
59
- == 0.3.0 - 31-Oct-2004
60
- * The constructor now takes an optional block. Instance objects will call
61
- that block if they are signaled.
62
- * Added the 'block' method (read-only). Allows you to access the block
63
- provided to the constructor.
64
- * Modified the 'wait' instance method to take an optional block. This block
65
- will be called if the object is signaled. Overrides the block to the
66
- constructor for that instance object (only).
67
- * Added the 'signaled?' instance method to indicate if the object is in the
68
- signaled state or not.
69
- * Modified all methods to raise an IpcError if an error occurs (instead of
70
- simply returning nil).
71
- * Added internal comments in order to make the code rdoc friendly, including
72
- changes to the README file.
73
-
74
- == 0.2.0 - 15-Jul-2004
75
- * Updated to use the newer allocation framework. This means that as of
76
- version 0.2.0, this package requires Ruby 1.8.0 or later.
77
- * Moved the test.rb script to docs/examples.
78
- * Minor code cleanup
79
-
80
- == 0.1.0 - 30-Apr-2004
81
- * Initial release
1
+ == 0.6.4 - 1-Jul-2015
2
+ * Fixed boolean argument type parameter. Thanks go to Rafal Bigaj for the patch.
3
+ * Updates to gemspec and Rakefile.
4
+
5
+ == 0.6.3 - 10-Jan-2015
6
+ * Declare the FFI prototype for WaitForSingleObject as blocking.
7
+
8
+ == 0.6.2 - 10-Jan-2015
9
+ * Declare the FFI prototype for WaitForMultipleObjects as blocking.
10
+
11
+ == 0.6.1 - 9-Apr-2013
12
+ * Updated the HANDLE function prototypes in the underlying FFI code. This
13
+ affects 64 bit versions of Ruby.
14
+
15
+ == 0.6.0 - 8-Jul-2012
16
+ * Now uses FFI instead of win32-api.
17
+ * The #signaled? method now has a meaningful default implementation.
18
+ * If an internal C function fails it raises a SystemCallError (Errno) instead
19
+ of an Ipc::Error.
20
+ * The Ipc::Error class, although defined for those who wish to still use it
21
+ in inherited classes, is no longer used internally.
22
+
23
+ == 0.5.3 - 19-Apr-2010
24
+ * Added a few gem related tasks to the Rakefile, and removed an old install
25
+ task.
26
+ * Removed the inline gem building code from the gemspec. That's now handled
27
+ by a Rake task.
28
+ * Some cosmetic changes to the source code.
29
+
30
+ == 0.5.2 - 6-Aug-2009
31
+ * License changed to Artistic 2.0.
32
+ * Some gemspec updates, including an updated description and adding a
33
+ license attribute.
34
+ * Renamed the test file to test_win32_ipc.rb.
35
+
36
+ == 0.5.1 - 1-Jan-2008
37
+ * Fixed bugs in the private wait_for_multiple method. Thanks go to an
38
+ anonymous user for the spot and the patch.
39
+ * Removed the install.rb file. Installation was merged into the Rakefile.
40
+ * Updated the MANIFEST.
41
+
42
+ == 0.5.0 - 30-Apr-2007
43
+ * Now pure Ruby.
44
+ * Ipc.new no longer accepts a block.
45
+ * Changed IpcError to Ipc::Error.
46
+ * Removed the 'doc' directory. The documentation is now inlined via rdoc.
47
+ * Added a gemspec.
48
+ * Added a Rakefile, including tasks for installation and testing.
49
+
50
+ == 0.4.1 - 23-Jan-2005
51
+ * Minor internal modifications for handling block arguments.
52
+
53
+ == 0.4.0 - 16-Dec-2004
54
+ * Changed the timeout from milliseconds to seconds. This wasn't documented,
55
+ and I'm guessing most people didn't know that they were passing milliseconds
56
+ instead of seconds. But, I've bumped the version number, just in case.
57
+
58
+ == 0.3.1 - 11-Dec-2004
59
+ * Fixed a bug in Ipc#wait where a segfault would occur if a block was not
60
+ provided.
61
+ * Moved the 'examples' directory to the toplevel directory.
62
+
63
+ == 0.3.0 - 31-Oct-2004
64
+ * The constructor now takes an optional block. Instance objects will call
65
+ that block if they are signaled.
66
+ * Added the 'block' method (read-only). Allows you to access the block
67
+ provided to the constructor.
68
+ * Modified the 'wait' instance method to take an optional block. This block
69
+ will be called if the object is signaled. Overrides the block to the
70
+ constructor for that instance object (only).
71
+ * Added the 'signaled?' instance method to indicate if the object is in the
72
+ signaled state or not.
73
+ * Modified all methods to raise an IpcError if an error occurs (instead of
74
+ simply returning nil).
75
+ * Added internal comments in order to make the code rdoc friendly, including
76
+ changes to the README file.
77
+
78
+ == 0.2.0 - 15-Jul-2004
79
+ * Updated to use the newer allocation framework. This means that as of
80
+ version 0.2.0, this package requires Ruby 1.8.0 or later.
81
+ * Moved the test.rb script to docs/examples.
82
+ * Minor code cleanup
83
+
84
+ == 0.1.0 - 30-Apr-2004
85
+ * 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 module 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 packages.
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-2013 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 module 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 packages.
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-2013 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,26 +1,27 @@
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
- spec = eval(IO.read('win32-ipc.gemspec'))
11
- Gem::Builder.new(spec).build
12
- end
13
-
14
- desc 'Install the win32-ipc gem'
15
- task :install => [:create] do
16
- file = Dir['*.gem'].first
17
- sh "gem install -l #{file}"
18
- end
19
- end
20
-
21
- Rake::TestTask.new do |t|
22
- t.verbose = true
23
- t.warning = true
24
- end
25
-
26
- 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
+ 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
data/lib/win32/ipc.rb CHANGED
@@ -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.3'
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, 0, 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, 1, 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=0, 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.length
148
-
149
- if length == 0
150
- raise ArgumentError, 'no objects to wait for'
151
- end
152
-
153
- ptr = FFI::MemoryPointer.new(:ulong, ipc_objects.size)
154
-
155
- handles = ipc_objects.map{ |o| o.handle }
156
- ptr.write_array_of_ulong(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.4'
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.length
148
+
149
+ if length == 0
150
+ raise ArgumentError, 'no objects to wait for'
151
+ end
152
+
153
+ ptr = FFI::MemoryPointer.new(:ulong, ipc_objects.size)
154
+
155
+ handles = ipc_objects.map{ |o| o.handle }
156
+ ptr.write_array_of_ulong(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.3', 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.4', 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
data/win32-ipc.gemspec CHANGED
@@ -1,25 +1,24 @@
1
- require 'rubygems'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'win32-ipc'
5
- spec.version = '0.6.3'
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
- spec.rubyforge_project = 'win32utils'
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
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-ipc'
5
+ spec.version = '0.6.4'
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
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-ipc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
5
- prerelease:
4
+ version: 0.6.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Daniel J. Berger
@@ -10,43 +9,40 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2015-01-10 00:00:00.000000000 Z
12
+ date: 2015-07-01 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: ffi
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - ">="
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - ">="
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: test-unit
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - ">="
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - ">="
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
- description: ! " The win32-ipc library provides the Win32::IPC class. This is meant
48
- to\n serve as an abstract base class for other IPC related libraries for MS\n
49
- \ Windows, such as win32-semaphore, win32-event, and so on.\n"
42
+ description: |2
43
+ The win32-ipc library provides the Win32::IPC class. This is meant to
44
+ serve as an abstract base class for other IPC related libraries for MS
45
+ Windows, such as win32-semaphore, win32-event, and so on.
50
46
  email: djberg96@gmail.com
51
47
  executables: []
52
48
  extensions: []
@@ -56,36 +52,35 @@ extra_rdoc_files:
56
52
  - MANIFEST
57
53
  files:
58
54
  - CHANGES
59
- - lib/win32/ipc.rb
60
55
  - MANIFEST
61
- - Rakefile
62
56
  - README
57
+ - Rakefile
58
+ - lib/win32/ipc.rb
63
59
  - test/test_win32_ipc.rb
64
60
  - win32-ipc.gemspec
65
61
  homepage: http://github.com/djberg96/win32-ipc
66
62
  licenses:
67
63
  - Artistic 2.0
64
+ metadata: {}
68
65
  post_install_message:
69
66
  rdoc_options: []
70
67
  require_paths:
71
68
  - lib
72
69
  required_ruby_version: !ruby/object:Gem::Requirement
73
- none: false
74
70
  requirements:
75
- - - ! '>='
71
+ - - ">="
76
72
  - !ruby/object:Gem::Version
77
73
  version: '0'
78
74
  required_rubygems_version: !ruby/object:Gem::Requirement
79
- none: false
80
75
  requirements:
81
- - - ! '>='
76
+ - - ">="
82
77
  - !ruby/object:Gem::Version
83
78
  version: '0'
84
79
  requirements: []
85
- rubyforge_project: win32utils
86
- rubygems_version: 1.8.24
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.8
87
82
  signing_key:
88
- specification_version: 3
83
+ specification_version: 4
89
84
  summary: An abstract base class for Windows synchronization objects.
90
85
  test_files:
91
86
  - test/test_win32_ipc.rb