mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
comments
This commit is contained in:
parent
c347e50c28
commit
22fa151391
@ -25,6 +25,7 @@ func NewWriter(rawWriter io.Writer) *BufferedWriter {
|
||||
}
|
||||
}
|
||||
|
||||
// ReadFrom implements io.ReaderFrom.ReadFrom().
|
||||
func (v *BufferedWriter) ReadFrom(reader io.Reader) (int64, error) {
|
||||
totalBytes := int64(0)
|
||||
for {
|
||||
@ -65,6 +66,7 @@ func (v *BufferedWriter) Write(b []byte) (int, error) {
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
// Flush writes all buffered content into underlying writer, if any.
|
||||
func (v *BufferedWriter) Flush() error {
|
||||
defer v.buffer.Clear()
|
||||
for !v.buffer.IsEmpty() {
|
||||
@ -77,10 +79,12 @@ func (v *BufferedWriter) Flush() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *BufferedWriter) Buffered() bool {
|
||||
// IsBuffered returns true if this BufferedWriter holds a buffer.
|
||||
func (v *BufferedWriter) IsBuffered() bool {
|
||||
return v.buffered
|
||||
}
|
||||
|
||||
// SetBuffered controls whether the BufferedWriter holds a buffer for writing. If not buffered, any write() calls into underlying writer directly.
|
||||
func (v *BufferedWriter) SetBuffered(cached bool) {
|
||||
v.buffered = cached
|
||||
if !cached && !v.buffer.IsEmpty() {
|
||||
|
@ -15,7 +15,7 @@ func TestBufferedWriter(t *testing.T) {
|
||||
content := buf.New()
|
||||
|
||||
writer := NewWriter(content)
|
||||
assert.Bool(writer.Buffered()).IsTrue()
|
||||
assert.Bool(writer.IsBuffered()).IsTrue()
|
||||
|
||||
payload := make([]byte, 16)
|
||||
|
||||
@ -35,7 +35,7 @@ func TestBufferedWriterLargePayload(t *testing.T) {
|
||||
content := buf.NewLocal(128 * 1024)
|
||||
|
||||
writer := NewWriter(content)
|
||||
assert.Bool(writer.Buffered()).IsTrue()
|
||||
assert.Bool(writer.IsBuffered()).IsTrue()
|
||||
|
||||
payload := make([]byte, 64*1024)
|
||||
rand.Read(payload)
|
||||
|
Loading…
Reference in New Issue
Block a user