mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
cleanup
This commit is contained in:
parent
ffa0787b09
commit
027270fd2c
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user