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


Golang BuffPool.RemoveClient方法代碼示例

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


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

示例1: checkConnActivity

func (this *DispatcherOutComponent) checkConnActivity(Time time.Time, client *model.Client, buffPool *buffpool.BuffPool, number uint16, userUuid string, devID uint32, token uint8) bool {
	//5分鍾
	if time.Now().Sub(Time) > define.KEEP_ALIVE_PEORID {
		if client.Conn != nil {
			(*client.Conn).Close()
		}
		if token > 0 {
			err := buffPool.RemoveClient(number, userUuid, devID, token)
			if err != nil {
				err = errors.New("DispatcherComponent.checkConnActivity() Error:can not remove invalid client's connection, " + err.Error())
				fmt.Println(err.Error())
				return false
			}
			clientArr := buffPool.QueryForDeviceId(number, userUuid, devID)
			if clientArr == nil || len(clientArr) == 0 {
				//offline broadcast
				unregister := GetUnregisterComponent()
				if unregister != nil {
					err2 := unregister.offlineBroadcast(buffPool, userUuid, devID)
					if err2 != nil {
						err2 = errors.New("cDispatcherComponent.checkConnActivity() Error: " + err2.Error())
						fmt.Println(err2.Error())
					}
				} else {
					fmt.Println("DispatcherComponent.checkConnActivity() Error: one client disconnected, but offline broadcast send failed, ")
				}
			}

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

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

示例3: listenClient

func (this *RegisterComponent) listenClient(conn *net.Conn, buffPool *buffpool.BuffPool, number uint16, userUuid string, deviceID uint32, token uint8) error {
	if buffPool == nil {
		err := errors.New("RegisterComponent listenClient() Error: invalid argument")
		fmt.Println(err.Error())
		return err
	}
	if conn == nil {
		err := errors.New("RegisterComponent listenClient() Error:invalid argument")
		fmt.Println(err.Error())
		fmt.Println("the invalid client connection will be removed")
		err2 := buffPool.RemoveClient(number, userUuid, deviceID, token)
		if err2 != nil {
			err2 = errors.New("RegisterComponent listenClient() Error:remove the invalid client's connection failed" + err2.Error())
			fmt.Println(err2.Error())
			return err2
		}
		fmt.Println("the invalid client connection has been removed")
		return err
	}
	var dispatcher *DispatcherComponent
	for {
		dispatcher = GetDispatcherComponent()
		if dispatcher != nil {
			break
		} else {
			fmt.Println("RegisterComponent listenClient() Error:can not get DispatcherComponent, will try again")
		}
	}

	for {
		msg, err := this.readMessage(conn)
		if err != nil && err != io.EOF && conn != nil {
			err = errors.New("RegisterComponent listenClient() Error " + err.Error())
			fmt.Println(err.Error())
			continue
		} else if err != nil && (err == io.EOF || conn == nil) {
			err = errors.New("RegisterComponent listenClient() Error the connection is invalid, " + err.Error())
			err2 := buffPool.RemoveClient(number, userUuid, deviceID, token)
			if conn != nil {
				(*conn).Close()
			}
			if err2 != nil {
				err2 = errors.New("RegisterComponent listenClient() Error: can not remove invalid client's connection, " + err2.Error())
				fmt.Println(err2.Error())
				return err2
			}
			clientArr := buffPool.QueryForDeviceId(number, userUuid, deviceID)
			if clientArr == nil || len(clientArr) == 0 {
				//offline broadcast
				unregister := GetUnregisterComponent()
				if unregister != nil {
					err3 := unregister.offlineBroadcast(buffPool, userUuid, deviceID)
					if err3 != nil {
						err3 = errors.New("RegisterComponent listenClient() Error:one client disconnected but offlineBroadcast send failed, " + err3.Error())
						fmt.Println(err3.Error())
					}
				} else {
					fmt.Println("RegisterComponent listenClient() Error:one client disconnected but offlineBroadcast send failed")
				}
			}

			return err
		}
		//push to DispatcherQueue
		if msg == nil {
			continue
		}
		dispatcher.NPushBack(msg, true) //need forward
	}
	return nil
}
開發者ID:huayuxian,項目名稱:im-server-go,代碼行數:71,代碼來源:register_component.go


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