diff options
| -rw-r--r-- | xmake/modules/private/service/connect_service.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/private/service/server/remote_build_server.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/private/service/server/server.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/private/service/socket_stream.lua (renamed from xmake/modules/private/service/stream.lua) | 30 |
4 files changed, 25 insertions, 25 deletions
diff --git a/xmake/modules/private/service/connect_service.lua b/xmake/modules/private/service/connect_service.lua index eabcdfc32..9509b3aab 100644 --- a/xmake/modules/private/service/connect_service.lua +++ b/xmake/modules/private/service/connect_service.lua @@ -23,7 +23,7 @@ import("core.base.option") import("core.base.socket") import("core.base.scheduler") import("private.service.config") -import("private.service.stream") +import("private.service.socket_stream") import("private.service.message") import("private.service.client.remote_build_client") @@ -49,9 +49,9 @@ function _connect(addr, port) print("%s: connect %s:%d ..", client, addr, port) if sock then print("%s: connected!", client) - local sock_stream = stream(sock) - if sock_stream:send_msg(message.new_ping()) and sock_stream:flush() then - local msg = sock_stream:recv_msg() + local stream = socket_stream(sock) + if stream:send_msg(message.new_ping()) and stream:flush() then + local msg = stream:recv_msg() if msg then msg:dump() end diff --git a/xmake/modules/private/service/server/remote_build_server.lua b/xmake/modules/private/service/server/remote_build_server.lua index 57f697f59..a323132a6 100644 --- a/xmake/modules/private/service/server/remote_build_server.lua +++ b/xmake/modules/private/service/server/remote_build_server.lua @@ -20,7 +20,7 @@ -- imports import("private.service.config") -import("private.service.stream") +import("private.service.socket_stream") import("private.service.message") import("private.service.server.server") @@ -41,8 +41,8 @@ end -- handle ping message function remote_build_server:handle_ping(sock, msg) - local wstream = stream(sock) - if wstream:send_msg(message.new_ping()) and wstream:flush() then + local stream = socket_stream(sock) + if stream:send_msg(message.new_ping()) and stream:flush() then print("send ok") end end diff --git a/xmake/modules/private/service/server/server.lua b/xmake/modules/private/service/server/server.lua index d3035eddf..ea1831934 100644 --- a/xmake/modules/private/service/server/server.lua +++ b/xmake/modules/private/service/server/server.lua @@ -23,7 +23,7 @@ import("core.base.object") import("core.base.bytes") import("core.base.socket") import("core.base.scheduler") -import("private.service.stream") +import("private.service.socket_stream") import("private.service.message") -- define module @@ -121,9 +121,9 @@ end -- handle session function server:_handle_session(sock) print("%s: %s session connected", self, sock) - local rstream = stream(sock) + local stream = socket_stream(sock) while true do - local msg = rstream:recv_object() + local msg = stream:recv_object() if msg then self:_HANDLER(sock, message(msg)) else diff --git a/xmake/modules/private/service/stream.lua b/xmake/modules/private/service/socket_stream.lua index d7000090e..74f71c330 100644 --- a/xmake/modules/private/service/stream.lua +++ b/xmake/modules/private/service/socket_stream.lua @@ -15,7 +15,7 @@ -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki --- @file stream.lua +-- @file socket_stream.lua -- -- imports @@ -25,10 +25,10 @@ import("core.base.bytes") import("private.service.message") -- define module -local stream = stream or object() +local socket_stream = socket_stream or object() --- init stream -function stream:init(sock) +-- init socket_stream +function socket_stream:init(sock) self._SOCK = sock self._BUFF = bytes(65536) self._RCACHE = bytes(8192) @@ -38,7 +38,7 @@ function stream:init(sock) end -- flush data -function stream:flush() +function socket_stream:flush() local cache = self._WCACHE local cache_size = self._WCACHE_SIZE if cache_size > 0 then @@ -54,7 +54,7 @@ function stream:flush() end -- send the given bytes -function stream:send(data, start, last) +function socket_stream:send(data, start, last) start = start or 1 last = last or data:size() local size = last + 1 - start @@ -91,12 +91,12 @@ function stream:send(data, start, last) end -- send message -function stream:send_msg(msg) +function socket_stream:send_msg(msg) return self:send_object(msg:body()) end -- send object -function stream:send_object(obj) +function socket_stream:send_object(obj) local str, errors = string.serialize(obj, {strip = true, indent = false}) if errors then raise(errors) @@ -107,7 +107,7 @@ function stream:send_object(obj) end -- send string -function stream:send_string(str) +function socket_stream:send_string(str) local buff = self._BUFF local size = #str buff:u16be_set(1, size) @@ -117,7 +117,7 @@ function stream:send_string(str) end -- recv the given bytes -function stream:recv(buff, size) +function socket_stream:recv(buff, size) assert(size <= buff:size()) -- read data from cache first @@ -176,7 +176,7 @@ function stream:recv(buff, size) end -- recv u16be -function stream:recv_u16be() +function socket_stream:recv_u16be() local data = self:recv(self._BUFF, 2) if data then return data:u16be(1) @@ -184,7 +184,7 @@ function stream:recv_u16be() end -- recv message -function stream:recv_msg() +function socket_stream:recv_msg() local body = self:recv_object() if body then return message(body) @@ -192,7 +192,7 @@ function stream:recv_msg() end -- recv object -function stream:recv_object() +function socket_stream:recv_object() local str = self:recv_string() if str then local obj, errors = str:deserialize() @@ -204,7 +204,7 @@ function stream:recv_object() end -- recv string -function stream:recv_string() +function socket_stream:recv_string() local size = self:recv_u16be() if size then local data = self:recv(self._BUFF, size) @@ -215,7 +215,7 @@ function stream:recv_string() end function main(sock) - local instance = stream() + local instance = socket_stream() instance:init(sock) return instance end |
