コード例 #1
0
ファイル: push-server.go プロジェクト: huayuxian/im-server-go
func main() {
	pusherServer := server.PushServer{}
	err := pusherServer.ReadConf("conf/push-server.conf")
	if err != nil {
		fmt.Println("PushServer Error:" + err.Error())
		return
	}
	runtime.GOMAXPROCS(pusherServer.GoMaxProcs)

	connect, err := pusherServer.Init()
	if err != nil {
		fmt.Println("PushServer Error:" + err.Error())
		return
	}

	err = pusherServer.Start(connect)
	if err != nil {
		fmt.Println("PushServer Error:" + err.Error())
		return
	}

	go func() {
		for {
			buffpool.GetBuffPool().PrintServiceConnections()
			buffpool.GetBuffPool().PrintClientConnections()
			buffpool.GetBuffPool().PrintTmpClientConnections()
			time.Sleep(5 * time.Second)
		}
	}()

	signal := make(chan bool, 0)
	<-signal
}
コード例 #2
0
func (this *CacheComponent) SendCached(destUuid string, deviceID uint32) error {

	this.CacheLock.RLock()
	defer this.CacheLock.RUnlock()

	if !this.CheckCached(destUuid, deviceID) {
		fmt.Println("\n", time.Now().String(), " CacheComponent.SendCached(), no cached messages ", "\n")
		return nil
	}

	dispatcherOut := GetDispatcherOutComponent()
	buffPool := buffpool.GetBuffPool()

	for e := this.Cache[destUuid].MDev[deviceID].List.Front(); e != nil; e = e.Next() {
		val, ok := e.Value.(CacheEntry)
		if !ok {
			continue
		}
		err := dispatcherOut.sendToClient(&val.Message, buffPool)
		if err != nil {
			fmt.Println("CacheComponent.SendCached() sendToClient Error: " + err.Error())
			return err
		}
	}
	return nil
}
コード例 #3
0
func (this *DispatcherComponent) process() {
	var responseComponent *ResponseComponent
	for {
		responseComponent = GetResponseComponent()
		if responseComponent != nil {
			break
		} else {
			fmt.Println("DispatcherComponent.Process() Error: can not get ResponComponent sigleton, will try again")
		}
	}

	var buffPool *buffpool.BuffPool
	for {
		buffPool = buffpool.GetBuffPool()
		if buffPool != nil {
			break
		}
	}

	for {
		packet := this.Pop()
		msg := packet.Message
		flag := packet.Flag
		this.dispatch(msg, flag, buffPool, responseComponent)
	}
}
コード例 #4
0
func (this *DispatcherOutComponent) handleKeepAlive(msg *protocol.Message) error {
	if msg == nil {
		err := errors.New("DispatcherOutComponent.handleKeepAlive() Error: invalid argument")
		fmt.Println(err.Error())
		return err
	}
	buffPool := buffpool.GetBuffPool()
	this.sendToClient(msg, buffPool)
	return nil
}
コード例 #5
0
func (this *DispatcherComponent) handleKeepAlive(msg *protocol.Message) error {
	if msg == nil {
		err := errors.New("DispatcherComponent.handleKeepAlive() Error: invalid argument")
		fmt.Println(err.Error())
		return err
	}
	buffPool := buffpool.GetBuffPool()
	err := buffPool.UpdateClientStatus(msg.Number, msg.UserUuid, msg.DeviceId, msg.Token, true)
	if err != nil {
		err = errors.New("DispatcherComponent.handleKeepAlive() Error: can not update client's connections status" + err.Error())
		fmt.Println(err.Error())
		return err
	}
	msg.PushType = protocol.PT_PUSHSERVER
	msg.UserUuid, msg.DestUuid = msg.DestUuid, msg.UserUuid
	GetDispatcherOutComponent().EPushBack(msg, false)
	return nil
}
コード例 #6
0
func (this *UnregisterComponent) Process() error {
	var buffPool *buffpool.BuffPool
	for {
		buffPool = buffpool.GetBuffPool()
		if buffPool != nil {
			break
		} else {
			fmt.Println("UnregisterComponent Process() Error:can not get BuffPool, will try again")
		}
	}
	for {
		msg := <-this.msgQueue
		if msg == nil {
			err := errors.New("UnregisterComponent Process() Error:received msg is nil, will try again")
			continue
		}
		if msg.MsgType != protocol.MT_UNREGISTER {
			err := errors.New("UnregisterComponent Process() Error:received non-MT_UNREGISTER message, will discard it and try again")
			continue
		}

		if msg.PushType == protocol.PT_SERVICE {
			err := this.unregisterService(buffPool, msg)
			if err != nil {
				err := errors.New("UnregisterComponent Process() Error: " + err.Error() + "; will handler next request")
				return err
			}
		} else if msg.PushType == protocol.PT_CLIENT {
			err := this.unregisterClient(buffPool, msg)
			if err != nil {
				err := errors.New("UnregisterComponent Process() Error, " + err.Error() + "; will handler next request")
				return err
			}
		}
	}
	return nil
}