Class: David::Server
- Inherits:
-
Object
- Object
- David::Server
- Defined in:
- lib/david/server.rb,
lib/david/server/mapping.rb,
lib/david/server/respond.rb,
lib/david/server/utility.rb,
lib/david/server/constants.rb,
lib/david/server/multicast.rb
Defined Under Namespace
Modules: Constants, Mapping, Multicast, Respond, Utility
Constant Summary
Constants included from Mapping
Mapping::HTTP_TO_COAP_CODES, Mapping::HTTP_TO_COAP_CODES_MINIMAL
Constants included from Constants
Constants::ASCII_8BIT, Constants::COAP_CBOR, Constants::COAP_DTLS, Constants::COAP_DTLS_ID, Constants::COAP_DTLS_NOSEC, Constants::COAP_MULTICAST, Constants::COAP_VERSION, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::CONTENT_TYPE_CBOR, Constants::CONTENT_TYPE_JSON, Constants::EMPTY_STRING, Constants::HTTP_ACCEPT, Constants::HTTP_CACHE_CONTROL, Constants::HTTP_CONTENT_LENGTH, Constants::HTTP_CONTENT_TYPE, Constants::HTTP_ETAG, Constants::HTTP_LOCATION, Constants::PATH_INFO, Constants::QUERY_STRING, Constants::RACK_ERRORS, Constants::RACK_INPUT, Constants::RACK_LOGGER, Constants::RACK_MULTIPROCESS, Constants::RACK_MULTITHREAD, Constants::RACK_RUN_ONCE, Constants::RACK_URL_SCHEME, Constants::RACK_URL_SCHEME_HTTP, Constants::RACK_VERSION, Constants::REMOTE_ADDR, Constants::REMOTE_PORT, Constants::REQUEST_METHOD, Constants::SCRIPT_NAME, Constants::SERVER_NAME, Constants::SERVER_PORT
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #answer(exchange, key = nil) ⇒ Object
-
#initialize(app, options) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Methods included from Respond
Methods included from Multicast
Methods included from MidCache
#cache, #cache_add, #cache_clean!, #cache_delete, #cache_get, included
Constructor Details
#initialize(app, options) ⇒ Server
Returns a new instance of Server.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/david/server.rb', line 21 def initialize(app, ) @app = app.respond_to?(:new) ? app.new : app @mid_cache = {} = AppConfig.new() @log = [:Log] host, port = .values_at(:Host, :Port) log.info "David #{David::VERSION} on #{RUBY_DESCRIPTION}" log.info "Starting on coap://[#{host}]:#{port}" af = ipv6? ? ::Socket::AF_INET6 : ::Socket::AF_INET # Actually Celluloid::IO::UDPSocket. @socket = UDPSocket.new(af) multicast_initialize! if [:Multicast] @socket.bind(host, port) end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
17 18 19 |
# File 'lib/david/server.rb', line 17 def log @log end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
17 18 19 |
# File 'lib/david/server.rb', line 17 def socket @socket end |
Instance Method Details
#answer(exchange, key = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/david/server.rb', line 55 def answer(exchange, key = nil) @socket.send(exchange..to_wire, 0, exchange.host, exchange.port) if log.info? log.info('-> ' + exchange.to_s) log.debug(exchange..inspect) end cache_add(exchange.key, exchange.) if exchange.ack? end |
#run ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/david/server.rb', line 40 def run loop do if jruby_or_rbx? dispatch(*@socket.recvfrom(1152)) else begin dispatch(*@socket.to_io.recvmsg_nonblock) rescue ::IO::WaitReadable Celluloid::IO.wait_readable(@socket) retry end end end end |