Class: Win32::Ipc
- Inherits:
-
Object
- Object
- Win32::Ipc
- Includes:
- Windows::Error, Windows::Handle, Windows::Synchronize
- Defined in:
- lib/win32/ipc.rb
Overview
This is a an abstract base class for IPC related classes, such as Events and Semaphores.
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
'0.5.0'
- SIGNALED =
1
- ABANDONED =
-1
- TIMEOUT =
0
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
The HANDLE object (an unsigned long value).
Instance Method Summary collapse
-
#close ⇒ Object
Closes the handle object provided in the constructor.
-
#initialize(handle) ⇒ Ipc
constructor
Creates and returns a new IPC object.
-
#signaled? ⇒ Boolean
Returns whether or not the IPC object is in a signaled state.
-
#wait(timeout = INFINITE) ⇒ Object
call-seq: Ipc#wait(timeout) Ipc#wait(timeout){ block called when signaled }.
-
#wait_all(ipc_objects, timeout = INFINITE) ⇒ Object
:call-seq: IPC#wait_all(, timeout = INFINITE).
-
#wait_any(ipc_objects, timeout = INFINITE) ⇒ Object
:call-seq: IPC#wait_any(, timeout = INFINITE).
Constructor Details
#initialize(handle) ⇒ Ipc
Creates and returns a new IPC object. Since the IPC class is meant as an abstract base class, you should never call this method directly.
31 32 33 34 |
# File 'lib/win32/ipc.rb', line 31 def initialize(handle) @handle = handle @signaled = false end |
Instance Attribute Details
#handle ⇒ Object (readonly)
The HANDLE object (an unsigned long value). Mostly provided for subclasses to use internally when needed.
26 27 28 |
# File 'lib/win32/ipc.rb', line 26 def handle @handle end |
Instance Method Details
#close ⇒ Object
Closes the handle object provided in the constructor.
38 39 40 |
# File 'lib/win32/ipc.rb', line 38 def close CloseHandle(@handle) end |
#signaled? ⇒ Boolean
Returns whether or not the IPC object is in a signaled state.
44 45 46 |
# File 'lib/win32/ipc.rb', line 44 def signaled? @signaled end |
#wait(timeout = INFINITE) ⇒ Object
call-seq:
Ipc#wait(timeout)
Ipc#wait(timeout){ block called when signaled }
Waits for the calling object to be signaled. The timeout
value is the maximum time to wait, in seconds. A timeout of 0 returns immediately.
Returns SIGNALED (1), ABANDONED (-1) or TIMEOUT (0). Raises an IPC::Error if the wait fails for some reason.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/win32/ipc.rb', line 59 def wait(timeout = INFINITE) timeout *= 1000 if timeout && timeout != INFINITE wait = WaitForSingleObject(@handle, timeout) case wait when WAIT_FAILED raise Error, get_last_error when WAIT_OBJECT_0 @signaled = true yield if block_given? return SIGNALED when WAIT_ABANDONED return ABANDONED when WAIT_TIMEOUT return TIMEOUT else raise Error, get_last_error end end |
#wait_all(ipc_objects, timeout = INFINITE) ⇒ Object
:call-seq:
IPC#wait_all([ipc_objects], timeout = INFINITE)
Identical to IPC#wait_any, except that it waits for all ipc_objects
to be signaled instead of just one.
Returns the index of the last object signaled. If at least one of the objects is an abandoned mutex, the return value is negative.
105 106 107 108 |
# File 'lib/win32/ipc.rb', line 105 def wait_all(ipc_objects, timeout=INFINITE) timeout *= 1000 if timeout && timeout != INFINITE wait_for_multiple(ipc_objects, 1, timeout) end |
#wait_any(ipc_objects, timeout = INFINITE) ⇒ Object
:call-seq:
IPC#wait_any([ipc_objects], timeout = INFINITE)
Waits for at least one of the ipc_objects
to be signaled. The timeout
value is maximum time to wait in seconds. A timeout of 0 returns immediately.
Returns the index+1 of the object that was signaled. If multiple objects are signaled, the one with the lowest index is returned. Returns 0 if no objects are signaled.
91 92 93 94 |
# File 'lib/win32/ipc.rb', line 91 def wait_any(ipc_objects, timeout=INFINITE) timeout *= 1000 if timeout && timeout != INFINITE wait_for_multiple(ipc_objects, 0, timeout) end |