1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
This commit is contained in:
Darien Raymond 2017-04-19 11:20:08 +02:00
parent ffa0787b09
commit 027270fd2c
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 11 additions and 10 deletions

View File

@ -42,7 +42,9 @@ func (w *Writer) writeInternal(mb buf.MultiBuffer) error {
meta.SessionStatus = SessionStatusNew meta.SessionStatus = SessionStatusNew
} }
if mb.Len() > 0 { hasData := !mb.IsEmpty()
if hasData {
meta.Option.Add(OptionData) meta.Option.Add(OptionData)
} }
@ -52,7 +54,7 @@ func (w *Writer) writeInternal(mb buf.MultiBuffer) error {
mb2 := buf.NewMultiBuffer() mb2 := buf.NewMultiBuffer()
mb2.Append(frame) mb2.Append(frame)
if mb.Len() > 0 { if hasData {
frame.AppendSupplier(serial.WriteUint16(uint16(mb.Len()))) frame.AppendSupplier(serial.WriteUint16(uint16(mb.Len())))
mb2.AppendMulti(mb) mb2.AppendMulti(mb)
} }
@ -61,11 +63,14 @@ func (w *Writer) writeInternal(mb buf.MultiBuffer) error {
func (w *Writer) Write(mb buf.MultiBuffer) error { func (w *Writer) Write(mb buf.MultiBuffer) error {
const chunkSize = 8 * 1024 const chunkSize = 8 * 1024
for !mb.IsEmpty() { for {
slice := mb.SliceBySize(chunkSize) slice := mb.SliceBySize(chunkSize)
if err := w.writeInternal(slice); err != nil { if err := w.writeInternal(slice); err != nil {
return err return err
} }
if mb.IsEmpty() {
break
}
} }
return nil return nil
} }

View File

@ -115,19 +115,15 @@ func (s *Stream) ReadTimeout(timeout time.Duration) (buf.MultiBuffer, error) {
} }
} }
func (s *Stream) Write(data buf.MultiBuffer) (err error) { func (s *Stream) Write(data buf.MultiBuffer) error {
if data.IsEmpty() { if data.IsEmpty() {
return return nil
} }
s.access.Lock() s.access.Lock()
defer s.access.Unlock() defer s.access.Unlock()
if s.err { if s.err || s.close {
data.Release()
return io.ErrClosedPipe
}
if s.close {
data.Release() data.Release()
return io.ErrClosedPipe return io.ErrClosedPipe
} }