Exemplo n.º 1
0
func onCliPacket(peerConn *zzcommon.PeerConn_t) (ret int) {
	gLock.Lock()
	defer gLock.Unlock()

	fmt.Println("onCliPacket")
	peerConn.ParseProtoHead()

	ret = onRecv(peerConn)
	return ret
}
Exemplo n.º 2
0
func onCliGetPacketLen(peerConn *zzcommon.PeerConn_t, packetLength int) (ret int) {
	//fmt.Println("onCliGetPacketLen")
	if uint32(packetLength) < zzcommon.ProtoHeadLength { //长度不足一个包头中的长度大小
		return 0
	}
	peerConn.ParseProtoHeadPacketLength()
	if uint32(peerConn.RecvProtoHead.PacketLength) < zzcommon.ProtoHeadLength {
		return zzcommon.ERROR_DISCONNECT_PEER
	}
	if gTcpServer.PacketLengthMax <= uint32(peerConn.RecvProtoHead.PacketLength) {
		return zzcommon.ERROR_DISCONNECT_PEER
	}
	if packetLength < int(peerConn.RecvProtoHead.PacketLength) {
		return 0
	}
	fmt.Println("onCliGetPacketLen:", peerConn.RecvProtoHead.PacketLength)
	return int(peerConn.RecvProtoHead.PacketLength)
}
Exemplo n.º 3
0
//获取消息的长度,0表示消息还未接受完成,
//ERROR_DISCONNECT_PEER表示长度有误,服务端断开
func onSerGetPacketLen(peerConn *zzcommon.PeerConn_t, packetLength int) (ret int) {
	if (uint32)(packetLength) < zzcommon.ProtoHeadLength { //长度不足一个包头中的长度大小
		return 0
	}
	peerConn.ParseProtoHead()
	if (uint32)(peerConn.RecvProtoHead.PacketLength) < zzcommon.ProtoHeadLength {
		return zzcommon.ERROR_DISCONNECT_PEER
	}
	fmt.Print(peerConn.RecvProtoHead)
	if gTcpServer.PacketLengthMax <= (uint32)(peerConn.RecvProtoHead.PacketLength) {
		return zzcommon.ERROR_DISCONNECT_PEER
	}
	if packetLength < int(peerConn.RecvProtoHead.PacketLength) {
		return 0
	}
	fmt.Println(peerConn)
	return int(peerConn.RecvProtoHead.PacketLength)
}