diff options
| author | ruki <[email protected]> | 2022-04-06 00:54:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-06 00:54:38 +0800 |
| commit | adb0d9cf10af42d491371fbf2504d9de8af159fd (patch) | |
| tree | c349b60a05e17b201cec53a076aef1c886e3199c | |
| parent | 913dd698032feb120b1c98d116aab3a89782be3d (diff) | |
add stream stub
| -rw-r--r-- | xmake/core/base/bytes.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/private/service/server/server.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/private/service/stream.lua | 64 |
3 files changed, 82 insertions, 0 deletions
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua index bb65d0cfc..199d071f0 100644 --- a/xmake/core/base/bytes.lua +++ b/xmake/core/base/bytes.lua @@ -461,6 +461,14 @@ function bytes.new(...) return _instance.new(...) end +-- is instance of bytes? +function bytes.instance_of(data) + if type(data) == "table" and data.cdata and data.size then + return true + end + return false +end + -- register call function setmetatable(bytes, { __call = function (_, ...) diff --git a/xmake/modules/private/service/server/server.lua b/xmake/modules/private/service/server/server.lua index d49b7951d..70727306a 100644 --- a/xmake/modules/private/service/server/server.lua +++ b/xmake/modules/private/service/server/server.lua @@ -22,6 +22,7 @@ import("core.base.object") import("core.base.socket") import("core.base.scheduler") +import("private.service.stream") -- define module local server = server or object() @@ -29,6 +30,12 @@ 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? @@ -126,6 +133,9 @@ function server:_handle_session(sock) while true do real, data = sock:recv(8192) if real > 0 then + if data then + self:stream():write_bytes(data) + end recv = recv + real wait = false elseif real == 0 and not wait then diff --git a/xmake/modules/private/service/stream.lua b/xmake/modules/private/service/stream.lua new file mode 100644 index 000000000..5910ce8d9 --- /dev/null +++ b/xmake/modules/private/service/stream.lua @@ -0,0 +1,64 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file stream.lua +-- + +-- imports +import("core.base.object") +import("core.base.bytes") + +-- define module +local stream = stream or object() + +-- init stream +function stream:init() +end + +-- is empty? +function stream:empty() +end + +-- write bytes +function stream:write_bytes(data) +end + +-- write table +function stream:write_table(tbl) +end + +-- write string +function stream:write_string(str) +end + +-- read bytes +function stream:read_bytes(size) +end + +-- read table +function stream:read_table() +end + +-- read string +function stream:read_string() +end + +function main() + local instance = stream() + instance:init() + return instance +end |
