|
@@ -8,6 +8,7 @@ import (
|
|
|
|
|
|
|
|
"v2ray.com/core/common/buf"
|
|
"v2ray.com/core/common/buf"
|
|
|
"v2ray.com/core/common/signal"
|
|
"v2ray.com/core/common/signal"
|
|
|
|
|
+ "v2ray.com/core/common/signal/done"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type state byte
|
|
type state byte
|
|
@@ -23,6 +24,7 @@ type pipe struct {
|
|
|
data buf.MultiBuffer
|
|
data buf.MultiBuffer
|
|
|
readSignal *signal.Notifier
|
|
readSignal *signal.Notifier
|
|
|
writeSignal *signal.Notifier
|
|
writeSignal *signal.Notifier
|
|
|
|
|
+ done *done.Instance
|
|
|
limit int32
|
|
limit int32
|
|
|
state state
|
|
state state
|
|
|
}
|
|
}
|
|
@@ -72,7 +74,10 @@ func (p *pipe) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|
|
return data, err
|
|
return data, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- <-p.readSignal.Wait()
|
|
|
|
|
|
|
+ select {
|
|
|
|
|
+ case <-p.readSignal.Wait():
|
|
|
|
|
+ case <-p.done.Wait():
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -87,6 +92,7 @@ func (p *pipe) ReadMultiBufferWithTimeout(d time.Duration) (buf.MultiBuffer, err
|
|
|
|
|
|
|
|
select {
|
|
select {
|
|
|
case <-p.readSignal.Wait():
|
|
case <-p.readSignal.Wait():
|
|
|
|
|
+ case <-p.done.Wait():
|
|
|
case <-timer:
|
|
case <-timer:
|
|
|
return nil, buf.ErrReadTimeout
|
|
return nil, buf.ErrReadTimeout
|
|
|
}
|
|
}
|
|
@@ -117,7 +123,11 @@ func (p *pipe) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- <-p.writeSignal.Wait()
|
|
|
|
|
|
|
+ select {
|
|
|
|
|
+ case <-p.writeSignal.Wait():
|
|
|
|
|
+ case <-p.done.Wait():
|
|
|
|
|
+ return io.ErrClosedPipe
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -130,8 +140,7 @@ func (p *pipe) Close() error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
p.state = closed
|
|
p.state = closed
|
|
|
- p.readSignal.Signal()
|
|
|
|
|
- p.writeSignal.Signal()
|
|
|
|
|
|
|
+ p.done.Close()
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -150,6 +159,5 @@ func (p *pipe) CloseError() {
|
|
|
p.data = nil
|
|
p.data = nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- p.readSignal.Signal()
|
|
|
|
|
- p.writeSignal.Signal()
|
|
|
|
|
|
|
+ p.done.Close()
|
|
|
}
|
|
}
|