当前位置: 首页>>代码示例>>Golang>>正文


Golang gotools.Trace函数代码示例

本文整理汇总了Golang中github.com/sunminghong/gotools.Trace函数的典型用法代码示例。如果您正苦于以下问题:Golang Trace函数的具体用法?Golang Trace怎么用?Golang Trace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Trace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的github.com/sunminghong/gotools.Trace函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。