Class: Grocer::Server
- Inherits:
-
Object
- Object
- Grocer::Server
- Defined in:
- lib/grocer/server.rb
Instance Attribute Summary collapse
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
Instance Method Summary collapse
- #accept ⇒ Object
- #close ⇒ Object
-
#initialize(server) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(server) ⇒ Server
Returns a new instance of Server.
10 11 12 13 14 15 |
# File 'lib/grocer/server.rb', line 10 def initialize(server) @server = server @clients = [] @notifications = Queue.new end |
Instance Attribute Details
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
8 9 10 |
# File 'lib/grocer/server.rb', line 8 def notifications @notifications end |
Instance Method Details
#accept ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/grocer/server.rb', line 17 def accept Thread.new { begin @server.accept { |client| @clients << client Thread.new { begin NotificationReader.new(client).each(¬ifications.method(:push)) rescue Errno::EBADF, NoMethodError, OpenSSL::OpenSSLError # Expected when another thread closes the socket end } } rescue Errno::EBADF # Expected when another thread closes the socket end } end |
#close ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/grocer/server.rb', line 37 def close if @server @server.close @server = nil end @clients.each(&:close) @clients = [] end |