Documentation ¶
Index ¶
- Variables
- func ListenUdpWithAddr(addr string) (*net.UDPConn, error)
- func TcpConnectTimeout(lAddr, rAddr string, timeout time.Duration) (net.Conn, error)
- type IConnection
- type ModOption
- type Option
- type Stat
- type StatAtomic
- type TcpClientConnection
- func (c *TcpClientConnection) Close()
- func (c *TcpClientConnection) Done() <-chan error
- func (c *TcpClientConnection) Flush() error
- func (c *TcpClientConnection) GetStat() (s Stat)
- func (c *TcpClientConnection) LocalAddr() net.Addr
- func (c *TcpClientConnection) Read(b []byte) (n int, rAddr net.Addr, err error)
- func (c *TcpClientConnection) ReadAtLeast(buf []byte, min int) (n int, err error)
- func (c *TcpClientConnection) ReadLine() (line []byte, isPrefix bool, err error)
- func (c *TcpClientConnection) Write(b []byte) (n int, err error)
- func (c *TcpClientConnection) WriteByAddr(b []byte, rAddr net.Addr) (n int, err error)
- type TcpConnectHandle
- type TcpServer
- type UdpConnection
- func (c *UdpConnection) Close()
- func (c *UdpConnection) Done() <-chan error
- func (c *UdpConnection) Flush() error
- func (c *UdpConnection) GetStat() (s Stat)
- func (c *UdpConnection) LocalAddr() net.Addr
- func (c *UdpConnection) Read(b []byte) (n int, rAddr net.Addr, err error)
- func (c *UdpConnection) ReadAtLeast(buf []byte, min int) (n int, err error)
- func (c *UdpConnection) ReadLine() (line []byte, isPrefix bool, err error)
- func (c *UdpConnection) Write(b []byte) (n int, err error)
- func (c *UdpConnection) WriteByAddr(b []byte, rAddr net.Addr) (n int, err error)
- type WriteChanFullBehavior
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrConnectionPanic = errors.New("connection: using in a wrong way") ErrClosedAlready = errors.New("connection: connection closed already") ErrWriteChanFull = errors.New("connection: write channel full") ErrRAddrIsNil = errors.New("connection: remote addr is nil") ErrUdpUnsupported = errors.New("connection: udp unsupported") )
Functions ¶
Types ¶
type IConnection ¶
type IConnection interface { Read(b []byte) (n int, rAddr net.Addr, err error) // ReadAtLeast tcp支持 ReadAtLeast(buf []byte, min int) (n int, err error) // ReadLine tcp支持 ReadLine() (line []byte, isPrefix bool, err error) Write(b []byte) (n int, err error) WriteByAddr(b []byte, rAddr net.Addr) (n int, err error) Close() LocalAddr() net.Addr Flush() error // Done /****************************************************** * @Description: 阻塞直到连接关闭或发生错误 * @return <-chan 返回nil则是本端主动调用Close关闭 ******************************************************/ Done() <-chan error GetStat() Stat }
type Option ¶
type Option struct { //tcp有效 如果不为0,则之后每次读/写使用bufio的缓冲 ReadBufSize int WriteBufSize int // 如果不为0,则之后每次读/写都带超时 ReadTimeoutMs int WriteTimeoutMs int // 如果不为0,则写使用channel将数据发送到后台协程中发送 WriteChanSize int // 系统socket缓存大小 SocketReadBufSize int SocketWriteBufSize int // 使用channel发送数据时,channel满了时Write函数的行为 // WriteChanFullBehaviorReturnError 返回错误 // WriteChanFullBehaviorBlock 阻塞直到向channel写入成功 WriteChanFullBehavior WriteChanFullBehavior // LocalAddr LocalAddr string // RemoteAddr RemoteAddr string TcpConnectTimeout time.Duration }
type StatAtomic ¶
type StatAtomic struct { ReadBytesSum atomicUtils.Uint64 WroteBytesSum atomicUtils.Uint64 }
type TcpClientConnection ¶
type TcpClientConnection struct {
// contains filtered or unexported fields
}
func NewTcpClientConnection ¶
func NewTcpClientConnection(modOptions ...ModOption) (*TcpClientConnection, error)
func NewTcpServerConnection ¶
func NewTcpServerConnection(conn net.Conn, modOptions ...ModOption) (*TcpClientConnection, error)
func (*TcpClientConnection) Close ¶
func (c *TcpClientConnection) Close()
func (*TcpClientConnection) Done ¶
func (c *TcpClientConnection) Done() <-chan error
func (*TcpClientConnection) Flush ¶
func (c *TcpClientConnection) Flush() error
func (*TcpClientConnection) GetStat ¶
func (c *TcpClientConnection) GetStat() (s Stat)
func (*TcpClientConnection) LocalAddr ¶
func (c *TcpClientConnection) LocalAddr() net.Addr
func (*TcpClientConnection) ReadAtLeast ¶
func (c *TcpClientConnection) ReadAtLeast(buf []byte, min int) (n int, err error)
func (*TcpClientConnection) ReadLine ¶
func (c *TcpClientConnection) ReadLine() (line []byte, isPrefix bool, err error)
func (*TcpClientConnection) Write ¶
func (c *TcpClientConnection) Write(b []byte) (n int, err error)
func (*TcpClientConnection) WriteByAddr ¶
type TcpConnectHandle ¶
type TcpConnectHandle func(ctx context.Context, conn *TcpClientConnection)
type TcpServer ¶
type TcpServer struct {
// contains filtered or unexported fields
}
func NewTcpServer ¶
func NewTcpServer(handle TcpConnectHandle, modOptions ...ModOption) *TcpServer
type UdpConnection ¶
type UdpConnection struct {
// contains filtered or unexported fields
}
func NewUdpConnection ¶
func NewUdpConnection(modOptions ...ModOption) (*UdpConnection, error)
func (*UdpConnection) Close ¶
func (c *UdpConnection) Close()
func (*UdpConnection) Done ¶
func (c *UdpConnection) Done() <-chan error
func (*UdpConnection) Flush ¶
func (c *UdpConnection) Flush() error
func (*UdpConnection) GetStat ¶
func (c *UdpConnection) GetStat() (s Stat)
func (*UdpConnection) LocalAddr ¶
func (c *UdpConnection) LocalAddr() net.Addr
func (*UdpConnection) ReadAtLeast ¶
func (c *UdpConnection) ReadAtLeast(buf []byte, min int) (n int, err error)
func (*UdpConnection) ReadLine ¶
func (c *UdpConnection) ReadLine() (line []byte, isPrefix bool, err error)
func (*UdpConnection) WriteByAddr ¶
type WriteChanFullBehavior ¶
type WriteChanFullBehavior int
const ( WriteChanFullBehaviorReturnError WriteChanFullBehavior = iota + 1 WriteChanFullBehaviorBlock )
Click to show internal directories.
Click to hide internal directories.