Documentation ¶
Overview ¶
base struct of connection.
connection interface.
TCPConnection. note: in OSX system, the default max concurrency is limited to 128, so when your concurrency number more than 128 will occur error: connect: connection reset by peer. you should by setting: 'sysctl -w kern.ipc.somaxconn=xxx', xxx is the max currency number. link https://github.com/golang/go/issues/20960.
updConnection.
Index ¶
- Constants
- type BaseConnection
- type CStore
- type ConnStore
- type Connection
- type TCPConnection
- func (t *TCPConnection) Close(data string)
- func (t *TCPConnection) GetLocalAddress() string
- func (t *TCPConnection) GetLocalIP() string
- func (t *TCPConnection) GetLocalPort() int
- func (t *TCPConnection) GetRecvBufferQueueSize() int
- func (t *TCPConnection) GetRemoteAddress() string
- func (t *TCPConnection) GetRemoteIP() string
- func (t *TCPConnection) GetRemotePort() int
- func (t *TCPConnection) GetSendBufferQueueSize() int
- func (t *TCPConnection) Read()
- func (t *TCPConnection) Send(buffer string, raw bool) interface{}
- type UDPConnection
- func (u *UDPConnection) AddRequestCount()
- func (u *UDPConnection) Close(data string)
- func (u *UDPConnection) GetLocalAddress() string
- func (u *UDPConnection) GetLocalIP() string
- func (u *UDPConnection) GetLocalPort() int
- func (u *UDPConnection) GetRemoteAddress() string
- func (u *UDPConnection) GetRemoteIP() string
- func (u *UDPConnection) GetRemotePort() int
- func (u *UDPConnection) Send(buffer string, raw bool) interface{}
Constants ¶
const ( // ReadBufferSize read buffer size. ReadBufferSize = 65535 // MaxSendBufferSize maximum size of send buffer. MaxSendBufferSize = 104856 // DefaultMaxSendBufferSize default maximum size of send buffer. DefaultMaxSendBufferSize = 104856 // MaxPackageSize maximum size of acceptable buffer. MaxPackageSize = 104856 // DefaultMaxPackageSize default maximum size of acceptable buffer. DefaultMaxPackageSize = 1048560 // StatusInitial initial status of connection. StatusInitial = 0 // StatusConnecting connecting status of connection. StatusConnecting = 1 // StatusEstablished established status of connection. StatusEstablished = 2 // StatusClosing closing status of connection. StatusClosing = 4 // StatusClosed closed status of connection. StatusClosed = 8 // GoerSendFail send fail. GoerSendFail = 2 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseConnection ¶
type BaseConnection struct { // ConnectionCount count of connection. ConnectionCount int // TotalRequest count of request. TotalRequest int // ThrowException count of error. ThrowException int // SendFail count of send fail. SendFail int }
BaseConnection Statistics on behalf of requests.
type CStore ¶
type CStore interface { // Set store a TCPConnection. Set(conn *TCPConnection) // Get return a TCPConnection. Get(connID int) (*TCPConnection, bool) // Del remove a TCPConnection from sync.Map. Del(connID int) // Range calls f sequentially for each key and value present in the map. Range(f func(key, value interface{}) bool) // Len return the count of all TCPConnection. Len() int32 }
CStore the interface of store all connection.
type ConnStore ¶
type ConnStore struct {
// contains filtered or unexported fields
}
ConnStore store all clients.
func (*ConnStore) Get ¶
func (cs *ConnStore) Get(connectionID int) (*TCPConnection, bool)
Get get a TCPConnection by ID.
type Connection ¶
type Connection interface { // Send sends data on the connection. Send(data string, raw bool) interface{} // Close close connection. Close(data string) // GetRemoteIP get remote IP. GetRemoteIP() string // GetRemotePort get remote port. GetRemotePort() int // GetRemoteAddress get remote address. GetRemoteAddress() string // GetLocalIP get local IP. GetLocalIP() string // GetLocalPort get local port. GetLocalPort() int // GetLocalAddress get local address. GetLocalAddress() string }
Connection the method of interface.
type TCPConnection ¶
type TCPConnection struct { // OnMessage emitted when data is received. OnMessage func(connection Connection, data []byte) // OnError emitted when a error occurs with connection. OnError func(connection Connection, code int, message string) // OnClose emitted when the other end of the socket send a FIN package. OnClose func(connection Connection) // OnBufferFull emitted when the send buffer becomes full. OnBufferFull func(connection Connection) // OnBufferDrain emitted when the send buffer becomes empty. OnBufferDrain func(connection Connection) // Transport transport. Transport string // Protocol application layer protocol. Protocol protocols.Protocol // ID the id of connection. ID int // MaxSendBufferSize set the maximum send buffer size for the current connection. MaxSendBufferSize int // MaxPackageSize set the maximum acceptable packet size for the current connection. MaxPackageSize int // Connections all connection instances, key is connection id and value is *net.Conn. Connections CStore // contains filtered or unexported fields }
TCPConnection struct.
func NewTCPConnection ¶
func NewTCPConnection(socket *net.Conn, remoteAddress string) *TCPConnection
NewTCPConnection new a tcp connection.
func (*TCPConnection) GetLocalAddress ¶
func (t *TCPConnection) GetLocalAddress() string
GetLocalAddress get remote address, the format is like this http://127.0.0.1:8080.
func (*TCPConnection) GetLocalIP ¶
func (t *TCPConnection) GetLocalIP() string
GetLocalIP get local ip.
func (*TCPConnection) GetLocalPort ¶
func (t *TCPConnection) GetLocalPort() int
GetLocalPort get local port.
func (*TCPConnection) GetRecvBufferQueueSize ¶
func (t *TCPConnection) GetRecvBufferQueueSize() int
GetRecvBufferQueueSize get recv buffer queue size.
func (*TCPConnection) GetRemoteAddress ¶
func (t *TCPConnection) GetRemoteAddress() string
GetRemoteAddress get remote address, the format is like this http://127.0.0.1:8080.
func (*TCPConnection) GetRemoteIP ¶
func (t *TCPConnection) GetRemoteIP() string
GetRemoteIP get remote ip.
func (*TCPConnection) GetRemotePort ¶
func (t *TCPConnection) GetRemotePort() int
GetRemotePort get remote port.
func (*TCPConnection) GetSendBufferQueueSize ¶
func (t *TCPConnection) GetSendBufferQueueSize() int
GetSendBufferQueueSize get send buffer queue size.
func (*TCPConnection) Send ¶
func (t *TCPConnection) Send(buffer string, raw bool) interface{}
Send send data on the connection. if connection is closing or closed, return false. if connection have not been established, then save encode data info application send buffer, otherwise direct send encode of data into system socket send buffer.
return value. if return true, indicate the message already send to operating system layer socket send buffer. else return false, send fail. return nil indicate the message already send to application send buffer, waiting for into operating system socket send buffer.
type UDPConnection ¶
type UDPConnection struct { // Protocol Application layer protocol. Protocol protocols.Protocol // contains filtered or unexported fields }
UDPConnection struct.
func NewUDPConnection ¶
func NewUDPConnection(socket net.PacketConn, remoteAddr net.Addr) *UDPConnection
NewUDPConnection new a object of UDPConnection.
func (*UDPConnection) AddRequestCount ¶
func (u *UDPConnection) AddRequestCount()
AddRequestCount increase request record.
func (*UDPConnection) GetLocalAddress ¶
func (u *UDPConnection) GetLocalAddress() string
GetLocalAddress get remote address, the format is like this http://127.0.0.1:8080.
func (*UDPConnection) GetLocalIP ¶
func (u *UDPConnection) GetLocalIP() string
GetLocalIP get local ip.
func (*UDPConnection) GetLocalPort ¶
func (u *UDPConnection) GetLocalPort() int
GetLocalPort get local port.
func (*UDPConnection) GetRemoteAddress ¶
func (u *UDPConnection) GetRemoteAddress() string
GetRemoteAddress get remote address, the format is like this 127.0.0.1:8080.
func (*UDPConnection) GetRemoteIP ¶
func (u *UDPConnection) GetRemoteIP() string
GetRemoteIP get remote ip.
func (*UDPConnection) GetRemotePort ¶
func (u *UDPConnection) GetRemotePort() int
GetRemotePort get remote port.
func (*UDPConnection) Send ¶
func (u *UDPConnection) Send(buffer string, raw bool) interface{}
Send send data on the connection. if return true indicate message send success, otherwise return false indicate send fail. return nil indicate no data to send.