tcp

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package tcp implements the framework of TCP connection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn 根据Protocol读写TCP数据

func Accept

func Accept(ln net.Listener, de Decoder) (*Conn, error)

Accept 接受连接

func Dial

func Dial(network string, address string, de Decoder) (*Conn, error)

Dial 连接对方

func (*Conn) Close

func (conn *Conn) Close() error

Close 关闭TCPConn,然后等待已接收数据处理完成

func (*Conn) Send

func (conn *Conn) Send(en Encoder) error

type Decoder

type Decoder interface {
	// ReadFrom 从TCPConn中读取数据,返回数据处理Handler,如果连接接收缓冲没有数据,方法将会阻塞
	// 返回error保持与TCPConn.Read保持一致,io.EOF为对方关闭,net.ErrClosed为己方关闭
	ReadFrom(c net.Conn) (Handler, error)
}

Decoder 从TCP连接中读取数据的解析器,并返回Handler,在单独goroutine中执行

type Encoder

type Encoder interface {
	WriteTo(c net.Conn) error
}

Encoder 解析类型为[]byte数据,由Conn写入到发送通道

type Handler

type Handler interface {
	Handle()
}

Handler 由Decoder从接收通道中解析数据后返回,执行数据处理任务

Jump to

Keyboard shortcuts

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