Module: Bluepill::Socket
Constant Summary collapse
- TIMEOUT =
10
Instance Method Summary collapse
- #client(base_dir, name) ⇒ Object
- #server(base_dir, name) ⇒ Object
- #socket_path(base_dir, name) ⇒ Object
Instance Method Details
#client(base_dir, name) ⇒ Object
8 9 10 |
# File 'lib/bluepill/socket.rb', line 8 def client(base_dir, name) UNIXSocket.open(socket_path(base_dir, name)) end |
#server(base_dir, name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bluepill/socket.rb', line 12 def server(base_dir, name) socket_path = self.socket_path(base_dir, name) begin UNIXServer.open(socket_path) rescue Errno::EADDRINUSE # if sock file has been created. test to see if there is a server begin return UNIXSocket.open(socket_path) rescue Errno::ECONNREFUSED File.delete(socket_path) return UNIXServer.open(socket_path) else logger.err("Server is already running!") exit(7) end end end |
#socket_path(base_dir, name) ⇒ Object
30 31 32 |
# File 'lib/bluepill/socket.rb', line 30 def socket_path(base_dir, name) File.join(base_dir, 'socks', name + ".sock") end |