8 local EV_READ = luaevent.core.EV_READ |
8 local EV_READ = luaevent.core.EV_READ |
9 local EV_WRITE = luaevent.core.EV_WRITE |
9 local EV_WRITE = luaevent.core.EV_WRITE |
10 local fair = false |
10 local fair = false |
11 |
11 |
12 local hookedObjectMt = false |
12 local hookedObjectMt = false |
13 |
|
14 -- Weak keys.. the keys are the client sockets |
|
15 local clientTable = setmetatable({}, {'__mode', 'k'}) |
|
16 |
13 |
17 function send(sock, data, start, stop) |
14 function send(sock, data, start, stop) |
18 local s, err |
15 local s, err |
19 local from = start or 1 |
16 local from = start or 1 |
20 local sent = 0 |
17 local sent = 0 |
77 local client = sock:accept() |
74 local client = sock:accept() |
78 if client then |
75 if client then |
79 --cl[#cl + 1] = client |
76 --cl[#cl + 1] = client |
80 client:settimeout(0) |
77 client:settimeout(0) |
81 local coFunc = coroutine.wrap(clientCoroutine) |
78 local coFunc = coroutine.wrap(clientCoroutine) |
82 clientTable[client] = luaevent.core.addevent(client, coFunc, client, callback) |
79 luaevent.core.addevent(client, coFunc, client, callback) |
83 end |
80 end |
84 until false |
81 until false |
85 end |
82 end |
86 |
83 |
87 local oldAddEvent = luaevent.core.addevent |
84 local oldAddEvent = luaevent.core.addevent |
101 return item |
98 return item |
102 end |
99 end |
103 |
100 |
104 function addserver(sock, callback) |
101 function addserver(sock, callback) |
105 local coFunc = coroutine.wrap(serverCoroutine) |
102 local coFunc = coroutine.wrap(serverCoroutine) |
106 clientTable[sock] = luaevent.core.addevent(sock, coFunc, sock, callback) |
103 luaevent.core.addevent(sock, coFunc, sock, callback) |
107 end |
104 end |
108 function addthread(sock, func, ...) |
105 function addthread(sock, func, ...) |
109 local coFunc = coroutine.wrap(func) |
106 local coFunc = coroutine.wrap(func) |
110 clientTable[sock] = luaevent.core.addevent(sock, coFunc, ...) |
107 luaevent.core.addevent(sock, coFunc, ...) |
111 end |
108 end |
112 local _skt_mt = {__index = { |
109 local _skt_mt = {__index = { |
113 connect = function(self, ...) |
110 connect = function(self, ...) |
114 return connect(self.socket, ...) |
111 return connect(self.socket, ...) |
115 end, |
112 end, |