summaryrefslogtreecommitdiff
path: root/xmake/core/base/pipe.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-02 21:44:58 +0800
committerruki <[email protected]>2020-02-02 21:44:58 +0800
commit77f79dd72801215d403b1a5a7b7a130c68bd4e2b (patch)
treef963b507be594df6e885e34875bfd974f6b3a6cf /xmake/core/base/pipe.lua
parent6da5429082cede5f1ad656e7619c79bd7d16406e (diff)
improve to read/write pipe
Diffstat (limited to 'xmake/core/base/pipe.lua')
-rw-r--r--xmake/core/base/pipe.lua16
1 files changed, 4 insertions, 12 deletions
diff --git a/xmake/core/base/pipe.lua b/xmake/core/base/pipe.lua
index 5f3418965..be798a606 100644
--- a/xmake/core/base/pipe.lua
+++ b/xmake/core/base/pipe.lua
@@ -87,7 +87,6 @@ function _instance:write(data, opt)
-- write it
local write = 0
local real = 0
- local wait = false
local errors = nil
if opt.block then
local size = last + 1 - start
@@ -96,12 +95,9 @@ function _instance:write(data, opt)
if real > 0 then
write = write + real
start = start + real
- wait = false
- elseif real == 0 and not wait then
+ elseif real == 0 then
local events, waiterrs = self:wait(pipe.EV_WRITE, opt.timeout or -1)
- if events == pipe.EV_WRITE then
- wait = true
- else
+ if events ~= pipe.EV_WRITE then
errors = waiterrs
break
end
@@ -141,7 +137,6 @@ function _instance:read(size, opt)
opt = opt or {}
local read = 0
local real = 0
- local wait = false
local data_or_errors = nil
if opt.block then
local results = {}
@@ -150,14 +145,11 @@ function _instance:read(size, opt)
real, data_or_errors = io.pipe_read(self:cdata(), buff:caddr(), math.min(buff:size(), size - read))
if real > 0 then
read = read + real
- wait = false
table.insert(results, bytes(buff, 1, real))
self:_readbuff_clear()
- elseif real == 0 and not wait then
+ elseif real == 0 then
local events, waiterrs = self:wait(pipe.EV_READ, opt.timeout or -1)
- if events == pipe.EV_READ then
- wait = true
- else
+ if events ~= pipe.EV_READ then
data_or_errors = waiterrs
break
end