1
0
Fork 0

half-close all connections supporting `CloseWrite() error`

Usecase: support TCP and UNIX connections, support "wrapped" connections (peek
first bytes to support multiple protocols on one listening socket).
logger
Stefan Bühler 2016-08-14 12:00:12 +02:00
parent b34cad17d2
commit 836d3b2bda
1 changed files with 5 additions and 1 deletions

View File

@ -340,11 +340,15 @@ func sendReply(w io.Writer, resp uint8, addr *AddrSpec) error {
return err
}
type closeWriter interface {
CloseWrite() error
}
// proxy is used to suffle data from src to destination, and sends errors
// down a dedicated channel
func proxy(dst io.Writer, src io.Reader, errCh chan error) {
_, err := io.Copy(dst, src)
if tcpConn, ok := dst.(*net.TCPConn); ok {
if tcpConn, ok := dst.(closeWriter); ok {
tcpConn.CloseWrite()
}
errCh <- err