webmcp
diff framework/bin/mcp.lua @ 316:a2c733535b8e
Support intervals; Interactive shell requires application name now
author | jbe |
---|---|
date | Mon Mar 23 16:05:56 2015 +0100 (2015-03-23) |
parents | d34b7b5e5e5c |
children | 732c4d53a823 |
line diff
1.1 --- a/framework/bin/mcp.lua Sun Mar 22 23:12:33 2015 +0100 1.2 +++ b/framework/bin/mcp.lua Mon Mar 23 16:05:56 2015 +0100 1.3 @@ -108,15 +108,12 @@ 1.4 arg2 == "-h" or arg2 == "--help" -- if first arg is provided by wrapper 1.5 then 1.6 helpout = io.stdout 1.7 - elseif 1.8 - #WEBMCP_CONFIG_NAMES < 1 or 1.9 - (WEBMCP_MODE == "interactive") ~= (arg3 == "INTERACTIVE") 1.10 - then 1.11 + elseif #WEBMCP_CONFIG_NAMES < 1 then 1.12 helpout = io.stderr 1.13 end 1.14 if helpout then 1.15 - helpout:write("Usage: moonbridge -- <framework path>/bin/mcp.lua <framework path> <app base path> <app name> <config name> [<config name> ...]\n") 1.16 - helpout:write(" or: lua -i <framework path>/bin/mcp.lua <framework path> <app base path> INTERACTIVE <config name> [<config name> ...]\n") 1.17 + helpout:write("Usage: moonbridge [moonbr opts] -- <framework path>/bin/mcp.lua <framework path> <app base path> <app name> <config name> [<config name> ...]\n") 1.18 + helpout:write(" or: lua -i [Lua opts] -- <framework path>/bin/mcp.lua <framework path> <app base path> <app name> <config name> [<config name> ...]\n") 1.19 if helpout == io.stderr then 1.20 return 1 1.21 else 1.22 @@ -128,9 +125,7 @@ 1.23 end 1.24 WEBMCP_FRAMEWORK_PATH = append_trailing_slash(arg1) 1.25 WEBMCP_BASE_PATH = append_trailing_slash(arg2) 1.26 - if WEBMCP_MODE == "listen" then 1.27 - WEBMCP_APP_NAME = arg3 1.28 - end 1.29 + WEBMCP_APP_NAME = arg3 1.30 end 1.31 1.32 -- check if framework path is correct 1.33 @@ -302,19 +297,31 @@ 1.34 local max_requests_per_fork = http_options.max_requests_per_fork or 100 1.35 local http = require("moonbridge_http") 1.36 for i, listener in ipairs(listeners) do 1.37 + local interval_handlers = {} 1.38 + for j, entry in ipairs(listener) do 1.39 + if entry.proto == "interval" then 1.40 + local name = entry.name or "Unnamed interval #" .. #interval_handlers+1 1.41 + interval_handlers[name] = entry.handler 1.42 + entry.name = name 1.43 + end 1.44 + end 1.45 local request_count = 0 1.46 local function inner_handler(http_request) 1.47 - request_count = request_count + 1 1.48 request.handler(http_request, request_count >= max_requests_per_fork) 1.49 end 1.50 local outer_handler = http.generate_handler(inner_handler, http_options) 1.51 listener.prepare = postfork_init 1.52 listener.connect = function(socket) 1.53 - outer_handler(socket) 1.54 + request_count = request_count + 1 1.55 + request.initialize() 1.56 + if socket.interval then 1.57 + interval_handlers[socket.interval]() 1.58 + else 1.59 + outer_handler(socket) 1.60 + end 1.61 return request_count < min_requests_per_fork 1.62 end 1.63 listener.finish = execute.finalizers 1.64 moonbridge_listen(listener) 1.65 end 1.66 end 1.67 -