當前位置: 首頁>>代碼示例>>Golang>>正文


Golang BuffPool.QueryForUuid方法代碼示例

本文整理匯總了Golang中push-server/buffpool.BuffPool.QueryForUuid方法的典型用法代碼示例。如果您正苦於以下問題:Golang BuffPool.QueryForUuid方法的具體用法?Golang BuffPool.QueryForUuid怎麽用?Golang BuffPool.QueryForUuid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在push-server/buffpool.BuffPool的用法示例。


在下文中一共展示了BuffPool.QueryForUuid方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: sendToClient2

func (this *DispatcherOutComponent) sendToClient2(msg *protocol.Message, forward bool, buffPool *buffpool.BuffPool) error {
	if msg == nil || buffPool == nil {
		err := errors.New("DispatcherOutComponent.sendToClient2() Error: invalid argument")
		fmt.Println(err.Error())
		return err
	}

	clientConnArr := make([]*model.Client, 0)
	if msg.Token > 0 {
		clientConn := buffPool.GetClient(msg.Number, msg.DestUuid, msg.DeviceId, msg.Token)
		if clientConn != nil && clientConn.Conn != nil {
			clientConnArr = append(clientConnArr, clientConn)
		}
		if (clientConnArr == nil || len(clientConnArr) <= 0) && forward && GetRunWithSnode().Flag {
			buf, err := msg.Encode()
			if err != nil {
				fmt.Println("DispatcherOutComponent.sendToClient2() Error: " + err.Error())
				fmt.Println("\n", time.Now().String(), "Not find user, not forward due to encode failed.", "\n")
				return err
			}
			snode_component.GetNodeComponent().Forward(stree_define.FORWARD, msg.DestUuid, msg.DeviceId, buf)
			return nil
		}
	} else if msg.Token == 0 && msg.DeviceId > 0 {
		clientConnArr = buffPool.QueryForDeviceId(msg.Number, msg.DestUuid, msg.DeviceId)
		if (clientConnArr == nil || len(clientConnArr) <= 0) && forward && GetRunWithSnode().Flag {
			buf, err := msg.Encode()
			if err != nil {
				fmt.Println("DispatcherOutComponent.sendToClient2() Error:" + err.Error())
				fmt.Println("\n", time.Now().String(), "Not find user, not forward due to encode failed.", "\n")
				return err
			}
			snode_component.GetNodeComponent().Forward(stree_define.FORWARD, msg.DestUuid, msg.DeviceId, buf)
			return nil
		}
	} else if msg.Token == 0 && msg.DeviceId == 0 {
		clientConnArr = buffPool.QueryForUuid(msg.Number, msg.DestUuid)
	}

	err := errors.New("DispatcherOutComponent.sendToClient2() Error: the client's connection not pass authorization yet")
	for _, client := range clientConnArr {
		if client == nil || client.Conn == nil {
			continue
		}
		if !this.checkConnActivity(client.Time, client, buffPool, msg.Number, msg.DestUuid, msg.DeviceId, msg.Token) {
			err := errors.New("DispatcherOutComponent.sendToClient2() Error: client's connection is not alive")
			fmt.Println(err.Error())
			continue
		}
		err2 := this.sendMessage(msg, client.Conn)
		if err2 != nil {
			err2 = errors.New("DispatcherOutComponent.sendToClient2() Error: can not send message to client's connection")
			fmt.Println(err.Error())
			continue
		}
	}
	return nil
}
開發者ID:huayuxian,項目名稱:im-server-go,代碼行數:58,代碼來源:dispatcher_out_component.go

示例2: sendToClient

func (this *DispatcherOutComponent) sendToClient(msg *protocol.Message, buffPool *buffpool.BuffPool) error {
	if msg == nil || buffPool == nil {
		err := errors.New("DispatcherOutComponent.sendToClient() Error: invalid argument")
		fmt.Println(err.Error())
		return err
	}
	clientConnArr := make([]*model.Client, 0)

	if msg.Token > 0 {
		clientConn := buffPool.GetClient(msg.Number, msg.DestUuid, msg.DeviceId, msg.Token)
		if clientConn != nil && clientConn.Conn != nil {
			clientConnArr = append(clientConnArr, clientConn)
		}
	} else if msg.Token == 0 && msg.DeviceId > 0 {
		clientConnArr = buffPool.QueryForDeviceId(msg.Number, msg.DestUuid, msg.DeviceId)
	} else if msg.Token == 0 && msg.DeviceId == 0 {
		clientConnArr = buffPool.QueryForUuid(msg.Number, msg.DestUuid)
	}

	if clientConnArr != nil && len(clientConnArr) <= 0 {
		err := errors.New("DispatcherOutComponent.sendToClient() Error: can not find client's connection")
		fmt.Println(err.Error())
		return err
	}

	err := errors.New("DispatcherOutComponent.sendToClient() Error: the client's connection not pass authorization yet")
	for _, client := range clientConnArr {
		if client == nil || client.Conn == nil {
			continue
		}

		if !this.checkConnActivity(client.Time, client, buffPool, msg.Number, msg.DestId, msg.DeviceId, msg.Token) {
			err := errors.New("DispatcherOutComponent.sendToClient() Error: client's connection is not alive")
			fmt.Println(err.Error())
			continue
		}

		err2 := this.sendMessage(msg, client.Conn)
		if err2 != nil {
			err2 = errors.New("DispatcherOutComponent.sendToClient() Error: can not send message to client's connection")
			fmt.Println(err.Error())
			continue
		}
	}

	return err
}
開發者ID:huayuxian,項目名稱:im-server-go,代碼行數:47,代碼來源:dispatcher_out_component.go


注:本文中的push-server/buffpool.BuffPool.QueryForUuid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。