mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
remove lock on bytes reader and writer
This commit is contained in:
parent
f195f15536
commit
ea33b7691b
@ -1,9 +1,6 @@
|
||||
package buf
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync"
|
||||
)
|
||||
import "io"
|
||||
|
||||
// BytesToBufferReader is a Reader that adjusts its reading speed automatically.
|
||||
type BytesToBufferReader struct {
|
||||
@ -52,7 +49,6 @@ func (v *BytesToBufferReader) Release() {
|
||||
}
|
||||
|
||||
type BufferToBytesReader struct {
|
||||
sync.Mutex
|
||||
stream Reader
|
||||
current *Buffer
|
||||
eof bool
|
||||
@ -74,8 +70,6 @@ func (v *BufferToBytesReader) Read(b []byte) (int, error) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
if v.current == nil {
|
||||
v.Fill()
|
||||
if v.eof {
|
||||
@ -92,11 +86,7 @@ func (v *BufferToBytesReader) Read(b []byte) (int, error) {
|
||||
|
||||
// Release implements Releasable.Release().
|
||||
func (v *BufferToBytesReader) Release() {
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
|
||||
v.eof = true
|
||||
v.current.Release()
|
||||
v.current = nil
|
||||
v.stream = nil
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package buf
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync"
|
||||
)
|
||||
import "io"
|
||||
|
||||
// BufferToBytesWriter is a Writer that writes alloc.Buffer into underlying writer.
|
||||
type BufferToBytesWriter struct {
|
||||
@ -32,17 +29,10 @@ func (v *BufferToBytesWriter) Release() {
|
||||
}
|
||||
|
||||
type BytesToBufferWriter struct {
|
||||
sync.Mutex
|
||||
writer Writer
|
||||
}
|
||||
|
||||
func (v *BytesToBufferWriter) Write(payload []byte) (int, error) {
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
if v.writer == nil {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
|
||||
bytesWritten := 0
|
||||
size := len(payload)
|
||||
for size > 0 {
|
||||
@ -62,8 +52,5 @@ func (v *BytesToBufferWriter) Write(payload []byte) (int, error) {
|
||||
|
||||
// Release implements Releasable.Release()
|
||||
func (v *BytesToBufferWriter) Release() {
|
||||
v.Lock()
|
||||
v.writer.Release()
|
||||
v.writer = nil
|
||||
v.Unlock()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user