class Win32::Pipe

Public Instance Methods

write(data) click to toggle source
# 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