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


Golang BuffPool.GetClient方法代码示例

本文整理汇总了Golang中push-server/buffpool.BuffPool.GetClient方法的典型用法代码示例。如果您正苦于以下问题:Golang BuffPool.GetClient方法的具体用法?Golang BuffPool.GetClient怎么用?Golang BuffPool.GetClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在push-server/buffpool.BuffPool的用法示例。


在下文中一共展示了BuffPool.GetClient方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: handleMTRegister

func (this *DispatcherOutComponent) handleMTRegister(msg *protocol.Message, buffPool *buffpool.BuffPool, respComp *ResponseComponent) error {
	if msg.PushType == protocol.PT_PUSHSERVER {
		conn := buffPool.QueryService(msg.Number, msg.DestUuid)
		if conn == nil {
			clientConn := buffPool.GetClient(msg.Number, msg.DestUuid, msg.DeviceId, msg.Token)
			if clientConn == nil || clientConn.Conn == nil {
				err := errors.New("DispatcherOutComponent.handleMTRegister() Error: can not find the dest conn")
				fmt.Println(err.Error())
				return err
			}
			conn = clientConn.Conn
		}
		if conn == nil {
			err := errors.New("DispatcherOutComponent.handleMTRegister() Error: can not find the dest conn")
			fmt.Println(err.Error())
			return err
		}
		err := this.sendMessage(msg, conn)
		if err != nil {
			err = errors.New("DispatcherComponnet.handleMTRegister() Error: can not send message out, " + err.Error())
			fmt.Println(err.Error())
			return err
		}
	}
	return nil
}
开发者ID:huayuxian,项目名称:im-server-go,代码行数:26,代码来源:dispatcher_out_component.go

示例2: 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

示例3: unregisterClient

func (this *UnregisterComponent) unregisterClient(buffPool *buffpool.BuffPool, msg *protocol.Message) error {
	if buffPool == nil || msg == nil {
		err := errors.New("UnregisterComponent.unregisterClient() Error: invalid argument")
		fmt.Println(err.Error())
		return err
	}
	clientConn := buffPool.GetClient(msg.Number, msg.UserUuid, msg.DeviceId, msg.Token)
	if clientConn == nil {
		return nil
	}

	//only remove conn from connPool, but do not disconnect this connection
	err := buffPool.RemoveClient(msg.Number, msg.UserUuid, msg.DeviceId, msg.Token)
	(*clientConn.Conn).Close()
	if err != nil {
		err = errors.New("UnregisterComponent.unregisterClient() Error: " + err.Error())
		fmt.Println(err.Error())
		//send failed response to client
		resp, err2 := protocol.NewMessage(protocol.VERSION, protocol.MT_ERROR, protocol.PT_PUSHSERVER, msg.Token, msg.Number, uint16(0),
			P_UID, msg.UserUuid, msg.DeviceId, nil)
		if err2 != nil {
			err2 = errors.New("UnregisterComponent.unregisterClient() Error:" + err2.Error())
			fmt.Println(err2.Error())
			return err2
		}
		err3 := sendResponse(clientConn.Conn, resp)
		if err3 != nil {
			err3 = errors.New("UnregisterComponent.unregisterClient() Error:, " + err3.Error())
			fmt.Println(err3.Error())
			return err3
		}
		return err
	}

	//offline broadcast
	err = this.offlineBroadcast(buffPool, msg.UserUuid, msg.DeviceId)
	if err != nil {
		err = errors.New("UnregisterComponent.unregisterClient() Error: offlineBroadcast send failed, " + err.Error())
		fmt.Println(err.Error())
	}

	resp, err := protocol.NewMessage(protocol.VERSION, protocol.MT_UNREGISTER, protocol.PT_PUSHSERVER, msg.Token, msg.Number, uint16(0),
		P_UID, msg.UserUuid, msg.DeviceId, nil)
	if err != nil {
		err = errors.New("UnregisterComponent.unregisterClient() Error: conn is removed from BuffPool, but can not send response to service" + err.Error())
		fmt.Println(err.Error())
		return err
	}
	err2 := sendResponse(clientConn.Conn, resp)
	if err2 != nil {
		err2 = errors.New("UnregisterComponent.unregisterClient() Error:conn is reomved from BuffPool, but failed when send response to service" + err2.Error())
		return err2
	}
	return nil
}
开发者ID:huayuxian,项目名称:im-server-go,代码行数:55,代码来源:unregister_component.go

示例4: 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.GetClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。