From 027270fd2c8b54b46963679215d637f7c5a9b2db Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 19 Apr 2017 11:20:08 +0200 Subject: [PATCH] cleanup --- app/proxyman/mux/writer.go | 11 ++++++++--- transport/ray/direct.go | 10 +++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/proxyman/mux/writer.go b/app/proxyman/mux/writer.go index c4541735e..ca3cea654 100644 --- a/app/proxyman/mux/writer.go +++ b/app/proxyman/mux/writer.go @@ -42,7 +42,9 @@ func (w *Writer) writeInternal(mb buf.MultiBuffer) error { meta.SessionStatus = SessionStatusNew } - if mb.Len() > 0 { + hasData := !mb.IsEmpty() + + if hasData { meta.Option.Add(OptionData) } @@ -52,7 +54,7 @@ func (w *Writer) writeInternal(mb buf.MultiBuffer) error { mb2 := buf.NewMultiBuffer() mb2.Append(frame) - if mb.Len() > 0 { + if hasData { frame.AppendSupplier(serial.WriteUint16(uint16(mb.Len()))) mb2.AppendMulti(mb) } @@ -61,11 +63,14 @@ func (w *Writer) writeInternal(mb buf.MultiBuffer) error { func (w *Writer) Write(mb buf.MultiBuffer) error { const chunkSize = 8 * 1024 - for !mb.IsEmpty() { + for { slice := mb.SliceBySize(chunkSize) if err := w.writeInternal(slice); err != nil { return err } + if mb.IsEmpty() { + break + } } return nil } diff --git a/transport/ray/direct.go b/transport/ray/direct.go index c2a472fa8..7732397ad 100644 --- a/transport/ray/direct.go +++ b/transport/ray/direct.go @@ -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() { - return + return nil } s.access.Lock() defer s.access.Unlock() - if s.err { - data.Release() - return io.ErrClosedPipe - } - if s.close { + if s.err || s.close { data.Release() return io.ErrClosedPipe }