Documentation ¶
Overview ¶
Package nbconn implements a non-blocking net.Conn wrapper.
It is designed to solve three problems.
The first is resolving the deadlock that can occur when both sides of a connection are blocked writing because all buffers between are full. See https://github.com/jackc/pgconn/issues/27 for discussion.
The second is the inability to use a write deadline with a TLS.Conn without killing the connection.
The third is to efficiently check if a connection has been closed via a non-blocking read.
Index ¶
- Variables
- type Conn
- type NetConn
- func (c *NetConn) BufferReadUntilBlock() error
- func (c *NetConn) Close() (err error)
- func (c *NetConn) Flush() error
- func (c *NetConn) LocalAddr() net.Addr
- func (c *NetConn) Read(b []byte) (n int, err error)
- func (c *NetConn) RemoteAddr() net.Addr
- func (c *NetConn) SetDeadline(t time.Time) error
- func (c *NetConn) SetReadDeadline(t time.Time) error
- func (c *NetConn) SetWriteDeadline(t time.Time) error
- func (c *NetConn) Write(b []byte) (n int, err error)
- type TLSConn
- func (tc *TLSConn) BufferReadUntilBlock() error
- func (tc *TLSConn) Close() error
- func (tc *TLSConn) Flush() error
- func (tc *TLSConn) LocalAddr() net.Addr
- func (tc *TLSConn) Read(b []byte) (n int, err error)
- func (tc *TLSConn) RemoteAddr() net.Addr
- func (tc *TLSConn) SetDeadline(t time.Time) error
- func (tc *TLSConn) SetReadDeadline(t time.Time) error
- func (tc *TLSConn) SetWriteDeadline(t time.Time) error
- func (tc *TLSConn) Write(b []byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
var ErrWouldBlock = new(wouldBlockError)
var NonBlockingDeadline = time.Date(1900, 1, 1, 0, 0, 0, 608536336, time.UTC)
NonBlockingDeadline is a magic value that when passed to Set[Read]Deadline places the connection in non-blocking read mode.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface { net.Conn // Flush flushes any buffered writes. Flush() error // BufferReadUntilBlock reads and buffers any sucessfully read bytes until the read would block. BufferReadUntilBlock() error }
Conn is a net.Conn where Write never blocks and always succeeds. Flush or Read must be called to actually write to the underlying connection.
type NetConn ¶
type NetConn struct {
// contains filtered or unexported fields
}
NetConn is a non-blocking net.Conn wrapper. It implements net.Conn.
func (*NetConn) BufferReadUntilBlock ¶
func (*NetConn) RemoteAddr ¶
func (*NetConn) SetDeadline ¶
SetDeadline is the equivalent of calling SetReadDealine(t) and SetWriteDeadline(t).
func (*NetConn) SetReadDeadline ¶
SetReadDeadline sets the read deadline as t. If t == NonBlockingDeadline then future reads will be non-blocking.
type TLSConn ¶
type TLSConn struct {
// contains filtered or unexported fields
}
TLSConn is a TLS wrapper around a *Conn. It works around a temporary write error (such as a timeout) being fatal to a tls.Conn.
func TLSClient ¶
TLSClient establishes a TLS connection as a client over conn using config.
To avoid the first Read on the returned *TLSConn also triggering a Write due to the TLS handshake and thereby potentially causing a read and write deadlines to behave unexpectedly, Handshake is called explicitly before the *TLSConn is returned.