Module: RubySL::Socket::Error

Defined in:
lib/rubysl/socket/error.rb

Class Method Summary collapse

Class Method Details

.nonblocking?(socket) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/rubysl/socket/error.rb', line 62

def self.nonblocking?(socket)
  socket.fcntl(::Fcntl::F_GETFL) & ::Fcntl::O_NONBLOCK > 0
end

.raise_wrapped_error(original, error_class) ⇒ Object

Wraps the error given in ‘original` in an instance of `error_class`.

This can be used to wrap e.g. an Errno::EAGAIN error in an ::IO::EAGAINWaitReadable instance.



54
55
56
57
58
59
60
# File 'lib/rubysl/socket/error.rb', line 54

def self.raise_wrapped_error(original, error_class)
  error = error_class.new(original.message)

  error.set_backtrace(original.backtrace)

  raise error
end

.read_error(message, socket) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/rubysl/socket/error.rb', line 12

def self.read_error(message, socket)
  if nonblocking?(socket)
    read_nonblock(message)
  else
    Errno.handle(message)
  end
end

.read_nonblock(message) ⇒ Object

Handles an error for a non-blocking read operation.



21
22
23
# File 'lib/rubysl/socket/error.rb', line 21

def self.read_nonblock(message)
  wrap_read_nonblock { Errno.handle(message) }
end

.wrap_read_nonblockObject



30
31
32
33
34
35
36
37
38
# File 'lib/rubysl/socket/error.rb', line 30

def self.wrap_read_nonblock
  yield
rescue Errno::EAGAIN => err
  raise_wrapped_error(err, ::IO::EAGAINWaitReadable)
rescue Errno::EWOULDBLOCK => err
  raise_wrapped_error(err, ::IO::EWOULDBLOCKWaitReadable)
rescue Errno::EINPROGRESS => err
  raise_wrapped_error(err, ::IO::EINPROGRESSWaitReadable)
end

.wrap_write_nonblockObject



40
41
42
43
44
45
46
47
48
# File 'lib/rubysl/socket/error.rb', line 40

def self.wrap_write_nonblock
  yield
rescue Errno::EAGAIN => err
  raise_wrapped_error(err, ::IO::EAGAINWaitWritable)
rescue Errno::EWOULDBLOCK => err
  raise_wrapped_error(err, ::IO::EWOULDBLOCKWaitWritable)
rescue Errno::EINPROGRESS => err
  raise_wrapped_error(err, ::IO::EINPROGRESSWaitWritable)
end

.write_error(message, socket) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/rubysl/socket/error.rb', line 4

def self.write_error(message, socket)
  if nonblocking?(socket)
    write_nonblock(message)
  else
    Errno.handle(message)
  end
end

.write_nonblock(message) ⇒ Object

Handles an error for a non-blocking write operation.



26
27
28
# File 'lib/rubysl/socket/error.rb', line 26

def self.write_nonblock(message)
  wrap_write_nonblock { Errno.handle(message) }
end