Added new instalation section to the manual.

This commit is contained in:
Diego Nehab
2004-11-28 08:17:16 +00:00
parent 297b32e828
commit 534b0cedf7
17 changed files with 264 additions and 89 deletions

View File

@ -7,8 +7,11 @@
-----------------------------------------------------------------------------
-- Declare module and import dependencies
-----------------------------------------------------------------------------
module("socket")
local base = require("base")
local string = require("string")
local math = require("math")
local socket = require("lsocket")
module("socket")
-----------------------------------------------------------------------------
-- Auxiliar functions
@ -40,11 +43,11 @@ socket.try = socket.newtry()
function socket.choose(table)
return function(name, opt1, opt2)
if type(name) ~= "string" then
if base.type(name) ~= "string" then
name, opt1, opt2 = "default", name, opt1
end
local f = table[name or "nil"]
if not f then error("unknown key (" .. tostring(name) .. ")", 3)
if not f then base.error("unknown key (".. base.tostring(name) ..")", 3)
else return f(opt1, opt2) end
end
end
@ -59,7 +62,7 @@ socket.sinkt = {}
socket.BLOCKSIZE = 2048
socket.sinkt["http-chunked"] = function(sock)
return setmetatable({
return base.setmetatable({
getfd = function() return sock:getfd() end,
dirty = function() return sock:dirty() end
}, {
@ -72,7 +75,7 @@ socket.sinkt["http-chunked"] = function(sock)
end
socket.sinkt["close-when-done"] = function(sock)
return setmetatable({
return base.setmetatable({
getfd = function() return sock:getfd() end,
dirty = function() return sock:dirty() end
}, {
@ -86,7 +89,7 @@ socket.sinkt["close-when-done"] = function(sock)
end
socket.sinkt["keep-open"] = function(sock)
return setmetatable({
return base.setmetatable({
getfd = function() return sock:getfd() end,
dirty = function() return sock:dirty() end
}, {
@ -102,7 +105,7 @@ socket.sinkt["default"] = socket.sinkt["keep-open"]
socket.sink = socket.choose(socket.sinkt)
socket.sourcet["by-length"] = function(sock, length)
return setmetatable({
return base.setmetatable({
getfd = function() return sock:getfd() end,
dirty = function() return sock:dirty() end
}, {
@ -119,7 +122,7 @@ end
socket.sourcet["until-closed"] = function(sock)
local done
return setmetatable({
return base.setmetatable({
getfd = function() return sock:getfd() end,
dirty = function() return sock:dirty() end
}, {
@ -137,7 +140,7 @@ socket.sourcet["until-closed"] = function(sock)
end
socket.sourcet["http-chunked"] = function(sock)
return setmetatable({
return base.setmetatable({
getfd = function() return sock:getfd() end,
dirty = function() return sock:dirty() end
}, {
@ -145,7 +148,7 @@ socket.sourcet["http-chunked"] = function(sock)
-- get chunk size, skip extention
local line, err = sock:receive()
if err then return nil, err end
local size = tonumber(string.gsub(line, ";.*", ""), 16)
local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
if not size then return nil, "invalid chunk size" end
-- was it the last chunk?
if size <= 0 then
@ -168,3 +171,5 @@ end
socket.sourcet["default"] = socket.sourcet["until-closed"]
socket.source = socket.choose(socket.sourcet)
base.setmetatable(socket, nil)