Class: Droonga::Client::Connection::DroongaProtocol::Thread::Receiver
- Inherits:
-
Object
- Object
- Droonga::Client::Connection::DroongaProtocol::Thread::Receiver
- Defined in:
- lib/droonga/client/connection/droonga-protocol/thread.rb
Constant Summary collapse
- BUFFER_SIZE =
8192
Instance Method Summary collapse
- #close ⇒ Object
- #host ⇒ Object
-
#initialize(options = {}) ⇒ Receiver
constructor
A new instance of Receiver.
- #port ⇒ Object
- #receive(options = {}, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Receiver
Returns a new instance of Receiver.
137 138 139 140 141 142 143 |
# File 'lib/droonga/client/connection/droonga-protocol/thread.rb', line 137 def initialize(={}) host = [:host] || Socket.gethostname port = [:port] || 0 @socket = TCPServer.new(host, port) @read_ios = [@socket] @client_handlers = {} end |
Instance Method Details
#close ⇒ Object
145 146 147 148 149 150 |
# File 'lib/droonga/client/connection/droonga-protocol/thread.rb', line 145 def close @socket.close @client_handlers.each_key do |client| client.close end end |
#host ⇒ Object
152 153 154 |
# File 'lib/droonga/client/connection/droonga-protocol/thread.rb', line 152 def host @socket.addr[3] end |
#port ⇒ Object
156 157 158 |
# File 'lib/droonga/client/connection/droonga-protocol/thread.rb', line 156 def port @socket.addr[1] end |
#receive(options = {}, &block) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/droonga/client/connection/droonga-protocol/thread.rb', line 161 def receive(={}, &block) timeout = [:timeout] catch do |tag| loop do start = Time.new readable_ios, = IO.select(@read_ios, nil, nil, timeout) break if readable_ios.nil? if timeout timeout -= (Time.now - start) timeout = 0 if timeout < 0 end readable_ios.each do |readable_io| on_readable(readable_io) do |object| begin yield(object) rescue LocalJumpError throw(tag) end end end end end end |