Module: Revent::RRCon
- Defined in:
- lib/revent/r_r.rb
Overview
Included by both Revent::RRServer and Revent::RRClient.
Instance Attribute Summary collapse
-
#session ⇒ Object
The place to store something associated with this connection.
Instance Method Summary collapse
- #on_message(message) ⇒ Object
- #post_init ⇒ Object
- #receive_data(data) ⇒ Object
- #remote_ip ⇒ Object
-
#send_message(message) ⇒ Object
————————————————————————–.
- #unbind ⇒ Object
- #user=(server_or_client) ⇒ Object
Instance Attribute Details
#session ⇒ Object
The place to store something associated with this connection
11 12 13 |
# File 'lib/revent/r_r.rb', line 11 def session @session end |
Instance Method Details
#on_message(message) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/revent/r_r.rb', line 48 def () @user.synchronize do if @user_is_server @user.(self, ) else @user.() end end rescue end |
#post_init ⇒ Object
18 19 20 |
# File 'lib/revent/r_r.rb', line 18 def post_init @data = '' end |
#receive_data(data) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/revent/r_r.rb', line 22 def receive_data(data) @data << data while true io = StringIO.new(@data) = Marshal.load(io) @data.slice!(0, io.pos) () end rescue end |
#remote_ip ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/revent/r_r.rb', line 59 def remote_ip peername = get_peername return @last_ip if peername.nil? a = get_peername[2, 6].unpack('nC4') a.delete_at(0) @last_ip = a.join('.') end |
#send_message(message) ⇒ Object
44 45 46 |
# File 'lib/revent/r_r.rb', line 44 def () send_data(Marshal.dump()) end |
#unbind ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/revent/r_r.rb', line 33 def unbind if @user_is_server @user.cons.synchronize { @user.cons.delete(self) } @user.on_unbind(self) else @user.on_unbind end end |
#user=(server_or_client) ⇒ Object
13 14 15 16 |
# File 'lib/revent/r_r.rb', line 13 def user=(server_or_client) @user_is_server = server_or_client.respond_to?(:start_server) @user = server_or_client end |