diff options
| author | ruki <[email protected]> | 2022-04-14 22:45:49 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-14 22:45:49 +0800 |
| commit | 851f956800571516c66b2ce0e7ef143aa9f876d8 (patch) | |
| tree | 2706bbdc803309f369b9a75a2a43081c9fe89bf0 | |
| parent | da479356aed60608d8134d86caffb15566c929d8 (diff) | |
read stdout from pipe
| -rw-r--r-- | xmake/modules/private/service/remote_build/server.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/session.lua | 42 |
2 files changed, 42 insertions, 1 deletions
diff --git a/xmake/modules/private/service/remote_build/server.lua b/xmake/modules/private/service/remote_build/server.lua index 3a4de8785..1cba2f79e 100644 --- a/xmake/modules/private/service/remote_build/server.lua +++ b/xmake/modules/private/service/remote_build/server.lua @@ -73,6 +73,7 @@ function remote_build_server:_on_handle(stream, msg) local session = self:_session(session_id) vprint("%s: %s: <session %s>: on handle message(%d)", self, stream:sock(), session_id, msg:code()) vprint(msg:body()) + session:stream_set(stream) local respmsg = msg:clone() local session_errs local session_ok = try diff --git a/xmake/modules/private/service/remote_build/session.lua b/xmake/modules/private/service/remote_build/session.lua index 108a26895..0992c6041 100644 --- a/xmake/modules/private/service/remote_build/session.lua +++ b/xmake/modules/private/service/remote_build/session.lua @@ -19,8 +19,12 @@ -- -- imports +import("core.base.pipe") +import("core.base.bytes") import("core.base.object") import("core.base.global") +import("core.base.option") +import("core.base.scheduler") import("devel.git") import("private.service.config") @@ -47,6 +51,16 @@ function session:close() self:_reset_sourcedir() end +-- set stream +function session:stream_set(stream) + self._STREAM = stream +end + +-- get stream +function session:stream() + return self._STREAM +end + -- sync files function session:sync(respmsg) local body = respmsg:body() @@ -76,7 +90,12 @@ function session:runcmd(respmsg) local program = body.program local argv = body.argv vprint("%s: run command(%s) ..", self, os.args(table.join(program, argv))) - os.execv(program, argv, {curdir = self:sourcedir()}) + local rpipe, wpipe = pipe.openpair(10) + local rpipeopt = {rpipe = rpipe, stop = false} + scheduler.co_start(self._read_pipe, self, rpipeopt) + os.execv(program, argv, {curdir = self:sourcedir(), stdout = wpipe}) + rpipeopt.stop = true + wpipe:close() vprint("%s: run command ok", self) end @@ -115,6 +134,27 @@ function session:_reset_sourcedir() end end +-- read process stdout from pipe +function session:_read_pipe(opt) + local buff = bytes(256) + local rpipe = opt.rpipe + vprint("%s: %s: reading data ..", self, rpipe) + while not opt.stop do + local real, data = rpipe:read(buff) + if real > 0 then + utils.vprintf(data:str()) + elseif real == 0 then + if rpipe:wait(pipe.EV_READ, -1) < 0 then + break + end + else + break + end + end + rpipe:close() + vprint("%s: %s read data end", self, rpipe) +end + -- get working branch of the source directory function session:_source_branch() return "remote_build" |
