net.*: Remove use of module() function

This commit is contained in:
Kim Alvefur 2015-02-21 10:45:24 +01:00
parent 27265c20e2
commit 69652ea24b
5 changed files with 44 additions and 34 deletions

View file

@ -16,9 +16,9 @@ local coroutine, tostring, pcall = coroutine, tostring, pcall;
local function dummy_send(sock, data, i, j) return (j-i)+1; end
module "adns"
local _ENV = nil;
function lookup(handler, qname, qtype, qclass)
local function lookup(handler, qname, qtype, qclass)
return coroutine.wrap(function (peek)
if peek then
log("debug", "Records for %s already cached, using those...", qname);
@ -43,12 +43,12 @@ function lookup(handler, qname, qtype, qclass)
end)(dns.peek(qname, qtype, qclass));
end
function cancel(handle, call_handler, reason)
local function cancel(handle, call_handler, reason)
log("warn", "Cancelling DNS lookup for %s", tostring(handle[3]));
dns.cancel(handle[1], handle[2], handle[3], handle[4], call_handler);
end
function new_async_socket(sock, resolver)
local function new_async_socket(sock, resolver)
local peername = "<unknown>";
local listener = {};
local handler = {};
@ -88,4 +88,8 @@ end
dns.socket_wrapper_set(new_async_socket);
return _M;
return {
lookup = lookup;
cancel = cancel;
new_async_socket = new_async_socket;
};

View file

@ -2,14 +2,17 @@
local log = require "util.logger".init("net.connlisteners");
local traceback = debug.traceback;
module "httpserver"
local _ENV = nil;
function fail()
local function fail()
log("error", "Attempt to use legacy connlisteners API. For more info see http://prosody.im/doc/developers/network");
log("error", "Legacy connlisteners API usage, %s", traceback("", 2));
end
register, deregister = fail, fail;
get, start = fail, fail, epic_fail;
return _M;
return {
register = fail;
register = fail;
get = fail;
start = fail;
-- epic fail
};

View file

@ -71,8 +71,8 @@ local get, set = ztact.get, ztact.set;
local default_timeout = 15;
-------------------------------------------------- module dns
module('dns')
local dns = _M;
local _ENV = nil;
local dns = {};
-- dns type & class codes ------------------------------ dns type & class codes

View file

@ -24,7 +24,7 @@ local assert, error = assert, error
local log = require "util.logger".init("http");
module "http"
local _ENV = nil;
local requests = {}; -- Open requests
@ -76,6 +76,13 @@ function listener.ondetach(conn)
requests[conn] = nil;
end
local function destroy_request(request)
if request.conn then
request.conn = nil;
request.handler:close()
end
end
local function request_reader(request, data, err)
if not request.parser then
local function error_cb(reason)
@ -107,7 +114,7 @@ local function request_reader(request, data, err)
end
local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end
function request(u, ex, callback)
local function request(u, ex, callback)
local req = url.parse(u);
if not (req and req.host) then
@ -189,17 +196,12 @@ function request(u, ex, callback)
return req;
end
function destroy_request(request)
if request.conn then
request.conn = nil;
request.handler:close()
end
end
local urlencode, urldecode = util_http.urlencode, util_http.urldecode;
local formencode, formdecode = util_http.formencode, util_http.formdecode;
_M.urlencode, _M.urldecode = urlencode, urldecode;
_M.formencode, _M.formdecode = formencode, formdecode;
return _M;
return {
request = request;
-- COMPAT
urlencode = util_http.urlencode;
urldecode = util_http.urldecode;
formencode = util_http.formencode;
formdecode = util_http.formdecode;
};

View file

@ -2,14 +2,15 @@
local log = require "util.logger".init("net.httpserver");
local traceback = debug.traceback;
module "httpserver"
local _ENV = nil;
function fail()
log("error", "Attempt to use legacy HTTP API. For more info see http://prosody.im/doc/developers/legacy_http");
log("error", "Legacy HTTP API usage, %s", traceback("", 2));
end
new, new_from_config = fail, fail;
set_default_handler = fail;
return _M;
return {
new = fail;
new_from_config = fail;
set_default_handler = fail;
};