Class: Sanford::Server

Inherits:
Object
  • Object
show all
Includes:
DatTCP::Server
Defined in:
lib/sanford/server.rb

Defined Under Namespace

Classes: Connection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, options = {}) ⇒ Server

Returns a new instance of Server.



14
15
16
17
# File 'lib/sanford/server.rb', line 14

def initialize(host, options = {})
  @host_data = host.kind_of?(Sanford::HostData) ? host : Sanford::HostData.new(host)
  super(@host_data.ip, @host_data.port, options)
end

Instance Attribute Details

#host_dataObject (readonly)

Returns the value of attribute host_data.



12
13
14
# File 'lib/sanford/server.rb', line 12

def host_data
  @host_data
end

Instance Method Details

#inspectObject



29
30
31
32
# File 'lib/sanford/server.rb', line 29

def inspect
  reference = '0x0%x' % (self.object_id << 1)
  "#<#{self.class}:#{reference} @service_host=#{@host_data.inspect}>"
end

#nameObject



19
20
21
# File 'lib/sanford/server.rb', line 19

def name
  @host_data.name
end

#serve(socket) ⇒ Object

‘serve` can be called at the same time by multiple threads. Thus we create a new instance of the handler for every request.



25
26
27
# File 'lib/sanford/server.rb', line 25

def serve(socket)
  Sanford::Worker.new(@host_data, Connection.new(socket)).run
end