mirror of https://github.com/cbeuw/Cloak
Fix Cloak client. Don't enforce read deadline after first read.
This commit is contained in:
parent
3d103e728c
commit
2a18da037f
|
|
@ -22,11 +22,13 @@ type datagramBufferedPipe struct {
|
||||||
rDeadline time.Time
|
rDeadline time.Time
|
||||||
|
|
||||||
timeoutTimer *time.Timer
|
timeoutTimer *time.Timer
|
||||||
|
enforceReadDeadline bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDatagramBufferedPipe() *datagramBufferedPipe {
|
func NewDatagramBufferedPipe() *datagramBufferedPipe {
|
||||||
d := &datagramBufferedPipe{
|
d := &datagramBufferedPipe{
|
||||||
rwCond: sync.NewCond(&sync.Mutex{}),
|
rwCond: sync.NewCond(&sync.Mutex{}),
|
||||||
|
enforceReadDeadline: true,
|
||||||
}
|
}
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +44,7 @@ func (d *datagramBufferedPipe) Read(target []byte) (int, error) {
|
||||||
return 0, io.EOF
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
hasRDeadline := !d.rDeadline.IsZero()
|
hasRDeadline := !d.rDeadline.IsZero() && d.enforceReadDeadline
|
||||||
if hasRDeadline {
|
if hasRDeadline {
|
||||||
if time.Until(d.rDeadline) <= 0 {
|
if time.Until(d.rDeadline) <= 0 {
|
||||||
return 0, ErrTimeout
|
return 0, ErrTimeout
|
||||||
|
|
@ -65,6 +67,7 @@ func (d *datagramBufferedPipe) Read(target []byte) (int, error) {
|
||||||
d.pLens = d.pLens[1:]
|
d.pLens = d.pLens[1:]
|
||||||
d.buf.Read(target[:dataLen])
|
d.buf.Read(target[:dataLen])
|
||||||
// err will always be nil because we have already verified that buf.Len() != 0
|
// err will always be nil because we have already verified that buf.Len() != 0
|
||||||
|
d.enforceReadDeadline = false
|
||||||
d.rwCond.Broadcast()
|
d.rwCond.Broadcast()
|
||||||
return dataLen, nil
|
return dataLen, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,13 @@ type streamBufferedPipe struct {
|
||||||
wtTimeout time.Duration
|
wtTimeout time.Duration
|
||||||
|
|
||||||
timeoutTimer *time.Timer
|
timeoutTimer *time.Timer
|
||||||
|
enforceReadDeadline bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStreamBufferedPipe() *streamBufferedPipe {
|
func NewStreamBufferedPipe() *streamBufferedPipe {
|
||||||
p := &streamBufferedPipe{
|
p := &streamBufferedPipe{
|
||||||
rwCond: sync.NewCond(&sync.Mutex{}),
|
rwCond: sync.NewCond(&sync.Mutex{}),
|
||||||
|
enforceReadDeadline: true,
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +42,7 @@ func (p *streamBufferedPipe) Read(target []byte) (int, error) {
|
||||||
return 0, io.EOF
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
hasRDeadline := !p.rDeadline.IsZero()
|
hasRDeadline := !p.rDeadline.IsZero() && p.enforceReadDeadline
|
||||||
if hasRDeadline {
|
if hasRDeadline {
|
||||||
if time.Until(p.rDeadline) <= 0 {
|
if time.Until(p.rDeadline) <= 0 {
|
||||||
return 0, ErrTimeout
|
return 0, ErrTimeout
|
||||||
|
|
@ -57,6 +59,7 @@ func (p *streamBufferedPipe) Read(target []byte) (int, error) {
|
||||||
}
|
}
|
||||||
n, err := p.buf.Read(target)
|
n, err := p.buf.Read(target)
|
||||||
// err will always be nil because we have already verified that buf.Len() != 0
|
// err will always be nil because we have already verified that buf.Len() != 0
|
||||||
|
p.enforceReadDeadline = false
|
||||||
p.rwCond.Broadcast()
|
p.rwCond.Broadcast()
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue