Sha256: 85da32bc6289dd5d746405a19bcd05fad764c272dd403542449b1f5e8f765439

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

class FluQ::Input::Socket < FluQ::Input::Base

  # @attr_reader [URI] url the URL
  attr_reader :url

  # Constructor.
  # @option options [String] :bind the URL to bind to
  # @raises [ArgumentError] when no bind URL provided
  # @raises [URI::InvalidURIError] if invalid URL is given
  # @example Launch a server
  #
  #   server = FluQ::Server.new(reactor, bind: "tcp://localhost:7654")
  #
  def initialize(*)
    super

    raise ArgumentError, 'No URL to bind to provided, make sure you pass :bind option' unless config[:bind]
    @url = FluQ::URL.parse(config[:bind], protocols)
  end

  # @return [String] descriptive name
  def name
    @name ||= "#{super} (#{@url})"
  end

  # Start the server
  def run
    args = [self.class::Connection, self]
    case @url.scheme
    when 'tcp'
      EventMachine.start_server @url.host, @url.port, *args
    when 'udp'
      EventMachine.open_datagram_socket @url.host, @url.port, *args
    when 'unix'
      EventMachine.start_server @url.path, *args
    end
  end

  protected

    # @return [Array] supported protocols
    def protocols
      ["tcp", "udp", "unix"]
    end

end

%w'connection'.each do |name|
  require "fluq/input/socket/#{name}"
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fluq-0.7.5 lib/fluq/input/socket.rb
fluq-0.7.3 lib/fluq/input/socket.rb
fluq-0.7.1 lib/fluq/input/socket.rb
fluq-0.7.0 lib/fluq/input/socket.rb