connection

package
v0.0.0-...-72cce0b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DataConnProxy proxy.Dialer
)
View Source
var (
	GetConnFunc func(network, address string) (ConnWrapper, error)
)

Functions

This section is empty.

Types

type ConnWrapper

type ConnWrapper interface {
	WriteBytes(msg []byte) (int, error)
	ReadBytes() ([]byte, error)

	WriteString(msg string) (int, error)
	ReadString() (string, error)

	WriteInt(msg int) (int, error)
	ReadInt() (int, error)

	WriteStruct(msg interface{}) (int, error)
	ReadStruct(target interface{}) error

	Flush() error
	Close() error
	Buffered() int
}

func DialDataConn

func DialDataConn(network, address string) (ConnWrapper, error)

DialDataConn creates a new connection that uses the, possibly set, proxy and then wraps it in a DataConn

func WrapConnection

func WrapConnection(conn net.Conn) ConnWrapper

WrapConnection creates a new DataConn from a net.Conn

type DataConn

type DataConn struct {
	// contains filtered or unexported fields
}

DataConn is a helper struct to simplify communication over a net.Conn. Also tries to save bandwidth by using a manually flushed bufio.ReadWriter. Has a artificial limit of 16K for message size.

func (DataConn) Buffered

func (d DataConn) Buffered() int

Buffered returns the number of bytes that have been written into the current buffer.

func (DataConn) Close

func (d DataConn) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (DataConn) Flush

func (d DataConn) Flush() error

Flush writes any buffered data to the underlying io.Writer.

func (DataConn) ReadBytes

func (d DataConn) ReadBytes() ([]byte, error)

ReadBytes reads a byte slice from the underlying connection

func (DataConn) ReadInt

func (d DataConn) ReadInt() (int, error)

ReadInt reades an int from the underlying connection

func (DataConn) ReadString

func (d DataConn) ReadString() (string, error)

ReadString reads a string from the underlying connection

func (DataConn) ReadStruct

func (d DataConn) ReadStruct(target interface{}) error

ReadStruct reades an serialized struct from the underlying connection and unmarshals it into the provided struct

func (DataConn) WriteBytes

func (d DataConn) WriteBytes(msg []byte) (int, error)

WriteBytes writes a byte slice to the connection. It returns the number of bytes written. If n < len(msg), it also returns an error explaining why the write is short.

func (DataConn) WriteInt

func (d DataConn) WriteInt(msg int) (int, error)

WriteInt writes the specified int to the underlying connection It returns the number of bytes written. If n < 4, it also returns an error explaining why the write is short.

func (DataConn) WriteString

func (d DataConn) WriteString(msg string) (int, error)

WriteString writes the specified string to the underlying connectrion It returns the number of bytes written. If n < len(msg), it also returns an error explaining why the write is short.

func (DataConn) WriteStruct

func (d DataConn) WriteStruct(msg interface{}) (int, error)

WriteStruct serializes and then writes the specified struct to the underlying connection It returns the number of bytes written. If n < len(json.Marshal(msg)), it also returns an error explaining why the write is short.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL