Class: SocketList
Overview
ソケットとIDの対応
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, sock) ⇒ Object
- #add(key, sock) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize ⇒ SocketList
constructor
A new instance of SocketList.
- #keys ⇒ Object
Constructor Details
#initialize ⇒ SocketList
Returns a new instance of SocketList.
5 6 7 8 |
# File 'lib/dango/socket_list.rb', line 5 def initialize @sl_hash = Hash.new @sl_mutex = Mutex.new end |
Instance Method Details
#[](key) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/dango/socket_list.rb', line 30 def [](key) @sl_mutex.synchronize do # raise("not exist key(#{key.inspect})") if ! @sl_hash.has_key?(key) return(nil) if ! @sl_hash.has_key?(key) @sl_hash[key] end end |
#[]=(key, sock) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/dango/socket_list.rb', line 38 def []=(key, sock) @sl_mutex.synchronize do # raise("not exist key(#{key.inspect})") if ! @sl_hash.has_key?(key) raise("sock(#{sock.inspect}) is not Socket") if sock.kind_of?(Socket) @sl_hash[key] = sock end end |
#add(key, sock) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/dango/socket_list.rb', line 22 def add(key, sock) @sl_mutex.synchronize do raise("already exist key(#{key.inspect})") if @sl_hash.has_key?(key) raise("sock(#{sock.inspect}) is not Socket") if sock.kind_of?(Socket) @sl_hash[key] = sock end end |
#delete(key) ⇒ Object
16 17 18 19 20 |
# File 'lib/dango/socket_list.rb', line 16 def delete(key) @sl_mutex.synchronize do @sl_hash.delete(key) end end |
#keys ⇒ Object
10 11 12 13 14 |
# File 'lib/dango/socket_list.rb', line 10 def keys() @sl_mutex.synchronize do @sl_hash.keys end end |