mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-18 07:17:32 -05:00
skip empty payload in ray
This commit is contained in:
parent
38e4cad8d1
commit
f7379bc1c3
@ -70,6 +70,10 @@ func (v *Stream) Read() (*buf.Buffer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *Stream) Write(data *buf.Buffer) (err error) {
|
func (v *Stream) Write(data *buf.Buffer) (err error) {
|
||||||
|
if data.IsEmpty() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-v.destClose:
|
case <-v.destClose:
|
||||||
return io.ErrClosedPipe
|
return io.ErrClosedPipe
|
||||||
|
@ -13,7 +13,9 @@ func TestStreamIO(t *testing.T) {
|
|||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
stream := NewStream()
|
stream := NewStream()
|
||||||
assert.Error(stream.Write(buf.New())).IsNil()
|
b1 := buf.New()
|
||||||
|
b1.AppendBytes('a')
|
||||||
|
assert.Error(stream.Write(b1)).IsNil()
|
||||||
|
|
||||||
_, err := stream.Read()
|
_, err := stream.Read()
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
@ -22,7 +24,9 @@ func TestStreamIO(t *testing.T) {
|
|||||||
_, err = stream.Read()
|
_, err = stream.Read()
|
||||||
assert.Error(err).Equals(io.EOF)
|
assert.Error(err).Equals(io.EOF)
|
||||||
|
|
||||||
err = stream.Write(buf.New())
|
b2 := buf.New()
|
||||||
|
b2.AppendBytes('b')
|
||||||
|
err = stream.Write(b2)
|
||||||
assert.Error(err).Equals(io.ErrClosedPipe)
|
assert.Error(err).Equals(io.ErrClosedPipe)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +34,9 @@ func TestStreamClose(t *testing.T) {
|
|||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
stream := NewStream()
|
stream := NewStream()
|
||||||
assert.Error(stream.Write(buf.New())).IsNil()
|
b1 := buf.New()
|
||||||
|
b1.AppendBytes('a')
|
||||||
|
assert.Error(stream.Write(b1)).IsNil()
|
||||||
|
|
||||||
stream.Close()
|
stream.Close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user