Project

General

Profile

Download (1.62 KB) Statistics
| Branch: | Tag: | Revision:
ecdabe95 Marc Dequènes (Duck)
#--
# CyborgHood, a distributed system management software.
364e4a96 Marc Dequènes (Duck)
# Copyright (c) 2009-2011 Marc Dequènes (Duck) <Duck@DuckCorp.org>
ecdabe95 Marc Dequènes (Duck)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++


module CyborgHood
d7ae0ab2 Marc Dequènes (Duck)
module BotNetUNIXSocket
def identifier_prefix
"unix_socket"
end

bc642412 Marc Dequènes (Duck)
def setup
super
d7ae0ab2 Marc Dequènes (Duck)
@pending_conversation_close = Set.new

d6ea2c18 Marc Dequènes (Duck)
@socket = peer_socket(@name)
ecdabe95 Marc Dequènes (Duck)
at_exit { remove_socket_file }
end

bc642412 Marc Dequènes (Duck)
def start_work
super
EventMachine.start_unix_domain_server(@socket, Conversation, self)
ecdabe95 Marc Dequènes (Duck)
end

d7ae0ab2 Marc Dequènes (Duck)
def peer_socket(peer)
File.join(Config::RUN_DIR, peer.downcase + ".sock")
end

429ebb9c Marc Dequènes (Duck)
def contact_peer(peer, dont_open_new_connection = false, &block)
super(peer, block, dont_open_new_connection) do |callback|
d7ae0ab2 Marc Dequènes (Duck)
EventMachine.connect_unix_domain(peer_socket(peer), Conversation, self, callback)
end
ecdabe95 Marc Dequènes (Duck)
end
bc642412 Marc Dequènes (Duck)
# backend-specific capabilities
def capabilities
super + []
end
476368e8 Marc Dequènes (Duck)
d7ae0ab2 Marc Dequènes (Duck)
def remove_socket_file
File.delete(@socket) if @socket && File.exist?(@socket)
476368e8 Marc Dequènes (Duck)
end
d1e614b5 Marc Dequènes (Duck)
end
ecdabe95 Marc Dequènes (Duck)
end