4 Star 5 Fork 4

Plato/Service-Box-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
connector_linux.go 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
CloudGuan 提交于 2022-11-15 14:20 . bug: linux connector 状态错误
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()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dennis-kk/service-box-go.git
git@gitee.com:dennis-kk/service-box-go.git
dennis-kk
service-box-go
Service-Box-go
v0.4.14

搜索帮助