diff options
| author | ruki <[email protected]> | 2022-04-15 00:51:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-15 00:51:39 +0800 |
| commit | 1d4af74c21ebcfd26cf9b82379d930990c56ded3 (patch) | |
| tree | 98f20ca3330dee664ad1ae86632863ec8f11f4f0 | |
| parent | 2c3bdeef93e51d426f0a85bbbe06a16c9486ea47 (diff) | |
read stdin for client
| -rw-r--r-- | xmake/modules/private/service/remote_build/client.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index d1121a028..af98758a2 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -21,6 +21,7 @@ -- imports import("core.base.bytes") import("core.base.socket") +import("core.base.scheduler") import("core.project.config", {alias = "project_config"}) import("devel.git") import("lib.detect.find_tool") @@ -230,6 +231,8 @@ function remote_build_client:runcmd(program, argv) if sock then local stream = socket_stream(sock) if stream:send_msg(message.new_runcmd(session_id, program, argv)) and stream:flush() then + local stdin_opt = {stop = false} + scheduler.co_start(self._read_stdin, self, stream, stdin_opt) while true do local msg = stream:recv_msg() if msg then @@ -258,6 +261,7 @@ function remote_build_client:runcmd(program, argv) break end end + stdin_opt.stop = true end end if #leftstr > 0 then @@ -333,6 +337,30 @@ function remote_build_client:_do_syncfiles(remote_path, remote_branch) git.push(remote_url, {remote_branch = remote_branch, verbose = true}) end +-- read stdin data +function remote_build_client:_read_stdin(stream, opt) + while not opt.stop do + if io.read(0) then + local line = io.read("L") -- with crlf + if line and #line > 0 then + local ok = false + local data = bytes(line) + if stream:send_msg(message.new_data(0, data:size())) then + if stream:send(data) and stream:flush() then + ok = true + end + end + if not ok then + break + end + end + else + os.sleep(500) + end + end +end + + function remote_build_client:__tostring() return "<remote_build_client>" end |
