本文整理汇总了Golang中owl/common/tcp.Session类的典型用法代码示例。如果您正苦于以下问题:Golang Session类的具体用法?Golang Session怎么用?Golang Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Dial
//TODO(yingsong.wu):需要优化
func (this *Agent) Dial(Type string) {
var (
tempDelay time.Duration
err error
session *tcp.Session
)
retry:
switch Type {
case "cfc":
session, err = this.Connect(GlobalConfig.CFC_ADDR, nil)
case "repeater":
session, err = this.Connect(GlobalConfig.REPEATER_ADDR, nil)
default:
}
if err != nil {
lg.Error("%s: %s", Type, err.Error())
if tempDelay == 0 {
tempDelay = 5 * time.Millisecond
} else {
tempDelay *= 2
}
if max := 5 * time.Second; tempDelay > max {
tempDelay = max
}
time.Sleep(tempDelay)
goto retry
}
switch Type {
case "cfc":
this.cfc = session
this.Addr = session.LocalAddr()
case "repeater":
this.repeater = session
}
for {
switch Type {
case "cfc":
if this.cfc.IsClosed() {
goto retry
}
case "repeater":
if this.repeater.IsClosed() {
goto retry
}
}
time.Sleep(time.Second * 1)
}
}
示例2: Handle
//数据包逻辑处理
func (this *handle) Handle(sess *tcp.Session, data []byte) {
defer func() {
if r := recover(); r != nil {
lg.Error("Recovered in Handle", r)
}
}()
var err error
mt := types.MessageType(data[0])
lg.Info("receive %v %v", types.MessageTypeText[mt], string(data[1:]))
if proxy.cfc.IsClosed() {
return
}
switch mt {
case types.MESS_POST_METRIC, types.MESS_POST_HOST_CONFIG, types.MESS_POST_HOST_ALIVE:
proxy.cfc.Send(data)
case types.MESS_GET_HOST_PLUGIN_LIST:
proxy.cfc.Send(data)
host := types.Host{}
if err = host.Decode(data[1:]); err != nil {
lg.Error("decode host error ", err.Error())
return
}
if resp := proxy.PluginList.Get(host.ID); len(resp) > 0 {
sess.Send(
types.Pack(
types.MESS_GET_HOST_PLUGIN_LIST_RESP,
&types.GetPluginResp{host.ID, resp},
))
}
case types.MESS_GET_HOST_PLUGIN_LIST_RESP:
resp := types.GetPluginResp{}
if err = resp.Decode(data[1:]); err != nil {
lg.Error("decode plugin response error %s", err)
return
}
proxy.PluginList.Set(resp.HostID, resp.Plugins)
default:
lg.Error("Unknown Option: %v", mt)
}
}
示例3: LostSession
func (this *ControllerHandle) LostSession(sess *tcp.Session) {
lg.Info("%s disconnect ", sess.RemoteAddr())
}
示例4: MakeSession
func (this *ControllerHandle) MakeSession(sess *tcp.Session) {
lg.Info("%s new connection ", sess.RemoteAddr())
}
示例5: LostSession
func (this *InspectorHandle) LostSession(sess *tcp.Session) {
lg.Info("%s disconnect ", sess.RemoteAddr())
}