diff options
| author | ruki <[email protected]> | 2022-04-06 22:32:10 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-06 22:32:10 +0800 |
| commit | 60c78f84bcef3be6e5a906cd10fe6bc0d7b0c77c (patch) | |
| tree | bc7f7a54641fd3bf57c1558483b911807d4066d9 | |
| parent | adb0d9cf10af42d491371fbf2504d9de8af159fd (diff) | |
improve stream
| -rw-r--r-- | xmake/core/base/bytes.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/service/server/server.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/private/service/stream.lua | 31 |
3 files changed, 17 insertions, 23 deletions
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua index 199d071f0..b95260237 100644 --- a/xmake/core/base/bytes.lua +++ b/xmake/core/base/bytes.lua @@ -97,7 +97,7 @@ function _instance.new(...) os.raise("incorrect bounds(%d-%d) for bytes(...)!", start, last) end instance._SIZE = last - start + 1 - instance._CDATA = b:cdata() -1 + start + instance._CDATA = b:cdata() - 1 + start instance._REF = b -- keep lua ref for GC instance._MANAGED = false instance._READONLY = b:readonly() diff --git a/xmake/modules/private/service/server/server.lua b/xmake/modules/private/service/server/server.lua index 70727306a..e5898c416 100644 --- a/xmake/modules/private/service/server/server.lua +++ b/xmake/modules/private/service/server/server.lua @@ -30,12 +30,6 @@ local server = server or object() -- init server function server:init(daemon) self._DAEMON = daemon - self._STREAM = stream() -end - --- get stream -function server:stream() - return self._STREAM end -- is daemon? @@ -134,7 +128,6 @@ function server:_handle_session(sock) real, data = sock:recv(8192) if real > 0 then if data then - self:stream():write_bytes(data) end recv = recv + real wait = false diff --git a/xmake/modules/private/service/stream.lua b/xmake/modules/private/service/stream.lua index 5910ce8d9..437abed4a 100644 --- a/xmake/modules/private/service/stream.lua +++ b/xmake/modules/private/service/stream.lua @@ -26,39 +26,40 @@ import("core.base.bytes") local stream = stream or object() -- init stream -function stream:init() +function stream:init(sock) + self._SOCK = sock end -- is empty? function stream:empty() end --- write bytes -function stream:write_bytes(data) +-- send bytes +function stream:send_bytes(data) end --- write table -function stream:write_table(tbl) +-- send table +function stream:send_table(tbl) end --- write string -function stream:write_string(str) +-- send string +function stream:send_string(str) end --- read bytes -function stream:read_bytes(size) +-- recv bytes +function stream:recv_bytes(size) end --- read table -function stream:read_table() +-- recv table +function stream:recv_table() end --- read string -function stream:read_string() +-- recv string +function stream:recv_string() end -function main() +function main(sock) local instance = stream() - instance:init() + instance:init(sock) return instance end |
