代码拉取完成,页面将自动刷新
package net
import (
"gitee.com/dennis-kk/service-box-go/util/errors"
"github.com/panjf2000/gnet"
"net"
"sync/atomic"
)
const (
BoxConnClose = iota
BoxConnConnecting
)
//connection wrapper of gnet connection
type gnetConn struct {
state int32
conn gnet.Conn
}
func (c *gnetConn) LocalAddr() (addr net.Addr) {
if c.IsClose() {
return nil
}
return c.conn.LocalAddr()
}
func (c *gnetConn) RemoteAddr() (addr net.Addr) {
if c.IsClose() {
return nil
}
return c.conn.RemoteAddr()
}
func (c *gnetConn) Read(b []byte) (n int, err error) {
if c == nil {
return 0, errors.ChannelHasClosed
}
if c.IsClose() {
return 0, errors.ChannelHasClosed
}
length, buffer := c.conn.ReadN(len(b))
copy(b, buffer)
c.conn.ShiftN(length)
return length, nil
}
func (c *gnetConn) Write(buf []byte) error {
if c == nil || c.conn == nil {
return errors.ChannelHasClosed
}
if c.IsClose() {
return errors.ChannelHasClosed
}
return c.conn.AsyncWrite(buf)
}
func (c *gnetConn) Close() error {
return c.conn.Close()
}
func (c *gnetConn) IsClose() bool {
return atomic.LoadInt32(&c.state) == BoxConnClose
}
func (c *gnetConn) OnClose() {
atomic.StoreInt32(&c.state, BoxConnClose)
}
func makeGnetConn(v interface{}) IBoxConn {
if c, ok := v.(gnet.Conn); ok {
return &gnetConn{
state: BoxConnConnecting,
conn: c,
}
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。