Documentation ¶
Index ¶
- Variables
- type ConnWrapper
- type DataConn
- func (d DataConn) Buffered() int
- func (d DataConn) Close() error
- func (d DataConn) Flush() error
- func (d DataConn) ReadBytes() ([]byte, error)
- func (d DataConn) ReadInt() (int, error)
- func (d DataConn) ReadString() (string, error)
- func (d DataConn) ReadStruct(target interface{}) error
- func (d DataConn) WriteBytes(msg []byte) (int, error)
- func (d DataConn) WriteInt(msg int) (int, error)
- func (d DataConn) WriteString(msg string) (int, error)
- func (d DataConn) WriteStruct(msg interface{}) (int, error)
Constants ¶
This section is empty.
Variables ¶
var (
DataConnProxy proxy.Dialer
)
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 ¶
Buffered returns the number of bytes that have been written into the current buffer.
func (DataConn) Close ¶
Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.
func (DataConn) ReadString ¶
ReadString reads a string from the underlying connection
func (DataConn) ReadStruct ¶
ReadStruct reades an serialized struct from the underlying connection and unmarshals it into the provided struct
func (DataConn) WriteBytes ¶
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 ¶
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 ¶
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 ¶
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.