A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pkg.go.dev/github.com/lesismal/nbio below:

nbio package - github.com/lesismal/nbio - Go Packages

View Source
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.4

DataHandler 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:

  1. This job
  2. New jobs that are pushed to the back of the list before this job is done.
  3. nbio.Engine.Execute returns until there's no more jobs in the job list.

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:

  1. The job wouldn't run or pushed to the back of the job list if the connection is closed.
  2. nbio.Engine.Execute is handled by a goroutine pool by default, users can customize it.

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:

  1. The data readed by the poller is not handled by this Conn's data handler by default.
  2. The data readed by the poller is handled by nbio.Engine's data handler which is registered by nbio.Engine.OnData by default.
  3. This Conn's data handler is used to customize your implementation, you can set different data handler for different Conns, and call Conn's data handler in nbio.Engine's data handler. For example: engine.OnData(func(c *nbio.Conn, data byte){ c.DataHandler()(c, data) }) conn1.OnData(yourDatahandler1) conn2.OnData(yourDatahandler2)

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.1

ReadAndGetConn handles reading for different types of connection. It returns the real connection:

  1. For Non-UDP connection, it returns the Conn itself.
  2. For UDP connection, it may be a UDP Server fd, then it returns consistent Conn for the same socket which has the same local addr and remote addr.

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:

  1. Users should update the read deadline in time.
  2. For example, call SetReadDeadline whenever a new WebSocket message is received.
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:

  1. This is a non-blocking interface, but you can use it as you use std.
  2. When it can't write all the data now, the connection will cache the data left to be written and wait for the writing event then try to flush it.

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