本文整理匯總了Golang中roolet/coreprocessing.CoreInstruction.NeedExit方法的典型用法代碼示例。如果您正苦於以下問題:Golang CoreInstruction.NeedExit方法的具體用法?Golang CoreInstruction.NeedExit怎麽用?Golang CoreInstruction.NeedExit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類roolet/coreprocessing.CoreInstruction
的用法示例。
在下文中一共展示了CoreInstruction.NeedExit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: connectionWriteProcessing
// answer worker
func connectionWriteProcessing(
connection net.Conn,
backChannel *chan coreprocessing.CoreInstruction,
dataManager *connectionsupport.ConnectionDataManager,
stat statistic.StatisticUpdater,
label string) {
//
wait := true
msgSize := 0
var newInstruction coreprocessing.CoreInstruction
var statGroupName string
for wait {
newInstruction = <-*backChannel
if newInstruction.IsEmpty() {
rllogger.Outputf(rllogger.LogWarn, "Closed write process for %s empty instruction!", label)
wait = false
} else {
// write
msgSize = 0
if answer, exists := newInstruction.GetAnswer(); exists {
data := answer.DataDump()
if data != nil {
line := append(*data, byte('\n'))
if writen, err := connection.Write(line); err == nil {
msgSize += writen
} else {
rllogger.Outputf(rllogger.LogWarn, "Can't wite answer to %s: %s", label, err)
stat.AddOneMsg("lost_connection_count")
// wtf ?
wait = false
}
}
}
// and / or command for client
if answerCmd, exists := newInstruction.GetCommand(); exists && wait {
data := answerCmd.DataDump()
if data != nil {
line := append(*data, byte('\n'))
if writen, err := connection.Write(line); err == nil {
msgSize += writen
} else {
rllogger.Outputf(rllogger.LogWarn, "Can't wite answer to %s: %s", label, err)
stat.AddOneMsg("lost_connection_count")
// wtf ?
wait = false
}
}
}
if msgSize > 0 {
stat.SendMsg("outcome_data_size", msgSize)
// update state data
if newInstruction.StateChanges != nil {
// so simple.. without some visitor for statistic
if newInstruction.StateChanges.ChangeType == connectionsupport.StateChangesTypeGroup {
switch newInstruction.StateChanges.ConnectionClientGroup {
case connectionsupport.GroupConnectionClient:
statGroupName = "count_connection_client"
case connectionsupport.GroupConnectionServer:
statGroupName = "count_connection_server"
case connectionsupport.GroupConnectionWsClient:
statGroupName = "count_connection_web"
}
stat.AddOneMsg(statGroupName)
}
// update data in manager
dataManager.UpdateState(newInstruction.Cid, newInstruction.StateChanges)
}
} else {
rllogger.Outputf(rllogger.LogWarn, "Empty answer to %s?", label)
}
if newInstruction.NeedExit() {
wait = false
rllogger.Outputf(rllogger.LogDebug, "Closed write process for %s from instruction.", label)
err := connection.Close()
if err != nil {
// wait = true ??
rllogger.Outputf(rllogger.LogError, "Close connection %s problem: %s", label, err)
}
}
}
}
stat.DelOneMsg(statGroupName)
close(*backChannel)
}