Class: Wsv::Server
- Inherits:
-
Object
- Object
- Wsv::Server
- Defined in:
- lib/wsv/server.rb,
lib/wsv/server/banner.rb,
lib/wsv/server/url_host.rb,
lib/wsv/server/connection.rb,
lib/wsv/server/deadline_reader.rb,
lib/wsv/server/browser_launcher.rb,
lib/wsv/server/connection_throttle.rb
Defined Under Namespace
Modules: UrlHost Classes: Banner, BrowserLauncher, Connection, ConnectionThrottle, DeadlineReader
Constant Summary collapse
- DEFAULT_READ_TIMEOUT =
10- DEFAULT_MAX_CONNECTIONS =
8
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(host:, port:, root:, out: $stdout, err: $stderr, read_timeout: DEFAULT_READ_TIMEOUT, max_connections: DEFAULT_MAX_CONNECTIONS, tls: nil, spa: false, open: false, cors: false) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(host:, port:, root:, out: $stdout, err: $stderr, read_timeout: DEFAULT_READ_TIMEOUT, max_connections: DEFAULT_MAX_CONNECTIONS, tls: nil, spa: false, open: false, cors: false) ⇒ Server
Returns a new instance of Server.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wsv/server.rb', line 18 def initialize( host:, port:, root:, out: $stdout, err: $stderr, read_timeout: DEFAULT_READ_TIMEOUT, max_connections: DEFAULT_MAX_CONNECTIONS, tls: nil, spa: false, open: false, cors: false ) @host = host @port = port @root = File.realpath(root) @out = out @err = err @read_timeout = read_timeout @tls = tls @ssl_context = tls&.to_ssl_context @open = open @app = App.new(@root, spa: spa, cors: cors) @throttle = ConnectionThrottle.new(max: max_connections, err: err) @running = false end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
16 17 18 |
# File 'lib/wsv/server.rb', line 16 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
16 17 18 |
# File 'lib/wsv/server.rb', line 16 def port @port end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
16 17 18 |
# File 'lib/wsv/server.rb', line 16 def root @root end |
Instance Method Details
#start ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/wsv/server.rb', line 45 def start @server = TCPServer.new(host, port) @running = true log_startup trap_signals open_in_browser if @open accept_loop ensure close end |
#stop ⇒ Object
56 57 58 59 |
# File 'lib/wsv/server.rb', line 56 def stop @running = false close end |