Module: ServerEngine::RbWinSock

Extended by:
Fiddle::Importer
Defined in:
lib/serverengine/winsock.rb

Class Method Summary collapse

Class Method Details

.raise_last_error(name) ⇒ Object

Raises:

  • (SystemCallError)


107
108
109
110
# File 'lib/serverengine/winsock.rb', line 107

def self.raise_last_error(name)
  errno = rb_w32_map_errno(WinSock.last_error)
  raise SystemCallError.new(name, errno)
end

.wrap_io_handle(sock_class, handle, flags) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/serverengine/winsock.rb', line 114

def self.wrap_io_handle(sock_class, handle, flags)
  begin
    fd = rb_w32_wrap_io_handle(handle, flags)
    if fd < 0
      raise_last_error("rb_w32_wrap_io_handle(3)")
    end

    sock = sock_class.for_fd(fd)
    wrapped = true
    sock.define_singleton_method(:handle) { handle }

    return sock
  ensure
    unless wrapped
      WinSock.CloseHandle(handle)
    end
  end
end