本文整理汇总了Golang中github.com/sunminghong/gotools.Trace函数的典型用法代码示例。如果您正苦于以下问题:Golang Trace函数的具体用法?Golang Trace怎么用?Golang Trace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Trace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Connect
func (c *TcpConnection) Connect(addr string) bool {
gts.Trace("connect to tcpserver[info]:", addr)
conn, err := net.Dial("tcp", addr)
if err != nil {
print(err)
gts.Warn("net.Dial to %s:%q", addr, err)
return false
} else {
gts.Trace("tcp dial to %s is ok. ", addr)
}
//go func() {
//defer conn.Close()
c.conn = conn
//创建go的线程 使用Goroutine
go c.ConnSender()
go c.ConnReader()
//<-c.Quit
//}()
return true
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:25,代码来源:tcpconnection.go
示例2: SendRaw
func (wh *Wormhole) SendRaw(bytes []byte) {
if wh.closeded {
return
}
if len(bytes) <= 1024 {
//if len(bytes) < 0 {
gts.Trace("send send protocol type:%d,%d,%d", wh.GetGuin(), wh.sendConnection.GetType(), wh.sendConnection.GetProtocolType())
wh.sendConnection.Send(bytes)
} else {
//gts.Trace("send ctrl protocol type:",wh.ctrlConnection)
gts.Trace("send ctrl protocol type:%d,%d,%d", wh.GetGuin(), wh.ctrlConnection.GetType(), wh.ctrlConnection.GetProtocolType())
gts.Trace("send ctrl:%q", bytes)
//v := reflect.ValueOf(wh.ctrlConnection)
//t := reflect.TypeOf(wh.ctrlConnection)
//gts.Trace("Type:", t)
//gts.Trace("Value:", v)
//gts.Trace("Kind:", t.Kind())
//gts.Trace("Kind:", wh.ctrlConnection.GetId())
wh.ctrlConnection.Send(bytes)
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:26,代码来源:wormhole.go
示例3: ConnReader
func (c *TcpConnection) ConnReader() {
gts.Trace("read_buffer_size:", c.read_buffer_size)
buffer := make([]byte, c.read_buffer_size)
for {
bytesRead, err := c.conn.Read(buffer)
if err != nil {
gts.Error("tcpconnection connreader error: ", err, bytesRead)
if c.closeCallback != nil {
c.closeCallback(c.id)
}
break
}
//gts.Trace("tcpConnReader read to buff:%d, % X",bytesRead, buffer[:bytesRead])
gts.Trace("tcpConnReader read to buff:%q", buffer[:bytesRead])
c.Stream.Write(buffer[0:bytesRead])
gts.Trace("\n%q", c.Stream.Bytes())
c.receiveCallback(c)
//n, dps := c.routePack.Fetch(c)
//gts.Trace("fetch message number", n)
//if n > 0 {
//c.receivePacketCallback(c.id, dps)
//}
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:27,代码来源:tcpconnection.go
示例4: Close
func (c *TcpConnection) Close() {
gts.Trace("tcp connection close1")
if !c.closeded {
c.closeded = true
c.quit <- true
}
gts.Trace("tcp connection close2")
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:8,代码来源:tcpconnection.go
示例5: receiveBytes
func (s *TcpServer) receiveBytes(conn IConnection) {
gts.Trace("tcp server receiveBytes:% X", conn.GetBuffer().Stream.Bytes())
n, dps := s.RoutePackHandle.Fetch(conn.GetBuffer())
gts.Trace("tcp server receivePackets:", n)
if n > 0 {
s.receivePackets(conn, dps)
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:8,代码来源:tcpserver.go
示例6: ProcessPackets
func (aw *LogicToAgent) ProcessPackets(dps []*wormhole.RoutePacket) {
gts.Trace("logicToAgent processpackets receive %d route packets", len(dps))
for _, dp := range dps {
gts.Trace("%q", dp)
//gts.Trace("%q",gts.utils.ByteString(dp.Data))
aw.SendPacket(dp)
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:9,代码来源:logicserver.go
示例7: Close
func (c *UdpConnection) Close() {
gts.Trace("udp connection close1")
if !c.closeded {
c.closeded = true
c.quitInterval <- true
c.quitSender <- true
}
gts.Trace("udp connection close2")
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:9,代码来源:udpconnection.go
示例8: SetGroup
func (aw *LogicToAgentWormhole) SetGroup(group string) {
aw.group = group
gts.Trace("logic register to agent:group(%s)", group)
packet := &RoutePacket{
Type: EPACKET_TYPE_LOGIC_REGISTER,
Guin: 0,
Data: []byte(group),
}
gts.Trace("%q", packet)
aw.SendPacket(packet)
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:12,代码来源:logictoagentwormhole.go
示例9: Start
func (s *UdpServer) Start() {
udpAddr, err := net.ResolveUDPAddr("udp", s.Addr)
if err != nil {
gts.Error("udp server addr(%s) is error:%q", s.Addr, err)
return
}
gts.Info(s.Name + " udpserver is starting...")
sock, _err := net.ListenUDP("udp", udpAddr)
if _err != nil {
gts.Error("udp server addr(%s) is error2:%q", s.Addr, err)
return
}
go func() {
buffer := make([]byte, s.udp_read_buffer_size)
for {
defer sock.Close()
if s.Stop_ {
return
}
n, fromAddr, err := sock.ReadFromUDP(buffer)
key := fromAddr.String()
if err == nil {
//log.Println("recv", n, from)
gts.Trace("udp connect from: %s", fromAddr)
udpConn, ok := s.udpAddrs[key]
if !ok {
newcid := s.AllocId()
udpConn = s.makeConn(
newcid,
sock,
s.RoutePackHandle.GetEndianer(),
fromAddr,
)
gts.Trace("new udp connection")
udpConn.SetReceiveCallback(s.receiveUdpBytes)
s.udpAddrs[key] = udpConn
}
udpConn.ConnReader(buffer[0:n])
} else {
e, ok := err.(net.Error)
if !ok || !e.Timeout() {
gts.Trace("recv errorserver:%s,%q.", key, err.Error())
delete(s.udpAddrs, key)
}
}
}
}()
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:53,代码来源:udpserver.go
示例10: Unpack
func (uf *UdpFrame) Unpack(rw *gts.RWStream) bool {
data, num := rw.Read(3)
if num == 0 {
return false
}
uf.OrderNo = int(rw.Endianer.Uint16(data[:2]))
uf.Flag = data[2]
uf.Count = 0
switch uf.Flag {
case UDPFRAME_FLAG_DATA:
if rw.Len() < 2 {
rw.SetPos(-3)
gts.Trace("setpos:-3")
return false
}
buf, n := rw.Read(2)
if n < 2 {
return false
}
length := rw.Endianer.Uint16(buf)
leng := int(length)
//length,err := rw.ReadUint16()
gts.Trace("udpframe.unpack:%d", leng)
//if err != nil || rw.Len() < int(leng) {
if rw.Len() < int(leng) {
rw.SetPos(-5)
gts.Trace("setpos:-5, %d", leng)
return false
}
data, _ := rw.Read(int(leng))
uf.Data = make([]byte, leng)
copy(uf.Data, data)
/*
uf.Buf = make([]byte, leng + 5)
copy(uf.Buf, data)
copy(uf.Buf[3:], buf)
copy(uf.Buf[5:], uf.Data)
*/
return true
case UDPFRAME_FLAG_DATA_GROUP:
return false
default:
return true
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:52,代码来源:udpconnection.go
示例11: receiveBytes
func (c *UdpConnection) receiveBytes(frame *UdpFrame) {
if frame.OrderNo%UDP_SEND_ACT_COUNT == 0 {
c.sendFrame(&UdpFrame{
OrderNo: frame.OrderNo,
Flag: UDPFRAME_FLAG_ACT,
})
gts.Trace("c.lastValidOrderNo:%d", c.lastValidOrderNo)
gts.Trace("c.lastOrderNo:%d", c.lastOrderNo)
gts.Trace("c.reqCache:%d,%d", frame.OrderNo, UDPFRAME_FLAG_ACT)
}
println("receivebytes:", frame.OrderNo, "\n")
c.Stream.Write(frame.Data)
c.receiveCallback(c)
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:15,代码来源:udpconnection.go
示例12: Dispatch
func (r *Dispatcher) Dispatch(dp *RoutePacket) (wh IWormhole) {
r.dlock.Lock()
defer r.dlock.Unlock()
var code, group int
if len(dp.Data) > 2 {
code = int(r.routepack.GetEndianer().Uint16(dp.Data))
group = int(code / 100)
gts.Trace("msg.group:", group)
} else {
group = 0
}
hands, ok := r.handlers[group]
if !ok {
hands, ok = r.handlers[0]
if !ok {
hands = []IWormhole{}
}
}
hlen := len(hands)
if hlen == 1 {
return hands[0]
} else if hlen > 1 {
return hands[int(dp.Guin)%hlen]
} else {
gts.Warn("data packet group is not exists!", code, group)
return nil
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:31,代码来源:logicdispatcher.go
示例13: reader
func (c *UdpConnection) reader() {
for {
<-c.receiveChan
for {
frame := &UdpFrame{}
if frame.Unpack(c.udpStream) {
//gts.Trace("%d,%d,%q", frame.OrderNo, frame.Flag, frame.Data)
//gts.Trace("////////////////////////////////////")
switch frame.Flag {
case UDPFRAME_FLAG_ACT:
//收到包确认frame,将相应的sendcache 删除
for i := frame.OrderNo; i > 1; i-- {
if _, ok := c.sendCache.Get(i); ok {
c.sendCache.Delete(i)
} else {
break
}
}
gts.Trace("-------------%d--------------", c.sendCache.Length())
case UDPFRAME_FLAG_REQ_RETRY:
gts.Trace("----------recv req:%d------------", frame.OrderNo)
if rframe, ok := c.sendCache.Get(frame.OrderNo); ok {
c.sendFrame(rframe.(*UdpFrame))
} else {
c.sendFrame(&UdpFrame{
OrderNo: frame.OrderNo,
Flag: UDPFRAME_FLAG_NOT_EXISTS,
})
}
case UDPFRAME_FLAG_NOT_EXISTS:
//如果该包丢失,就当接受到一个正常frame处理
frame.Data = []byte{}
c.recvFrame(frame)
default:
c.recvFrame(frame)
}
} else {
break
}
}
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:47,代码来源:udpconnection.go
示例14: dataClosed
func (wh *Wormhole) dataClosed(id int) {
gts.Trace("dataClosed")
if wh.sendConnection == nil {
//wh.dataConnection.GetType() == wh.sendConnection.GetType() {
wh.sendConnection = wh.ctrlConnection
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:8,代码来源:wormhole.go
示例15: Connect
func (c *UdpConnection) Connect(addr string) bool {
udpAddr, err := net.ResolveUDPAddr("udp", addr)
if err != nil {
gts.Error("dial udp server addr(%s) is error:%q", udpAddr, err)
return false
}
conn, err := net.DialUDP("udp", nil, udpAddr)
if err != nil {
gts.Warn("net.Dial to %s:%q", addr, err)
return false
}
gts.Trace("dial to udp(%s) is ok.", addr)
c.conn = conn
go func() {
go func() {
buffer := make([]byte, 1024)
for {
defer conn.Close()
if c.closeded {
return
}
n, err := conn.Read(buffer[0:])
if err == nil {
c.ConnReader(buffer[0:n])
} else {
e, ok := err.(net.Error)
if !ok || !e.Timeout() {
gts.Trace("recv errorconn:%q.", err.Error())
c.quitConnect <- true
return
}
}
}
}()
go c.ConnSenderClient()
<-c.quitConnect
}()
return true
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:46,代码来源:udpconnection.go
示例16: receiveTcpPackets
func (c *Client) receiveTcpPackets(conn IConnection, dps []*RoutePacket) {
for _, dp := range dps {
if dp.Type == EPACKET_TYPE_HELLO {
gts.Trace("client receive tcp hello:%q", dp)
c.guin = dp.Guin
c.initWormhole(dp, conn)
fromType := EWormholeType(dp.Data[0])
c.wormhole.SetFromType(fromType)
c.wormhole.Init()
if len(dp.Data) > 1 {
c.udpAddr = string(dp.Data[1:])
}
//} else if dp.Type == EPACKET_TYPE_UDP_SERVER {
//c.guin = dp.Guin
//c.udpAddr = string(dp.Data)
//连接udp server
c.udpConn = NewUdpConnection(1,nil,c.routepack.GetEndianer(),nil)
if len(c.udpAddr) > 0 {
gts.Trace("client send udp hello:(%s), wormtype:(%d).", c.udpAddr, c.wormType)
if c.udpConn.Connect(c.udpAddr) {
//hello to tcp server
packet := &RoutePacket {
Type: EPACKET_TYPE_HELLO,
Guin: c.guin,
Data: []byte{byte(c.wormType)},
}
c.udpConn.Send(c.routepack.Pack(packet))
c.initWormhole(dp, c.udpConn)
print("\n-----------------------------------------------------------\n")
} else {
gts.Warn("dial to udp server lost:%s", c.udpAddr)
}
}
}
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:44,代码来源:client.go
示例17: Start
func (s *TcpServer) Start() {
gts.Info(s.Name + " tcpserver is starting...")
s.Stop_ = false
//todo: MaxConns don't proccess
netListen, error := net.Listen("tcp", s.Addr)
if error != nil {
gts.Error(error)
return
}
gts.Info("listen with :", s.Addr)
gts.Info(s.Name + " tcpserver is started !!!")
go func() {
//defer函数退出时执行
defer netListen.Close()
for {
gts.Trace("Waiting for connection")
if s.Stop_ {
break
}
connection, err := netListen.Accept()
if err != nil {
gts.Error("Transport error: ", err)
} else {
gts.Debug("%v is connection!", connection.RemoteAddr())
newcid := s.AllocId()
if newcid == 0 {
gts.Warn("connection num is more than ", s.MaxConns)
} else {
gts.Trace("//////////////////////newcid:", newcid)
tcpConn := s.makeConn(newcid, connection,
s.RoutePackHandle.GetEndianer())
tcpConn.SetReceiveCallback(s.receiveBytes)
}
}
}
}()
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:44,代码来源:tcpserver.go
示例18: ProcessPackets
func (acw *AgentToClientWormhole) ProcessPackets(dps []*RoutePacket) {
gts.Trace("agenttoclientwormhole processpackets receive %d packets", len(dps))
for _, dp := range dps {
gts.Debug("%q", dp)
gts.Trace("guin:", acw.GetGuin())
dp.Guin = acw.GetGuin()
dp.Type = dp.Type | 1
acw.SendPacket(dp)
//转发给logic server
//根据guin进行hash运算非配到相应的logic server
if server, ok := acw.GetManager().GetServer().(*Agent); ok {
server.LogicWormholes.(*LogicManager).Delay(dp)
}
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:19,代码来源:agenttoclientwormhole.go
示例19: addReq
func (c *UdpConnection) addReq(rate int) {
rate = 1
gts.Trace("addreq:::%d", c.lastOrderNo)
c.reqCache.Set(c.lastOrderNo, &UdpFrame{
OrderNo: c.lastOrderNo,
//Data: make([]byte),
Flag: UDPFRAME_FLAG_REQ_RETRY,
Count: UDP_REQ_CHECK_COUNT * rate,
})
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:10,代码来源:udpconnection.go
示例20: receiveUdpPackets
func (s *UdpServer) receiveUdpPackets(conn IConnection, dps []*RoutePacket) {
for _, dp := range dps {
if dp.Type == EPACKET_TYPE_HELLO {
gts.Trace("server receive udp hello:%q", dp)
//接到连接方hello包
var guin int
var wh IWormhole
var ok bool
if dp.Guin > 0 {
//TODO:重连处理
//如果客户端hello是发送的guin有,则表示是重连,需要处理重连逻辑
//比如在一定时间内可以重新连接会原有wormhole
guin = dp.Guin
if wh, ok = s.Wormholes.Get(guin); ok {
if wh.GetState() == ECONN_STATE_SUSPEND {
wh.SetState(ECONN_STATE_ACTIVE)
} else if wh.GetState() == ECONN_STATE_DISCONNTCT {
wh = nil
}
}
} else {
guin = GenerateGuin(s.ServerId, int(conn.GetId()))
}
if wh == nil {
wh = s.makeWormhole(guin, s.Wormholes, s.RoutePackHandle)
s.Wormholes.Add(wh)
}
//将该连接绑定到wormhole,
//并且connection的receivebytes将被wormhole接管
//该函数将不会被该connection调用
wh.AddConnection(conn, ECONN_TYPE_DATA)
gts.Trace("has wormholes:%d\n-----------------------------------", s.Wormholes.Length())
fromType := EWormholeType(dp.Data[0])
wh.SetFromType(fromType)
break
}
}
}
开发者ID:sunminghong,项目名称:wormhole,代码行数:42,代码来源:udpserver.go
注:本文中的github.com/sunminghong/gotools.Trace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论