class BilibiliSunday::Server
Constants
- DEFAULT_PORT
Public Class Methods
new(port = DEFAULT_PORT, working_dir = nil)
click to toggle source
# File lib/bilibili_sunday/server.rb, line 109 def initialize(port = DEFAULT_PORT, working_dir = nil) @port = port @downloader = Downloader.new(working_dir || File.expand_path("~/.bilibili_sunday")) end
Public Instance Methods
start()
click to toggle source
# File lib/bilibili_sunday/server.rb, line 114 def start @running = true @downloader_thread = Thread.new do while true @downloader.routine_work sleep 1 end end @rpc_server_thread = Thread.new do begin server = WEBrick::HTTPServer.new(:Port => @port) server.mount "/jsonrpc", Servlet, @downloader server.start rescue ensure server.shutdown end end while true unless @running @downloader_thread.terminate @rpc_server_thread.terminate break end sleep 1 end end
stop()
click to toggle source
# File lib/bilibili_sunday/server.rb, line 145 def stop @running = false end