diff options
author | Ben Burkert <ben@benburkert.com> | 2019-04-26 22:45:45 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-04-26 22:46:45 -0700 |
commit | 66bca6fc221393c9553cbaa0486e07c8124e2477 (patch) | |
tree | f16003e77764b22369af09479db0a51234b9f68b /pkg/tcpip/adapters/gonet/gonet.go | |
parent | 43dff57b878edb5502daf486cbc13b058780dd56 (diff) |
tcpip/adapters/gonet: add CloseRead & CloseWrite methods to Conn
Add the CloseRead & CloseWrite methods that performs shutdown on the
corresponding Read & Write sides of a connection.
Change-Id: I3996a2abdc7cd68a2becba44dc4bd9f0919d2ce1
PiperOrigin-RevId: 245537950
Diffstat (limited to 'pkg/tcpip/adapters/gonet/gonet.go')
-rw-r--r-- | pkg/tcpip/adapters/gonet/gonet.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/pkg/tcpip/adapters/gonet/gonet.go b/pkg/tcpip/adapters/gonet/gonet.go index 232d44d24..628e28f57 100644 --- a/pkg/tcpip/adapters/gonet/gonet.go +++ b/pkg/tcpip/adapters/gonet/gonet.go @@ -435,6 +435,28 @@ func (c *Conn) Close() error { return nil } +// CloseRead shuts down the reading side of the TCP connection. Most callers +// should just use Close. +// +// A TCP Half-Close is performed the same as CloseRead for *net.TCPConn. +func (c *Conn) CloseRead() error { + if terr := c.ep.Shutdown(tcpip.ShutdownRead); terr != nil { + return c.newOpError("close", errors.New(terr.String())) + } + return nil +} + +// CloseWrite shuts down the writing side of the TCP connection. Most callers +// should just use Close. +// +// A TCP Half-Close is performed the same as CloseWrite for *net.TCPConn. +func (c *Conn) CloseWrite() error { + if terr := c.ep.Shutdown(tcpip.ShutdownWrite); terr != nil { + return c.newOpError("close", errors.New(terr.String())) + } + return nil +} + // LocalAddr implements net.Conn.LocalAddr. func (c *Conn) LocalAddr() net.Addr { a, err := c.ep.GetLocalAddress() |