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.
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 44 45 |
# File 'lib/wsv/server.rb', line 19 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 @cors = Cors.new if cors @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.
17 18 19 |
# File 'lib/wsv/server.rb', line 17 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
17 18 19 |
# File 'lib/wsv/server.rb', line 17 def port @port end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
17 18 19 |
# File 'lib/wsv/server.rb', line 17 def root @root end |
Instance Method Details
#start ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/wsv/server.rb', line 47 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
58 59 60 61 |
# File 'lib/wsv/server.rb', line 58 def stop @running = false close end |