Class: Win32::Pipe

Inherits:
Object
  • Object
show all
Defined in:
lib/isomorfeus/speednode/runtime/vm.rb

Instance Method Summary collapse

Instance Method Details

#write(data) ⇒ Object

Raises:

  • (Error)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 7

def write(data)
  bytes = ::FFI::MemoryPointer.new(:ulong)

  raise Error, "no pipe created" unless @pipe

  if @asynchronous
    bool = WriteFile(@pipe, data, data.bytesize, bytes, @overlapped)
    bytes_written = bytes.read_ulong

    if bool && bytes_written > 0
      @pending_io = false
      return true
    end

    error = GetLastError()
    if !bool && error == ERROR_IO_PENDING
      @pending_io = true
      return true
    end

    return false
  else
    unless WriteFile(@pipe, data, data.bytesize, bytes, nil)
      raise SystemCallError.new("WriteFile", FFI.errno)
    end

    return true
  end
end