Class: SWS::Adaptor::Standalone

Inherits:
Generic
  • Object
show all
Defined in:
lib/sws/adaptor.rb

Overview

Adaptor listening on a TCPport

Constant Summary

Constants inherited from Generic

Generic::HEADER_TRANSLATION

Instance Attribute Summary collapse

Attributes inherited from Generic

#base_path

Instance Method Summary collapse

Constructor Details

#initialize(port = 1234) ⇒ Standalone

Creates new adaptor listening on a given port



59
60
61
62
63
64
65
# File 'lib/sws/adaptor.rb', line 59

def initialize ( port = 1234 )

	@port = port
	#Always "/" for this class, as the application listens on its own port
	@base_path = "/"

end

Instance Attribute Details

#portObject

Returns the value of attribute port.



56
57
58
# File 'lib/sws/adaptor.rb', line 56

def port
  @port
end

Instance Method Details

#each_requestObject

Main adaptor method - invokes block for each received request



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/sws/adaptor.rb', line 75

def each_request ()

	while ( socket = @server.accept() )

		request = create_request( socket )
		response = yield( request )
		begin
			socket.print( "#{response.http_version} #{response.status}\r\n" )
			socket.print( response.to_s )						
			socket.close()
		rescue => exception
			$log_sws_request.warn( "Exception #{exception.class} when writing response: #{exception.message}" )
		end

	end

end

#runObject

Start listening for request



69
70
71
# File 'lib/sws/adaptor.rb', line 69

def run ()
	@server = TCPServer.new( @port )
end