Class: Win32::Ipc
Overview
This is a an abstract base class for IPC related classes, such as Events and Semaphores.
Constant Summary collapse
- VERSION =
The version of the win32-ipc library
'0.7.0'
- SIGNALED =
1
- ABANDONED =
-1
- TIMEOUT =
0
- INFINITE =
0xFFFFFFFF
- WAIT_OBJECT_0 =
0
- WAIT_TIMEOUT =
0x102
- WAIT_ABANDONED =
128
- WAIT_ABANDONED_0 =
WAIT_ABANDONED
- WAIT_FAILED =
0xFFFFFFFF
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.
44 45 46 47 |
# File 'lib/win32/ipc.rb', line 44 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.
39 40 41 |
# File 'lib/win32/ipc.rb', line 39 def handle @handle end |
Instance Method Details
#close ⇒ Object
Closes the handle object provided in the constructor.
51 52 53 |
# File 'lib/win32/ipc.rb', line 51 def close CloseHandle(@handle) end |
#signaled? ⇒ Boolean
Returns whether or not the IPC object is in a signaled state. – This method assumes a single object. You may need to redefine this to suit your needs in your subclass.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/win32/ipc.rb', line 60 def signaled? state = WaitForSingleObject(@handle, 0) if state == WAIT_FAILED raise SystemCallError.new("WaitForSingleObject", FFI.errno) elsif state == WAIT_OBJECT_0 @signaled = true else @signaled = false end @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 a SystemCallError (Errno) if the wait fails for some reason.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/win32/ipc.rb', line 84 def wait(timeout = INFINITE) timeout *= 1000 if timeout && timeout != INFINITE wait = WaitForSingleObject(@handle, timeout) case wait when WAIT_FAILED raise SystemCallError.new("WaitForSingleObject", FFI.errno) when WAIT_OBJECT_0 @signaled = true yield if block_given? return SIGNALED when WAIT_ABANDONED return ABANDONED when WAIT_TIMEOUT return TIMEOUT else raise SystemCallError.new("WaitForSingleObject", FFI.errno) 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.
130 131 132 133 |
# File 'lib/win32/ipc.rb', line 130 def wait_all(ipc_objects, timeout=INFINITE) timeout *= 1000 if timeout && timeout != INFINITE wait_for_multiple(ipc_objects, true, 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.
116 117 118 119 |
# File 'lib/win32/ipc.rb', line 116 def wait_any(ipc_objects, timeout=INFINITE) timeout *= 1000 if timeout && timeout != INFINITE wait_for_multiple(ipc_objects, false, timeout) end |