diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2006-03-19 21:22:21 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2006-03-19 21:22:21 +0000 |
commit | 93806208c77607146f6f462426e380e732327ed5 (patch) | |
tree | ac0286d21b5d9343ab01afda6bc277e152936065 /etc | |
parent | 09ad4b299c59c3c5c6c442f0ee99f3c9e8dbe8ce (diff) | |
download | luasocket-93806208c77607146f6f462426e380e732327ed5.tar.gz luasocket-93806208c77607146f6f462426e380e732327ed5.tar.bz2 luasocket-93806208c77607146f6f462426e380e732327ed5.zip |
Updates for 2.0.1 on the way.
Diffstat (limited to 'etc')
-rw-r--r-- | etc/dispatch.lua | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/etc/dispatch.lua b/etc/dispatch.lua index dd76d6d..6f3855e 100644 --- a/etc/dispatch.lua +++ b/etc/dispatch.lua | |||
@@ -5,6 +5,7 @@ | |||
5 | -- RCS ID: $$ | 5 | -- RCS ID: $$ |
6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
7 | local base = _G | 7 | local base = _G |
8 | local table = require("table") | ||
8 | local socket = require("socket") | 9 | local socket = require("socket") |
9 | local coroutine = require("coroutine") | 10 | local coroutine = require("coroutine") |
10 | module("dispatch") | 11 | module("dispatch") |
@@ -50,7 +51,7 @@ function socket.protect(f) | |||
50 | return function(...) | 51 | return function(...) |
51 | local co = coroutine.create(f) | 52 | local co = coroutine.create(f) |
52 | while true do | 53 | while true do |
53 | local results = {coroutine.resume(co, unpack(arg))} | 54 | local results = {coroutine.resume(co, base.unpack(arg))} |
54 | local status = table.remove(results, 1) | 55 | local status = table.remove(results, 1) |
55 | if not status then | 56 | if not status then |
56 | if type(results[1]) == 'table' then | 57 | if type(results[1]) == 'table' then |
@@ -58,9 +59,9 @@ function socket.protect(f) | |||
58 | else error(results[1]) end | 59 | else error(results[1]) end |
59 | end | 60 | end |
60 | if coroutine.status(co) == "suspended" then | 61 | if coroutine.status(co) == "suspended" then |
61 | arg = {coroutine.yield(unpack(results))} | 62 | arg = {coroutine.yield(base.unpack(results))} |
62 | else | 63 | else |
63 | return unpack(results) | 64 | return base.unpack(results) |
64 | end | 65 | end |
65 | end | 66 | end |
66 | end | 67 | end |
@@ -72,7 +73,7 @@ end | |||
72 | local function newset() | 73 | local function newset() |
73 | local reverse = {} | 74 | local reverse = {} |
74 | local set = {} | 75 | local set = {} |
75 | return setmetatable(set, {__index = { | 76 | return base.setmetatable(set, {__index = { |
76 | insert = function(set, value) | 77 | insert = function(set, value) |
77 | if not reverse[value] then | 78 | if not reverse[value] then |
78 | table.insert(set, value) | 79 | table.insert(set, value) |
@@ -105,7 +106,7 @@ local function cowrap(dispatcher, tcp, error) | |||
105 | local metat = { __index = function(table, key) | 106 | local metat = { __index = function(table, key) |
106 | table[key] = function(...) | 107 | table[key] = function(...) |
107 | arg[1] = tcp | 108 | arg[1] = tcp |
108 | return tcp[key](unpack(arg)) | 109 | return tcp[key](base.unpack(arg)) |
109 | end | 110 | end |
110 | return table[key] | 111 | return table[key] |
111 | end} | 112 | end} |
@@ -202,7 +203,7 @@ local function cowrap(dispatcher, tcp, error) | |||
202 | dispatcher.receiving.cortn[tcp] = nil | 203 | dispatcher.receiving.cortn[tcp] = nil |
203 | return tcp:close() | 204 | return tcp:close() |
204 | end | 205 | end |
205 | return setmetatable(wrap, metat) | 206 | return base.setmetatable(wrap, metat) |
206 | end | 207 | end |
207 | 208 | ||
208 | 209 | ||
@@ -253,17 +254,17 @@ function cometat.__index:step() | |||
253 | self.sending.set, 1) | 254 | self.sending.set, 1) |
254 | -- for all readable connections, resume their cortns and reschedule | 255 | -- for all readable connections, resume their cortns and reschedule |
255 | -- when they yield back to us | 256 | -- when they yield back to us |
256 | for _, tcp in ipairs(readable) do | 257 | for _, tcp in base.ipairs(readable) do |
257 | schedule(wakeup(self.receiving, tcp)) | 258 | schedule(wakeup(self.receiving, tcp)) |
258 | end | 259 | end |
259 | -- for all writable connections, do the same | 260 | -- for all writable connections, do the same |
260 | for _, tcp in ipairs(writable) do | 261 | for _, tcp in base.ipairs(writable) do |
261 | schedule(wakeup(self.sending, tcp)) | 262 | schedule(wakeup(self.sending, tcp)) |
262 | end | 263 | end |
263 | -- politely ask replacement I/O functions in idle cortns to | 264 | -- politely ask replacement I/O functions in idle cortns to |
264 | -- return reporting a timeout | 265 | -- return reporting a timeout |
265 | local now = socket.gettime() | 266 | local now = socket.gettime() |
266 | for tcp, stamp in pairs(self.stamp) do | 267 | for tcp, stamp in base.pairs(self.stamp) do |
267 | if tcp.class == "tcp{client}" and now - stamp > TIMEOUT then | 268 | if tcp.class == "tcp{client}" and now - stamp > TIMEOUT then |
268 | abort(self.sending, tcp) | 269 | abort(self.sending, tcp) |
269 | abort(self.receiving, tcp) | 270 | abort(self.receiving, tcp) |
@@ -296,6 +297,6 @@ function handlert.coroutine() | |||
296 | function dispatcher.tcp() | 297 | function dispatcher.tcp() |
297 | return cowrap(dispatcher, socket.tcp()) | 298 | return cowrap(dispatcher, socket.tcp()) |
298 | end | 299 | end |
299 | return setmetatable(dispatcher, cometat) | 300 | return base.setmetatable(dispatcher, cometat) |
300 | end | 301 | end |
301 | 302 | ||