Class: Slack::RealTime::Concurrency::Celluloid::Socket
- Inherits:
-
Socket
- Object
- Socket
- Slack::RealTime::Concurrency::Celluloid::Socket
show all
- Extended by:
- Forwardable
- Includes:
- Celluloid::IO, Celluloid::Internals::Logger
- Defined in:
- lib/slack/real_time/concurrency/celluloid.rb
Defined Under Namespace
Classes: Actor
Constant Summary
collapse
- BLOCK_SIZE =
4096
Instance Attribute Summary collapse
Attributes inherited from Socket
#driver, #options, #url
Instance Method Summary
collapse
Methods inherited from Socket
#disconnect!, #send_data, #start_sync
Constructor Details
#initialize(*args) ⇒ Socket
Returns a new instance of Socket.
23
24
25
|
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 23
def initialize(*args)
super
end
|
Instance Attribute Details
#socket ⇒ Object
Returns the value of attribute socket.
21
22
23
|
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 21
def socket
@socket
end
|
Instance Method Details
#connect! ⇒ Object
27
28
29
30
|
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 27
def connect!
super
run_loop
end
|
#connected? ⇒ Boolean
61
62
63
|
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 61
def connected?
!@connected.nil?
end
|
#read ⇒ Object
41
42
43
44
45
|
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 41
def read
buffer = socket.readpartial(BLOCK_SIZE)
logger.debug("#{self.class}##{__method__}") { buffer }
driver.parse buffer
end
|
#run_client_loop ⇒ Object
57
58
59
|
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 57
def run_client_loop
@client.run_loop
end
|
#run_loop ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 32
def run_loop
@socket = build_socket
@connected = @socket.connect
driver.start
loop { read } if socket
rescue EOFError
end
|
#start_async(client) ⇒ Object
52
53
54
55
|
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 52
def start_async(client)
@client = client
Actor.new(future.run_client_loop)
end
|
#write(data) ⇒ Object
47
48
49
50
|
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 47
def write(data)
logger.debug("#{self.class}##{__method__}") { data }
socket.write(data)
end
|