diff options
| -rw-r--r-- | lib/tasklib.lua | 42 | 
1 files changed, 37 insertions, 5 deletions
| diff --git a/lib/tasklib.lua b/lib/tasklib.lua index fc2ce51..dbd2284 100644 --- a/lib/tasklib.lua +++ b/lib/tasklib.lua @@ -19,7 +19,7 @@   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   */ -/* $Id: tasklib.lua,v 1.6 2008-02-15 15:01:52 pixel Exp $ */ +/* $Id: tasklib.lua,v 1.7 2008-02-17 00:48:38 pixel Exp $ */  ]]-- @@ -27,13 +27,20 @@  -- Create some simple bindings for the LuaTask system to hide the various ugly yields.  -- -local nb_clients = 0 +local nb_clients_per_hosts = {} +local max_clients_per_hosts = 5  function HttpClient(url, headers, vars) -    if nb_clients >= 5 then +    local host, nb_clients = string.match(url, "http://([^/]*)/"), 0 +    if host then +	nb_clients = nb_clients_per_hosts[host] or 0 +    end +    if nb_clients >= max_clients_per_hosts then          return Buffer()      end -    nb_clients = nb_clients + 1 +    if host then +	nb_clients_per_hosts[host] = nb_clients + 1 +    end      if type(headers) == "nil" then          headers = {}      end @@ -42,7 +49,32 @@ function HttpClient(url, headers, vars)      end      headers["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) Gecko/20061010 Firefox/2.0"      local r = coroutine.yield("HttpClient", url, headers, vars) -    nb_clients = nb_clients - 1 +    if host then +	nb_clients_per_hosts[host] = nb_clients_per_hosts[host] - 1 +    end +    return r +end + +function MaxNbClients(n) +    local r = max_clients_per_hosts + +    if n then     +        max_clients_per_hosts = n +    end +     +    return r +end + +function GetNbClients(host) +    if host then +	return nb_clients_per_hosts[host] or 0 +    end +     +    local r, k, v = {} +    for k, v in pairs(nb_clients_per_hosts) do +	r[k] = v +    end +          return r  end | 
