class Celluloid::IO::Socket

Base class for all classes that wrap a ruby socket. @abstract

Constants

Constants

Compatibility

Public Class Methods

new(socket) click to toggle source

@param socket [BasicSocket, OpenSSL::SSL::SSLSocket]

# File lib/celluloid/io/socket.rb, line 13
def initialize(socket)
  case socket
  when ::BasicSocket, OpenSSL::SSL::SSLSocket
    @socket = socket
  else
    raise ArgumentError, "expected a socket, got #{socket.inspect}"
  end
end
new(*args) click to toggle source

Celluloid::IO:Socket.new behaves like ::new for compatibility. This is is not problematic since Celluloid::IO::Socket is abstract. To instantiate a socket use one of its subclasses.

Calls superclass method
# File lib/celluloid/io/socket.rb, line 35
def self.new(*args)
  if self == Celluloid::IO::Socket
    return ::Socket.new(*args)
  else
    super
  end
end
try_convert(socket, convert_io = true) click to toggle source

Tries to convert the given ruby socket into a subclass of GenericSocket. @param socket @return [SSLSocket, TCPServer, TCPSocket, UDPSocket, UNIXServer, UNIXSocket] @return [nil] if the socket can't be converted

# File lib/celluloid/io/socket.rb, line 47
def self.try_convert(socket, convert_io = true)
  case socket
  when Celluloid::IO::Socket, Celluloid::IO::SSLServer
    socket
  when ::TCPServer
    TCPServer.new(socket)
  when ::TCPSocket
    TCPSocket.new(socket)
  when ::UDPSocket
    UDPSocket.new(socket)
  when ::UNIXServer
    UNIXServer.new(socket)
  when ::UNIXSocket
    UNIXSocket.new(socket)
  when OpenSSL::SSL::SSLServer
    SSLServer.new(socket.to_io, socket.instance_variable_get(:@ctx))
  when OpenSSL::SSL::SSLSocket
    SSLSocket.new(socket)
  else
    if convert_io
      return try_convert(IO.try_convert(socket), false)
    end
    nil
  end
end

Public Instance Methods

to_io() click to toggle source

Returns the wrapped socket. @return [BasicSocket, OpenSSL::SSL::SSLSocket]

# File lib/celluloid/io/socket.rb, line 24
def to_io
  @socket
end