示例#1
0
func (this *Connection) serveWsHandle() {
	defer util.TraceCrashStackAndHandle(func() {
		this.Conn.Close()
	})
	logger.Info("Websocket handle looping tcp \n")

	defer this.Conn.Close()

	client := client.NewClient(this.Conn)

	//serve when connect
	go router.GetRouter().ConnHandler.Handle(client, this.FirstDataChan)

	//loop recv protocol
	for {
		select {
		case wp, _ := <-this.WsChan:
			//get handler
			logger.Info("handle module:%v command:%v data:%v \n", wp.Module, wp.Command, string(wp.Data))
			h := router.GetRouter().GetWsHandler()[wp.Module]
			if h != nil {
				c := h.Handle(client, string(wp.Data))
				if c != nil {
					client = c
				}
			}
		case data, ok := <-this.IpcChan:
			logger.Info("IPCHandler %v %v\r\n", data.Data, ok)
			h := router.GetRouter().GetIpcHandler()[data.ModuleId]
			if h != nil {
				c := h.Handle(client, data.CommandId, data.Data)
				if c != nil {
					client = c
				}
			}
			break
		case data, ok := <-this.ExitChan:
			logger.Info("ExitHandler %v %v\r\n", data, ok)
			router.GetRouter().GetDisconHandler().Handle(client)
			return
		}
	}

	fmt.Printf("ServeHandle ending \n")
}
示例#2
0
// into the handler
func (this *Connection) serveHandle() {
	logger.Info("TCPHandle looping tcp \n")
	defer this.Conn.Close()
	client := client.NewClient(this.Conn)

	defer util.TraceCrashStackAndHandle(func() {
		logger.Critial("serveHandle goroutine crash!\n")
		this.Conn.Close()
	})

	defer router.GetRouter().GetDisconHandler().Handle(client)

	//serve when connect
	go router.GetRouter().ConnHandler.Handle(client, this.FirstDataChan)

	//loop recv protocol
	for {
		select {
		case <-this.ExitChan:
			logger.Debug("Serve Handle Goroutine Exit !!! \r\n")
			router.GetRouter().GetDisconHandler().Handle(client)
			return
		case data, _ := <-this.TcpChan:
			logger.Debug("TCPHandler %v %v\r\n", data)
			h := router.GetRouter().GetTcpHandler()[data.ModuleId]
			if h != nil {
				c := h.Handle(client, &data)
				if c != nil {
					client = c
				}
			}
		case data, _ := <-this.IpcChan:
			logger.Info("IPCHandler %v %v\r\n", data.Data)
			h := router.GetRouter().GetIpcHandler()[data.ModuleId]
			if h != nil {
				c := h.Handle(client, data.CommandId, data.Data)
				if c != nil {
					client = c
				}
			}
		} // end select
	} //end for

}