summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-04-10 21:25:47 +0800
committerruki <[email protected]>2022-04-10 21:25:47 +0800
commitc3319aeb502825434e3055e27e4593e817e3485c (patch)
treea8d254b72ab47d265bd97017cae8d3b9aa4382d3
parent2bf71798ce8355a66868628cfe5b85c52c592366 (diff)
rename socket stream
-rw-r--r--xmake/modules/private/service/remote_build/client.lua4
-rw-r--r--xmake/modules/private/service/remote_build/server.lua7
-rw-r--r--xmake/modules/private/service/remote_build/session.lua41
-rw-r--r--xmake/modules/private/service/server.lua2
-rw-r--r--xmake/modules/private/service/stream.lua (renamed from xmake/modules/private/service/socket_stream.lua)32
5 files changed, 64 insertions, 22 deletions
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua
index ad5764b31..25caf599c 100644
--- a/xmake/modules/private/service/remote_build/client.lua
+++ b/xmake/modules/private/service/remote_build/client.lua
@@ -15,7 +15,7 @@
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
--- @file remote_build_client.lua
+-- @file client.lua
--
-- imports
@@ -24,7 +24,7 @@ import("core.project.config", {alias = "project_config"})
import("private.service.config")
import("private.service.message")
import("private.service.client")
-import("private.service.socket_stream")
+import("private.service.stream", {alias = "socket_stream"})
-- define module
local remote_build_client = remote_build_client or client()
diff --git a/xmake/modules/private/service/remote_build/server.lua b/xmake/modules/private/service/remote_build/server.lua
index 37fb9b5f5..dc7cb67d3 100644
--- a/xmake/modules/private/service/remote_build/server.lua
+++ b/xmake/modules/private/service/remote_build/server.lua
@@ -15,14 +15,15 @@
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
--- @file remote_build_server.lua
+-- @file server.lua
--
-- imports
import("private.service.config")
-import("private.service.socket_stream")
import("private.service.message")
import("private.service.server")
+import("private.service.stream", {alias = "socket_stream"})
+import("private.service.remote_build.session", {alias = "server_session"})
-- define module
local remote_build_server = remote_build_server or server()
@@ -92,7 +93,7 @@ end
-- open session
function remote_build_server:_session_open(session_id)
- self._SESSIONS[session_id] = {}
+ self._SESSIONS[session_id] = server_session(session_id)
end
-- close session
diff --git a/xmake/modules/private/service/remote_build/session.lua b/xmake/modules/private/service/remote_build/session.lua
new file mode 100644
index 000000000..df7e1f837
--- /dev/null
+++ b/xmake/modules/private/service/remote_build/session.lua
@@ -0,0 +1,41 @@
+--!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 session.lua
+--
+
+-- imports
+import("core.base.object")
+
+-- define module
+local session = session or object()
+
+-- init session
+function session:init(session_id)
+ self._ID = session_id
+end
+
+-- get session id
+function session:id()
+ return self._ID
+end
+
+function main(session_id)
+ local instance = session()
+ instance:init(session_id)
+ return instance
+end
diff --git a/xmake/modules/private/service/server.lua b/xmake/modules/private/service/server.lua
index 2acc230f6..4a80cd98a 100644
--- a/xmake/modules/private/service/server.lua
+++ b/xmake/modules/private/service/server.lua
@@ -23,8 +23,8 @@ import("core.base.object")
import("core.base.bytes")
import("core.base.socket")
import("core.base.scheduler")
-import("private.service.socket_stream")
import("private.service.message")
+import("private.service.stream", {alias = "socket_stream"})
-- define module
local server = server or object()
diff --git a/xmake/modules/private/service/socket_stream.lua b/xmake/modules/private/service/stream.lua
index 1b428a936..c2709189a 100644
--- a/xmake/modules/private/service/socket_stream.lua
+++ b/xmake/modules/private/service/stream.lua
@@ -15,7 +15,7 @@
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
--- @file socket_stream.lua
+-- @file stream.lua
--
-- imports
@@ -25,10 +25,10 @@ import("core.base.bytes")
import("private.service.message")
-- define module
-local socket_stream = socket_stream or object()
+local stream = stream or object()
--- init socket_stream
-function socket_stream:init(sock)
+-- init stream
+function stream:init(sock)
self._SOCK = sock
self._BUFF = bytes(65536)
self._RCACHE = bytes(8192)
@@ -38,12 +38,12 @@ function socket_stream:init(sock)
end
-- get socket
-function socket_stream:sock()
+function stream:sock()
return self._SOCK
end
-- flush data
-function socket_stream:flush()
+function stream:flush()
local cache = self._WCACHE
local cache_size = self._WCACHE_SIZE
if cache_size > 0 then
@@ -59,7 +59,7 @@ function socket_stream:flush()
end
-- send the given bytes
-function socket_stream:send(data, start, last)
+function stream:send(data, start, last)
start = start or 1
last = last or data:size()
local size = last + 1 - start
@@ -96,12 +96,12 @@ function socket_stream:send(data, start, last)
end
-- send message
-function socket_stream:send_msg(msg)
+function stream:send_msg(msg)
return self:send_object(msg:body())
end
-- send object
-function socket_stream:send_object(obj)
+function stream:send_object(obj)
local str, errors = string.serialize(obj, {strip = true, indent = false})
if errors then
raise(errors)
@@ -112,7 +112,7 @@ function socket_stream:send_object(obj)
end
-- send string
-function socket_stream:send_string(str)
+function stream:send_string(str)
local buff = self._BUFF
local size = #str
buff:u16be_set(1, size)
@@ -122,7 +122,7 @@ function socket_stream:send_string(str)
end
-- recv the given bytes
-function socket_stream:recv(buff, size)
+function stream:recv(buff, size)
assert(size <= buff:size())
-- read data from cache first
@@ -181,7 +181,7 @@ function socket_stream:recv(buff, size)
end
-- recv u16be
-function socket_stream:recv_u16be()
+function stream:recv_u16be()
local data = self:recv(self._BUFF, 2)
if data then
return data:u16be(1)
@@ -189,7 +189,7 @@ function socket_stream:recv_u16be()
end
-- recv message
-function socket_stream:recv_msg()
+function stream:recv_msg()
local body = self:recv_object()
if body then
return message(body)
@@ -197,7 +197,7 @@ function socket_stream:recv_msg()
end
-- recv object
-function socket_stream:recv_object()
+function stream:recv_object()
local str = self:recv_string()
if str then
local obj, errors = str:deserialize()
@@ -209,7 +209,7 @@ function socket_stream:recv_object()
end
-- recv string
-function socket_stream:recv_string()
+function stream:recv_string()
local size = self:recv_u16be()
if size then
local data = self:recv(self._BUFF, size)
@@ -220,7 +220,7 @@ function socket_stream:recv_string()
end
function main(sock)
- local instance = socket_stream()
+ local instance = stream()
instance:init(sock)
return instance
end