示例#1
0
// log发送api
func wsLogHandle(conn *ws.Conn) {
	var err error
	defer func() {
		reporter.Printf("websocket log发送出错断开 (%v) !", err)
	}()

	Log.logChan = make(chan string, 1024)

	go func(conn *ws.Conn) {
		defer func() {
			close(Log.logChan)
			conn.Close()
		}()
		for {
			if err := ws.JSON.Receive(conn, nil); err != nil {
				reporter.Printf("websocket log接收出错断开 (%v) !", err)
				return
			}
		}
	}(conn)

	for msg := range Log.logChan {
		if _, err = ws.Message.Send(conn, msg); err != nil {
			return
		}
	}
}
示例#2
0
func wsHandle(conn *ws.Conn) {
	sess, _ := globalSessions.SessionStart(nil, conn.Request())
	sessID := sess.SessionID()
	if Sc.connPool[sessID] == nil {
		Sc.Add(sessID, conn)
	}

	defer Sc.Remove(sessID, conn)

	go func() {
		var err error
		for info := range Sc.wchanPool[sessID].wchan {
			if _, err = ws.JSON.Send(conn, info); err != nil {
				return
			}
		}
	}()

	for {
		var req map[string]interface{}

		if err := ws.JSON.Receive(conn, &req); err != nil {
			// logs.Log.Debug("websocket接收出错断开 (%v) !", err)
			return
		}

		// log.Log.Debug("Received from web: %v", req)
		wsApi[util.Atoa(req["operate"])](sessID, req)
	}
}
示例#3
0
func wsHandle(conn *ws.Conn) {
	defer func() {
		close(wchan)
		conn.Close()
	}()
	wchan = make(chan interface{}, 1024)

	go func(conn *ws.Conn) {
		var err error
		defer func() {
			reporter.Printf("websocket发送出错断开 (%v) !", err)
		}()
		for info := range wchan {
			if _, err = ws.JSON.Send(conn, info); err != nil {
				return
			}
		}
	}(conn)

	for {
		var req map[string]interface{}

		if err := ws.JSON.Receive(conn, &req); err != nil {
			reporter.Printf("websocket接收出错断开 (%v) !", err)
			return
		}

		reporter.Printf("Received from web: %v", req)
		wsApi[util.Atoa(req["operate"])](conn, req)
	}
}
示例#4
0
// log发送api
func wsLogHandle(conn *ws.Conn) {
	var err error
	defer func() {
		// reporter.Printf("websocket log发送出错断开 (%v) !", err)
	}()

	// 新建web前端log输出
	Log.Open()

	go func(conn *ws.Conn) {
		defer func() {
			// 关闭web前端log输出
			Log.Close()
			// 关闭websocket连接
			conn.Close()
		}()
		for {
			if err := ws.JSON.Receive(conn, nil); err != nil {
				// reporter.Printf("websocket log接收出错断开 (%v) !", err)
				return
			}
		}
	}(conn)

	for msg := range Log.logChan {
		if _, err = ws.Message.Send(conn, msg); err != nil {
			return
		}
	}
}
示例#5
0
// log发送api
func wsLogHandle(conn *ws.Conn) {
	var err error
	sess, _ := globalSessions.SessionStart(nil, conn.Request())
	sessID := sess.SessionID()
	if Lsc.connPool[sessID] == nil {
		Lsc.Add(sessID, conn)
	}
	go func() {
		defer func() {
			// 关闭web前端log输出并断开websocket连接
			Lsc.Remove(sessID, conn)
		}()
		for {
			if err := ws.JSON.Receive(conn, nil); err != nil {
				// logs.Log.Debug("websocket log接收出错断开 (%v) !", err)
				return
			}
		}
	}()

	for msg := range Lsc.lvPool[sessID].logChan {
		if _, err = ws.Message.Send(conn, msg); err != nil {
			return
		}
	}
}
示例#6
0
func wsHandle(conn *ws.Conn) {
	wchanClosed = false
	defer func() {
		// 连接断开前关闭正在运行的任务
		// if isRunning {
		// 	isRunning = false
		// 	logicApp.LogRest().Stop()
		// }
		wchanClosed = true
		close(wchan)
		conn.Close()
	}()
	wchan = make(chan interface{}, 1024)

	go func(conn *ws.Conn) {
		var err error
		for info := range wchan {
			if _, err = ws.JSON.Send(conn, info); err != nil {
				return
			}
		}
	}(conn)

	for {
		var req map[string]interface{}

		if err := ws.JSON.Receive(conn, &req); err != nil {
			// logs.Log.Debug("websocket接收出错断开 (%v) !", err)
			return
		}

		// log.Log.Debug("Received from web: %v", req)
		wsApi[util.Atoa(req["operate"])](conn, req)
	}
}
示例#7
0
func (self *LogSocketController) Remove(sessID string, conn *ws.Conn) {
	if self.connPool[sessID] == nil {
		return
	}
	lv := self.lvPool[sessID]
	lv.closed = true
	close(lv.logChan)
	conn.Close()
	delete(self.connPool, sessID)
	delete(self.lvPool, sessID)
}
示例#8
0
func (self *SocketController) Remove(sessID string, conn *ws.Conn) {
	self.rwMutex.Lock()
	defer self.rwMutex.Unlock()

	if self.connPool[sessID] == nil {
		return
	}
	wc := self.wchanPool[sessID]
	close(wc.wchan)
	conn.Close()
	delete(self.connPool, sessID)
	delete(self.wchanPool, sessID)
}