Class: Weso::Base::SocketCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/weso/socket_creator.rb

Overview

::nodoc

Constant Summary collapse

DEFAULT_SSL_VERSION =
'SSLv23'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options) ⇒ SocketCreator

Returns a new instance of SocketCreator.



11
12
13
14
# File 'lib/weso/socket_creator.rb', line 11

def initialize(url, options)
  @uri = URI.parse(url)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/weso/socket_creator.rb', line 7

def options
  @options
end

#uriObject (readonly)

Returns the value of attribute uri.



7
8
9
# File 'lib/weso/socket_creator.rb', line 7

def uri
  @uri
end

Instance Method Details

#callObject



16
17
18
19
20
21
# File 'lib/weso/socket_creator.rb', line 16

def call
  socket = TCPSocket.new(uri.host, port)
  socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
  socket = process_secure(socket) if secure?
  socket
end

#secure?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/weso/socket_creator.rb', line 23

def secure?
  %w[https wss].include? uri.scheme
end