mirror of
https://github.com/criyle/go-sandbox.git
synced 2025-11-04 14:49:53 +08:00
container: host async wait
This commit is contained in:
parent
91dae1dfc6
commit
3b55a156bc
@ -82,6 +82,8 @@ type container struct {
|
||||
|
||||
recvCh chan recvReply
|
||||
sendCh chan sendCmd
|
||||
|
||||
execveWaitCh chan execveWait
|
||||
}
|
||||
|
||||
type recvReply struct {
|
||||
@ -222,9 +224,12 @@ func (b *Builder) startContainer() (*container, error) {
|
||||
recvCh: make(chan recvReply, 1),
|
||||
sendCh: make(chan sendCmd, 1),
|
||||
done: make(chan struct{}),
|
||||
|
||||
execveWaitCh: make(chan execveWait, 1),
|
||||
}
|
||||
go c.sendLoop()
|
||||
go c.recvLoop()
|
||||
go c.execveWaitLoop()
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@ -118,8 +118,29 @@ func (c *container) execveWait(ctx context.Context, sTime time.Time, result chan
|
||||
mTime := time.Now()
|
||||
|
||||
// wait for result / cancel
|
||||
go func() {
|
||||
defer c.mu.Unlock()
|
||||
c.execveWaitCh <- execveWait{
|
||||
ctx: ctx,
|
||||
sTime: sTime,
|
||||
mTime: mTime,
|
||||
result: result,
|
||||
}
|
||||
}
|
||||
|
||||
type execveWait struct {
|
||||
ctx context.Context
|
||||
sTime time.Time
|
||||
mTime time.Time
|
||||
result chan runner.Result
|
||||
}
|
||||
|
||||
func (c *container) execveWaitLoop() {
|
||||
for {
|
||||
waitParam := <-c.execveWaitCh
|
||||
ctx := waitParam.ctx
|
||||
sTime := waitParam.sTime
|
||||
mTime := waitParam.mTime
|
||||
result := waitParam.result
|
||||
|
||||
select {
|
||||
case <-c.done: // socket error
|
||||
result <- convertReplyResult(reply{}, sTime, mTime, c.err)
|
||||
@ -135,7 +156,8 @@ func (c *container) execveWait(ctx context.Context, sTime time.Time, result chan
|
||||
_, _, err := c.recvReply()
|
||||
result <- convertReplyResult(ret.Reply, sTime, mTime, err)
|
||||
}
|
||||
}()
|
||||
c.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func convertReplyResult(reply reply, sTime, mTime time.Time, err error) runner.Result {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user