diff options
author | Valentin Popov <valentin@popov.link> | 2025-06-05 01:39:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-05 01:39:45 +0300 |
commit | 3b579b3bab9a91338ee5821edf9dcd852b105fe9 (patch) | |
tree | 3aa5f1364397f968f7face32d11c135cb3cf227e /internal/conn/conn.go | |
parent | b139fd5838a94c982caf5376486fdba89f68bea8 (diff) | |
parent | 67ea5c1c87afd440bad06c153d951e3a62113c68 (diff) | |
download | go-metatrader4-3b579b3bab9a91338ee5821edf9dcd852b105fe9.tar.xz go-metatrader4-3b579b3bab9a91338ee5821edf9dcd852b105fe9.zip |
Merge pull request #7 from valentineus/codex/prepare-documentation-for-methods-and-types
Improve package documentation
Diffstat (limited to 'internal/conn/conn.go')
-rw-r--r-- | internal/conn/conn.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/internal/conn/conn.go b/internal/conn/conn.go index 0bf3ae6..6df7e49 100644 --- a/internal/conn/conn.go +++ b/internal/conn/conn.go @@ -7,6 +7,7 @@ import ( "time" ) +// Conn is a wrapper around net.Conn with convenience helpers. type Conn struct { netConn net.Conn } @@ -14,6 +15,7 @@ type Conn struct { // FromNetConn wraps an existing net.Conn. Useful for tests. func FromNetConn(n net.Conn) *Conn { return &Conn{netConn: n} } +// Dial opens a TCP connection to addr using the given timeout. func Dial(ctx context.Context, addr string, timeout time.Duration) (*Conn, error) { d := net.Dialer{Timeout: timeout} c, err := d.DialContext(ctx, "tcp", addr) @@ -23,6 +25,7 @@ func Dial(ctx context.Context, addr string, timeout time.Duration) (*Conn, error return &Conn{netConn: c}, nil } +// Close closes the underlying network connection. func (c *Conn) Close() error { if c.netConn == nil { return nil @@ -30,6 +33,7 @@ func (c *Conn) Close() error { return c.netConn.Close() } +// Send writes data to the connection with the provided timeout. func (c *Conn) Send(ctx context.Context, data []byte, timeout time.Duration) error { if dl, ok := ctx.Deadline(); ok { if err := c.netConn.SetWriteDeadline(dl); err != nil { @@ -44,6 +48,7 @@ func (c *Conn) Send(ctx context.Context, data []byte, timeout time.Duration) err return err } +// Receive reads all data from the connection with the provided timeout. func (c *Conn) Receive(ctx context.Context, timeout time.Duration) ([]byte, error) { if dl, ok := ctx.Deadline(); ok { if err := c.netConn.SetReadDeadline(dl); err != nil { |