class Slack::RealTime::Concurrency::Celluloid::Socket
Constants
- BLOCK_SIZE
Attributes
socket[R]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Slack::RealTime::Socket.new
# File lib/slack/real_time/concurrency/celluloid.rb, line 22 def initialize(*args) super end
Public Instance Methods
close()
click to toggle source
Calls superclass method
Slack::RealTime::Socket#close
# File lib/slack/real_time/concurrency/celluloid.rb, line 48 def close @closing = true driver.close super end
connect!()
click to toggle source
Calls superclass method
Slack::RealTime::Socket#connect!
# File lib/slack/real_time/concurrency/celluloid.rb, line 26 def connect! super run_loop end
connected?()
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 78 def connected? !@connected.nil? end
handle_read(buffer)
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 59 def handle_read(buffer) logger.debug("#{self.class}##{__method__}") { buffer } driver.parse buffer end
read()
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 54 def read buffer = socket.readpartial(BLOCK_SIZE) async.handle_read(buffer) end
run_client_loop()
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 74 def run_client_loop @client.run_loop end
run_loop()
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 31 def run_loop @closing = false @socket = build_socket @connected = @socket.connect driver.start loop { read } if socket rescue EOFError, Errno::EPIPE => e logger.debug("#{self.class}##{__method__}") { e } driver.emit(:close, WebSocket::Driver::CloseEvent.new(1001, 'server closed connection')) unless @closing ensure begin current_actor.terminate if current_actor.alive? rescue nil end end
start_async(client)
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 69 def start_async(client) @client = client Actor.new(future.run_client_loop) end
write(data)
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 64 def write(data) logger.debug("#{self.class}##{__method__}") { data } socket.write(data) end
Protected Instance Methods
build_driver()
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 106 def build_driver ::WebSocket::Driver.client(self) end
build_socket()
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 96 def build_socket socket = ::Celluloid::IO::TCPSocket.new(addr, port) socket = ::Celluloid::IO::SSLSocket.new(socket, build_ssl_context) if secure? socket end
build_ssl_context()
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 102 def build_ssl_context OpenSSL::SSL::SSLContext.new(:TLSv1_2_client) end
connect()
click to toggle source
# File lib/slack/real_time/concurrency/celluloid.rb, line 110 def connect @driver = build_driver end