webmcp

changeset 336:209d378c0a3b

Detect interval handlers with duplicate name; Added documentation for listen{...}
author jbe
date Tue Mar 24 18:26:27 2015 +0100 (2015-03-24)
parents 75be5e3f3581
children d8baa0f30731
files framework/bin/mcp.lua framework/env/param/get_list.lua
line diff
     1.1 --- a/framework/bin/mcp.lua	Tue Mar 24 17:38:50 2015 +0100
     1.2 +++ b/framework/bin/mcp.lua	Tue Mar 24 18:26:27 2015 +0100
     1.3 @@ -280,6 +280,52 @@
     1.4    execute.postfork_initializers()
     1.5  end
     1.6  
     1.7 +--[[--
     1.8 +listen{
     1.9 +  {
    1.10 +    proto     = proto,            -- "local", "tcp4", "tcp6", or "interval"
    1.11 +    path      = path,             -- path to unix domain socket if proto == "local"
    1.12 +    port      = port,             -- TCP port number
    1.13 +    localhost = localhost_only,   -- set to true to only listen on localhost (127.0.0.1 or ::1) interface
    1.14 +    name      = interval_name,    -- optional interval name (may be useful for log output)
    1.15 +    handler   = interval_handler  -- interval handler if proto == "interval"
    1.16 +  },
    1.17 +  {
    1.18 +    ...                           -- second listener
    1.19 +  },
    1.20 +  ...                             -- more listeners
    1.21 +  -- the following options are all optional and have default values:
    1.22 +  pre_fork         = pre_fork,          -- desired number of spare (idle) processes
    1.23 +  min_fork         = min_fork,          -- minimum number of processes
    1.24 +  max_fork         = max_fork,          -- maximum number of processes (hard limit)
    1.25 +  fork_delay       = fork_delay,        -- delay (seconds) between creation of spare processes
    1.26 +  fork_error_delay = fork_error_delay,  -- delay (seconds) before retry of failed process creation
    1.27 +  exit_delay       = exit_delay,        -- delay (seconds) between destruction of excessive spare processes
    1.28 +  idle_timeout     = idle_timeout,      -- idle time (seconds) after a fork gets terminated (0 for no timeout)
    1.29 +  memory_limit     = memory_limit,      -- maximum memory consumption (bytes) before process gets terminated
    1.30 +  min_requests_per_fork = min_requests_per_fork,  -- minimum count of requests handled before fork is terminated
    1.31 +  max_requests_per_fork = max_requests_per_fork,  -- maximum count of requests handled before fork is terminated
    1.32 +  http_options = {
    1.33 +    static_headers            = static_headers,            -- string or table of static headers to be returned with every request
    1.34 +    request_body_size_limit   = request_body_size_limit,   -- maximum size of request body sent by client
    1.35 +    request_header_timeout    = request_header_timeout,    -- time after which request headers must have been received and processed
    1.36 +    timeout                   = timeout,                   -- time in which request body and response must be sent
    1.37 +    minimum_output_chunk_size = minimum_output_chunk_size  -- chunk size for chunked-transfer-encoding
    1.38 +  }
    1.39 +}
    1.40 +
    1.41 +The listen{...} function determines on which TCP port an application is answering requests. A typical call looks as follows:
    1.42 +
    1.43 +listen{
    1.44 +  { proto = "tcp4", port = 8080, localhost = true },
    1.45 +  { proto = "tcp6", port = 8080, localhost = true }
    1.46 +}
    1.47 +
    1.48 +This function must be called in a configuration file (in the config/ directory) or in pre-fork initializers (in the app/_prefork/ or app/<application name>/_prefork/ directories), unless WebMCP is invoked in interactive mode (in which case any calls of listen{...} are ignored).
    1.49 +
    1.50 +This function is a variant of Moonbridge's listen{...} function which has been wrapped for WebMCP. No "prepare", "conenct", or "finish" handler can be set. Instead WebMCP automatically dispatches incoming connections. For interval timers, an interval handler may be specified in each listener.
    1.51 +
    1.52 +--]]--
    1.53  -- prepare for interactive or listen mode
    1.54  if WEBMCP_MODE == "interactive" then
    1.55    function listen()  -- overwrite Moonbridge's listen function
    1.56 @@ -297,6 +343,9 @@
    1.57      for j, listener in ipairs(args) do
    1.58        if listener.proto == "interval" then
    1.59          local name = listener.name or "Unnamed interval #" .. #interval_handlers+1
    1.60 +        if interval_handlers[name] ~= nil then
    1.61 +          error('Interval handler with duplicate name "' .. name .. '"')
    1.62 +        end
    1.63          interval_handlers[name] = listener.handler
    1.64          listener.name = name
    1.65        end
    1.66 @@ -329,6 +378,7 @@
    1.67      moonbridge_listen(args)
    1.68    end
    1.69  end
    1.70 +--//--
    1.71  
    1.72  -- execute configurations and pre-fork initializers
    1.73  for i, config_name in ipairs(WEBMCP_CONFIG_NAMES) do
     2.1 --- a/framework/env/param/get_list.lua	Tue Mar 24 17:38:50 2015 +0100
     2.2 +++ b/framework/env/param/get_list.lua	Tue Mar 24 18:26:27 2015 +0100
     2.3 @@ -2,7 +2,7 @@
     2.4  values =         -- list of values casted to the chosen param_type
     2.5  param.get_list(
     2.6    key,           -- name of the parameter without "[]" suffix
     2.7 -  param_type,    -- desired type of the returned values
     2.8 +  param_type     -- desired type of the returned values
     2.9  )
    2.10  
    2.11  Same as param.get(...), but used for parameters which contain a list of values. For external GET/POST parameters the parameter name gets suffixed with "[]".

Impressum / About Us