diff options
| author | onur1 <onur1@onurgunduz.com> | 2023-01-01 18:44:45 +0100 |
|---|---|---|
| committer | onur1 <onur1@onurgunduz.com> | 2023-01-01 18:44:45 +0100 |
| commit | 77e13c055fdc76ff9babbb43754a8f8e44ca6128 (patch) | |
| tree | 298ba0734bf93cee47aad6150c9ffcd4ca3d87dc /binproto.go | |
| parent | 02387a1dc1ec156e0613920645cf47a51a04a930 (diff) | |
| download | muxer-77e13c055fdc76ff9babbb43754a8f8e44ca6128.tar.gz muxer-77e13c055fdc76ff9babbb43754a8f8e44ca6128.zip | |
Add documentation
Diffstat (limited to 'binproto.go')
| -rw-r--r-- | binproto.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/binproto.go b/binproto.go index 6b2ca54..016c87c 100644 --- a/binproto.go +++ b/binproto.go @@ -7,6 +7,10 @@ import ( "net/textproto" ) +// A Conn represents a binary network protocol connection. +// It consists of a Reader and Writer to manage I/O +// and a Pipeline (which is borrowed from textproto) to sequence +// concurrent requests on the connection. type Conn struct { Reader Writer @@ -14,6 +18,7 @@ type Conn struct { conn io.ReadWriteCloser } +// NewConn returns a new Conn using conn for I/O. func NewConn(conn io.ReadWriteCloser) *Conn { r, w := NewReaderSize(bufio.NewReader(conn), 16), NewWriter(bufio.NewWriter(conn)) return &Conn{ @@ -23,6 +28,9 @@ func NewConn(conn io.ReadWriteCloser) *Conn { } } +// Send is a convenience method that sends a variable number of messages +// after waiting its turn in the pipeline. +// Send returns the id of the command, for use with StartResponse and EndResponse. func (c *Conn) Send(m ...*Message) (id uint, err error) { id = c.Next() c.StartRequest(id) @@ -34,10 +42,13 @@ func (c *Conn) Send(m ...*Message) (id uint, err error) { return id, nil } +// Close closes the connection. func (c *Conn) Close() error { return c.conn.Close() } +// Dial connects to the given address on the given network using net.Dial +// and then returns a new Conn for the connection. func Dial(network, addr string) (*Conn, error) { c, err := net.Dial(network, addr) if err != nil { |
