const ( DefaultReadBufferSize = 1024 * 64 DefaultMaxWriteBufferSize = 0 DefaultMaxConnReadTimesPerEventLoop = 3 DefaultUDPReadTimeout = 120 * time.Second )View Source
const ( NETWORK_TCP = "tcp" NETWORK_TCP4 = "tcp4" NETWORK_TCP6 = "tcp6" NETWORK_UDP = "udp" NETWORK_UDP4 = "udp4" NETWORK_UDP6 = "udp6" NETWORK_UNIX = "unix" NETWORK_UNIXGRAM = "unixgram" NETWORK_UNIXPACKET = "unixpacket" )
This section is empty.
Conn implements net.Conn with non-blocking interfaces.
Dial calls net.Dial to make a net.Conn and convert it to *nbio.Conn.
Dial calls net.DialTimeout to make a net.Conn and convert it to *nbio.Conn.
NBConn converts net.Conn to *Conn.
func (c *Conn) AsyncRead()
AsyncReadInPoller is used for reading data async.
Close implements closes connection.
CloseWithError closes connection with user specified error.
func (*Conn) DataHandler ¶ added in v1.2.4DataHandler returns Conn's data handler.
Execute is used to run the job.
How it works: If the job is the head/first of the Conn's job list, it will call the nbio.Engine.Execute to run all the jobs in the job list that include:
Else if the job is not the head/first of the job list, it will push the job to the back of the job list and wait to be called. This guarantees there's at most one flow or goroutine running job/jobs for each Conn. This guarantees all the jobs are executed in order.
Notice:
ExecuteLen returns the length of the Conn's job list.
Hash returns a hash code of this connection.
IsClosed returns whether the Conn is closed.
IsTCP returns whether this Conn is a TCP Conn.
IsUDP returns whether this Conn is a UDP Conn.
IsUnix returns whether this Conn is a Unix Conn.
LocalAddr returns the local network address, if known.
func (c *Conn) MustExecute(job func())
MustExecute implements a similar function as Execute did, but will still execute or push the job to the back of the job list no matter whether Conn has been closed, it guarantees the job to be executed. This is used to handle the close event in nbio/nbhttp.
OnData registers Conn's data handler. Notice:
Read . Depracated . It was used to customize users' reading implementation, but better to use `ReadAndGetConn` instead, which can handle different types of connection and returns the consistent connection instance for UDP. Notice: non-blocking interface, should not be used as you use std.
func (*Conn) ReadAndGetConn ¶ added in v1.3.1ReadAndGetConn handles reading for different types of connection. It returns the real connection:
Notice: non-blocking interface, should not be used as you use std.
RemoteAddr returns the remote network address, if known.
func (c *Conn) ResetPollerEvent()
func (c *Conn) Session() interface{}
Session returns user session.
SetDeadline sets deadline for both read and write. If it is time.Zero, SetDeadline will clear the deadlines.
SetKeepAlive sets whether the operating system should send keep-alive messages on the connection.
SetKeepAlivePeriod sets period between keep-alives.
SetNoDelay controls whether the operating system should delay packet transmission in hopes of sending fewer packets (Nagle's algorithm). The default is true (no delay), meaning that data is sent as soon as possible after a Write.
SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.
SetReadDeadline sets the deadline for future Read calls. When the user doesn't update the deadline and the deadline exceeds, the connection will be closed. If it is time.Zero, SetReadDeadline will clear the deadline.
Notice:
func (c *Conn) SetSession(session interface{})
SetSession sets user session.
SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.
SetWriteDeadline sets the deadline for future data writing. If it is time.Zero, SetReadDeadline will clear the deadline.
If the next Write call writes all the data successfully and there's no data left to bewritten, the deadline timer will be cleared automatically; Else when the user doesn't update the deadline and the deadline exceeds, the connection will be closed.
Write writes data to the connection. Notice:
Writev does similar things as Write, but with [][]byte input arg. Notice: doesn't support UDP if more than 1 []byte.
ConnType is used to identify different types of Conn.
const ( ConnTypeTCP ConnType = iota + 1 ConnTypeUDPServer ConnTypeUDPClientFromRead ConnTypeUDPClientFromDial ConnTypeUnix )
Engine is a manager of poller.
NewEngine creates an Engine and init default configurations.
AddConn adds conn to a poller.
DialAsync connects asynchrony to the address on the named network.
DialAsync connects asynchrony to the address on the named network with timeout.
OnAcceptError is called when accept error.
OnClose registers callback for disconnected.
OnData registers callback for data.
OnDataPtr registers callback for data ptr.
OnOpen registers callback for new connection.
OnRead registers callback for reading event.
OnReadBufferAlloc registers callback for memory allocating.
OnReadBufferFree registers callback for memory release.
func (g *Engine) OnStop(h func())
OnStop registers callback before Engine is stopped.
OnOpen registers callback for new connection.
OnWrittenSize registers callback for written size. If len(b) is bigger than 0, it represents that it's writing a buffer, else it's operating by Sendfile.
PollerBuffer returns Poller's buffer by Conn, can be used on linux/bsd.
PollerBufferPtr returns Poller's buffer by Conn, can be used on linux/bsd.
func (e *Engine) SetETAsyncRead()
SetETAsyncRead .
func (e *Engine) SetLTSyncRead()
SetLTSyncRead .
Shutdown stops Engine gracefully with context.
Start inits and starts pollers.
Stop closes listeners/pollers/conns/timer.
Gopher keeps old type to compatible with new name Engine.
type ProtocolStack struct { }
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4