Class: Carnivore::UnixSocket::Util::Server
- Inherits:
-
Object
- Object
- Carnivore::UnixSocket::Util::Server
- Includes:
- Carnivore::Utils::Logging, Celluloid
- Defined in:
- lib/carnivore-unixsocket/util/socket_server.rb
Instance Attribute Summary collapse
-
#notify_actor ⇒ Object
readonly
Returns the value of attribute notify_actor.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#supervisor ⇒ Object
readonly
Returns the value of attribute supervisor.
Instance Method Summary collapse
- #add_lines(lines) ⇒ Object
-
#initialize(args = {}) ⇒ Server
constructor
A new instance of Server.
- #return_lines ⇒ Object
- #setup_server! ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Server
Returns a new instance of Server.
14 15 16 17 18 19 |
# File 'lib/carnivore-unixsocket/util/socket_server.rb', line 14 def initialize(args={}) @path = ::File.(args[:path]) @notify_actor = args[:notify_actor] @supervisor = Celluloid::SupervisionGroup.run! = [] end |
Instance Attribute Details
#notify_actor ⇒ Object (readonly)
Returns the value of attribute notify_actor.
12 13 14 |
# File 'lib/carnivore-unixsocket/util/socket_server.rb', line 12 def notify_actor @notify_actor end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/carnivore-unixsocket/util/socket_server.rb', line 12 def path @path end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
12 13 14 |
# File 'lib/carnivore-unixsocket/util/socket_server.rb', line 12 def server @server end |
#supervisor ⇒ Object (readonly)
Returns the value of attribute supervisor.
12 13 14 |
# File 'lib/carnivore-unixsocket/util/socket_server.rb', line 12 def supervisor @supervisor end |
Instance Method Details
#add_lines(lines) ⇒ Object
46 47 48 49 50 |
# File 'lib/carnivore-unixsocket/util/socket_server.rb', line 46 def add_lines(lines) lines = [lines] unless lines.is_a?(Array) += lines notify_actor.signal(:new_socket_lines) end |
#return_lines ⇒ Object
52 53 54 55 56 |
# File 'lib/carnivore-unixsocket/util/socket_server.rb', line 52 def return_lines msgs = .dup .clear msgs end |
#setup_server! ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/carnivore-unixsocket/util/socket_server.rb', line 37 def setup_server! unless(@server) if(::File.exists?(path)) ::File.delete(path) end @server = Celluloid::IO::UNIXServer.new(path) end end |
#start ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/carnivore-unixsocket/util/socket_server.rb', line 21 def start srv_actor = current_actor defer do loop do setup_server! debug 'Waiting for new connection to server' connection = server.accept debug 'Received new connection to server. Setting up connection...' supervisor.supervise_as("con_#{connection.hash}", Connection, :io => connection, :server => srv_actor, :auto_consume => true ) debug 'Connection setup complete and active' end end end |