代码拉取完成,页面将自动刷新
package net
import (
"gitee.com/dennis-kk/service-box-go/util/slog"
"github.com/panjf2000/gnet"
)
// gnetConnector wrapper for network connector
// gnet client maybe not corss platform
type gnetConnector struct {
client *gnet.Client
}
//newBoxConnector create connector by loop
func makeConnector(v interface{}) IBoxConnector {
if gnetEH, ok := v.(*clientEH); ok {
bc := &gnetConnector{}
var err error
if bc.client, err = gnet.NewClient(gnetEH); err != nil {
slog.Error("[BoxNetwork] create sbox connector error %v !", err)
return nil
}
return bc
}
return nil
}
func (bc *gnetConnector) Start() error {
if bc == nil || bc.client == nil {
panic("[BoxNetwork] box network is invalid !")
}
return bc.client.Start()
}
// ConnectTo connect to remote server, this function will block current goroutine
func (bc *gnetConnector) ConnectTo(network, address string) (boxConn IBoxConn, err error) {
if bc == nil || bc.client == nil {
panic("[BoxNetwork] box network is invalid !")
}
// Dial function will not trigger OnOpened
conn, err := bc.client.Dial(network, address)
if err == nil {
//TODO manager connection
slog.Info("[BoxNetwork] connect to remote %s:%s successfully!", network, address)
boxConn = &gnetConn{
conn: conn,
state: BoxConnConnecting,
}
}
return
}
func (bc *gnetConnector) Stop() error {
if bc == nil || bc.client == nil {
return nil
}
return bc.client.Stop()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。