class Grocer::Server

Attributes

notifications[R]

Public Class Methods

new(server) click to toggle source
# File lib/grocer/server.rb, line 10
def initialize(server)
  @server = server

  @clients = []
  @notifications = Queue.new
end

Public Instance Methods

accept() click to toggle source
# File lib/grocer/server.rb, line 17
def accept
  Thread.new {
    begin
      @server.accept { |client|
        @clients << client

        Thread.new {
          begin
            NotificationReader.new(client).each(&notifications.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() click to toggle source
# File lib/grocer/server.rb, line 37
def close
  if @server
    @server.close
    @server = nil
  end

  @clients.each(&:close)
  @clients = []
end