Class: Win32::Pipe::Client

Inherits:
Win32::Pipe show all
Defined in:
lib/win32/pipe/client.rb

Overview

The Pipe::Client class encapsulates the client side of a named pipe connection.

Constant Summary

Constants inherited from Win32::Pipe

ACCESS_DUPLEX, ACCESS_INBOUND, ACCESS_OUTBOUND, DEFAULT_OPEN_MODE, DEFAULT_PIPE_MODE, FIRST_PIPE_INSTANCE, NOWAIT, OVERLAPPED, PIPE_BUFFER_SIZE, PIPE_TIMEOUT, READMODE_BYTE, READMODE_MESSAGE, TYPE_BYTE, TYPE_MESSAGE, VERSION, WAIT, WRITE_THROUGH

Instance Attribute Summary

Attributes inherited from Win32::Pipe

#buffer, #name, #open_mode, #pipe_mode, #size, #transferred

Instance Method Summary collapse

Methods inherited from Win32::Pipe

#asynchronous?, #close, #disconnect, #pending?, #read, #wait, #write

Constructor Details

#initialize(name, pipe_mode = DEFAULT_PIPE_MODE, open_mode = DEFAULT_OPEN_MODE) ⇒ Client

Create and return a new Pipe::Client instance.

The default pipe mode is PIPE_WAIT.

The default open mode is FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH. – 2147483776 is FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH



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
39
40
41
42
43
44
45
46
47
# File 'lib/win32/pipe/client.rb', line 14

def initialize(name, pipe_mode = DEFAULT_PIPE_MODE, open_mode = DEFAULT_OPEN_MODE)
   super(name, pipe_mode, open_mode)
   
   @pipe = CreateFile(
      @name,
      GENERIC_READ | GENERIC_WRITE,
      FILE_SHARE_READ | FILE_SHARE_WRITE,
      nil,
      OPEN_EXISTING,
      @open_mode,
      nil 
   )

   error = GetLastError()
   
   if error == ERROR_PIPE_BUSY
      unless WaitNamedPipe(@name, NMPWAIT_WAIT_FOREVER)
         raise Error, get_last_error
      end
   end
   
   if @pipe == INVALID_HANDLE_VALUE
      raise Error, get_last_error
   end
   
   if block_given?
      begin
         yield self
      ensure
         disconnect
         close
      end
   end
end