Pure Go 1000k+ connections solution, support tls/http1.x/websocket and basically compatible with net/http, with high-performance and low memory cost, non-blocking, event-driven, easy-to-use.
conf:= nbio.Configstruct {
// Name describes your gopher name for logging, it's set to "NB" by defaultName: "NB",
// MaxLoad represents the max online num, it's set to 10k by defaultMaxLoad: 1024*10,
// NPoller represents poller goroutine num, it's set to runtime.NumCPU() by defaultNPoller: runtime.NumCPU(),
// ReadBufferSize represents buffer size for reading, it's set to 16k by defaultReadBufferSize: 1024*16,
// MaxWriteBufferSize represents max write buffer size for Conn, it's set to 1m by default.// if the connection's Send-Q is full and the data cached by nbio is // more than MaxWriteBufferSize, the connection would be closed by nbio.MaxWriteBufferSizeuint32// LockListener represents listener's goroutine to lock thread or not, it's set to false by default.LockListenerbool// LockPoller represents poller's goroutine to lock thread or not.LockPollerbool
}
g.OnWriteBufferFree(func(c*Conn, b []byte) {
// ...
})
Handle Conn Before Read
// BeforeRead registers callback before syscall.Read// the handler would be called only on windowsg.OnData(func(c*Conn, data []byte) {
c.SetReadDeadline(time.Now().Add(time.Second*30))
})
Handle Conn After Read
// AfterRead registers callback after syscall.Read// the handler would be called only on *nixg.BeforeRead(func(c*Conn) {
c.SetReadDeadline(time.Now().Add(time.Second*30))
})
Handle Conn Before Write
g.OnData(func(c*Conn, data []byte) {
c.SetWriteDeadline(time.Now().Add(time.Second*5))
})
Pure Go 1000k+ connections solution, support tls/http1.x/websocket and basically compatible with net/http, with high-performance and low memory cost, non-blocking, event-driven, easy-to-use.