dtcp

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNetConn

func NewNetConn(addr string, timeout ...time.Duration) (net.Conn, error)

NewNetConn 创建并返回一个 net.Conn 链接,addr的格式为:"127.0.0.1:80", timeout为链接超时时间,如果不传则表示使用默认的30秒超时

func NewNetConnTLS

func NewNetConnTLS(addr string, tslConfig *tls.Config, timeout ...time.Duration) (net.Conn, error)

NewNetConnTLS 创建并返回一个tls加密的 net.Conn 链接,addr的格式为:"127.0.0.1:80",

Types

type Conn

type Conn struct {
	net.Conn //tcp 链接的对象
	// contains filtered or unexported fields
}

Conn tcp链接对象

func NewConn

func NewConn(addr string, timeout ...time.Duration) (*Conn, error)

NewConn 创建一个tcp链接

func NewConnByNetConn

func NewConnByNetConn(conn net.Conn) *Conn

NewConnByNetConn 通过已有的net.Conn 创建一个tcp链接

func NewConnTLS

func NewConnTLS(addr string, tlsConfig *tls.Config) (*Conn, error)

NewConnTLS 创建一个TLS加密的tcp链接

func (*Conn) Recv

func (that *Conn) Recv(length int, retry ...Retry) ([]byte, error)

Recv 读取数据

func (*Conn) RecvLine

func (that *Conn) RecvLine(retry ...Retry) ([]byte, error)

RecvLine 获取以 \n 结尾的一行,但是返回的数据不包含 \n

func (*Conn) RecvWithTimeout

func (that *Conn) RecvWithTimeout(length int, timeout time.Duration, retry ...Retry) (data []byte, err error)

RecvWithTimeout 在指定的时间内读取数据

func (*Conn) Send

func (that *Conn) Send(data []byte, retry ...Retry) error

Send 发送数据到远端,没有任何缓冲,直接调用tcp write写入到系统缓冲区

func (*Conn) SendRecv

func (that *Conn) SendRecv(data []byte, length int, retry ...Retry) ([]byte, error)

SendRecv 发送并且读取

func (*Conn) SendWithTimeout

func (that *Conn) SendWithTimeout(data []byte, timeout time.Duration, retry ...Retry) (err error)

SendWithTimeout 在指定的时间内发送数据

func (*Conn) SetDeadline

func (that *Conn) SetDeadline(t time.Time) error

SetDeadline 设置超时时间

func (*Conn) SetRecvDeadline

func (that *Conn) SetRecvDeadline(t time.Time) error

SetRecvDeadline 设置读取超时时间

func (*Conn) SetSendDeadline

func (that *Conn) SetSendDeadline(t time.Time) error

SetSendDeadline 设置发送超时时间

type Retry

type Retry struct {
	Count    int           // Retry count.
	Interval time.Duration // Retry interval.
}

重试结构体

Jump to

Keyboard shortcuts

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