Documentation ¶
Overview ¶
Package tcpconnect provides a tcp dialer with a two-channel []byte{} interface (In, Out)
Index ¶
- func EchoHandler(ctx context.Context, c *TCPconnect)
- func SpeakThenEchoHandler(ctx context.Context, c *TCPconnect)
- type TCPconnect
- func (c *TCPconnect) Dial(ctx context.Context, uri string)
- func (c *TCPconnect) Echo(ctx context.Context, uri string)
- func (c *TCPconnect) HandleConn(ctx context.Context, conn net.Conn)
- func (c *TCPconnect) Listen(ctx context.Context, uri string, handler func(context.Context, *TCPconnect))
- func (c *TCPconnect) WithConn(conn *net.Conn) *TCPconnect
- func (c *TCPconnect) WithMaxFrameBytes(max int) *TCPconnect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EchoHandler ¶
func EchoHandler(ctx context.Context, c *TCPconnect)
EchoHandler is for testing (it echoes messages)
func SpeakThenEchoHandler ¶
func SpeakThenEchoHandler(ctx context.Context, c *TCPconnect)
SpeakThenEchoHandler is used for testing (it says something then echoes)
Types ¶
type TCPconnect ¶
type TCPconnect struct { // In channel carries messages FROM TCP conn In chan []byte //Out channel carries messages TO TCP conn Out chan []byte // MaxFrameBytes represents the maximum size of a single message MaxFrameBytes int // Listeners is a list of connections when in listening mode Listeners []*TCPconnect // ID identifies the instance, useful for logging ID string // Conn holds a pointer to the net.conn Conn *net.Conn }
TCPconnect represents a TCP connection
func (*TCPconnect) Dial ¶
func (c *TCPconnect) Dial(ctx context.Context, uri string)
Dial starts a connection to the given URI
func (*TCPconnect) Echo ¶
func (c *TCPconnect) Echo(ctx context.Context, uri string)
Echo echoes messages (used for testing)
func (*TCPconnect) HandleConn ¶
func (c *TCPconnect) HandleConn(ctx context.Context, conn net.Conn)
HandleConn handles connections, including reading and writing
func (*TCPconnect) Listen ¶
func (c *TCPconnect) Listen(ctx context.Context, uri string, handler func(context.Context, *TCPconnect))
Listen returns new conns over a channel for use by other handlers
func (*TCPconnect) WithConn ¶
func (c *TCPconnect) WithConn(conn *net.Conn) *TCPconnect
WithConn sets which net.Conn is used
func (*TCPconnect) WithMaxFrameBytes ¶
func (c *TCPconnect) WithMaxFrameBytes(max int) *TCPconnect
WithMaxFrameBytes sets the maximum bytes that can be sent per frame this impacts memory usage (larger max frame sizes require more memory for the buffer)