Class: Celluloid::IO::Socket Abstract

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Socket::Constants
Defined in:
lib/celluloid/io/socket.rb

Overview

This class is abstract.

Base class for all classes that wrap a ruby socket.

Direct Known Subclasses

Stream, TCPServer, UDPSocket, UNIXServer

Constant Summary collapse

Constants =

Compatibility

::Socket::Constants

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ Socket

Returns a new instance of Socket.

Parameters:

  • socket (BasicSocket, OpenSSL::SSL::SSLSocket)


13
14
15
16
17
18
19
20
# 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

Class Method Details

.new(*args) ⇒ Object

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



35
36
37
38
39
40
41
# 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) ⇒ SSLSocket, ...

Tries to convert the given ruby socket into a subclass of GenericSocket.

Parameters:

  • socket

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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

Instance Method Details

#to_ioBasicSocket, OpenSSL::SSL::SSLSocket

Returns the wrapped socket.

Returns:

  • (BasicSocket, OpenSSL::SSL::SSLSocket)


24
25
26
# File 'lib/celluloid/io/socket.rb', line 24

def to_io
  @socket
end