Sha256: e45c1127c62fbaa0723a769866127846e548e116b5a444b4ae4753c23739e004

Contents?: true

Size: 818 Bytes

Versions: 10

Compression:

Stored size: 818 Bytes

Contents

require 'socket'

module Bluepill
  module Socket
    TIMEOUT = 10
    extend self

    def client(base_dir, name)
      UNIXSocket.open(socket_path(base_dir, name))
    end
    
    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
    
    def socket_path(base_dir, name)
      File.join(base_dir, 'socks', name + ".sock") 
    end
  end
end
 

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
wijet-bluepill-0.0.33 lib/bluepill/socket.rb
bluepill-0.0.32 lib/bluepill/socket.rb
bluepill-0.0.31 lib/bluepill/socket.rb
bluepill-0.0.30 lib/bluepill/socket.rb
bluepill-0.0.28 lib/bluepill/socket.rb
bluepill-0.0.27 lib/bluepill/socket.rb
gvarela-bluepill-0.0.28 lib/bluepill/socket.rb
gvarela-bluepill-0.0.27 lib/bluepill/socket.rb
bluepill-0.0.26 lib/bluepill/socket.rb
bluepill-0.0.25 lib/bluepill/socket.rb