-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2014 Manu Martinez-Almeida. All rights reserved. | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
package gin | ||
|
||
import ( | ||
"io" | ||
"net" | ||
) | ||
|
||
type bufWriter interface { | ||
io.Writer | ||
Flush() error | ||
} | ||
|
||
// rwConn implements net.Conn but overrides Read and Write so that reads and | ||
// writes are forwarded to the provided io.Reader and bufWriter. | ||
type rwConn struct { | ||
net.Conn | ||
io.Reader | ||
BufWriter bufWriter | ||
} | ||
|
||
// Read forwards reads to the underlying Reader. | ||
func (c *rwConn) Read(p []byte) (int, error) { | ||
return c.Reader.Read(p) | ||
} | ||
|
||
// Write forwards writes to the underlying bufWriter and immediately flushes. | ||
func (c *rwConn) Write(p []byte) (int, error) { | ||
n, err := c.BufWriter.Write(p) | ||
if err := c.BufWriter.Flush(); err != nil { | ||
return 0, err | ||
} | ||
return n, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters