Exemple #1
0
func processClientConnection(ctx context.Context, s *wsock.Server) {
	var clients ClientSlice
	addCh, delCh, doneCh, _ := s.GetChannels()
	log.Println("Get server channels", addCh, delCh, doneCh)

Loop:
	for {
		select {
		case <-doneCh:
			log.Println("doneCh got message")
			break Loop
		case <-ctx.Done():
			log.Println("Context destroyed")
			break Loop
		case cli := <-addCh:
			log.Println("processClientConnection got add client notification", cli)
			//			go clientProcessor(cli)
			clients = append(clients, cli)
			_, toWS, _ := cli.GetChannels()
			if isCurrent {
				c := wsock.MessageT{}
				c["msg"] = currentConfig.config
				toWS <- &c
			}
			break
		case cli := <-delCh:
			log.Println("delCh got client", cli)
			for i, v := range clients {
				if v == cli {
					clients = append(clients[:i], clients[i+1:]...)
					log.Println("Removed client", cli)
				}
			}
			break
		case msg := <-ctx.Value("stateUpdateChannel").(chan *bson.M):
			out := wsock.MessageT{}
			out["state"] = msg
			for _, v := range clients {
				_, toWS, _ := v.GetChannels()
				toWS <- &out
			}
		}
	}
	log.Println("processClientConnection exited")
}
Exemple #2
0
func processClientConnection(ctx context.Context, s *wsock.Server) {
	var (
		clients ClientSlice
	)
	addCh, delCh, doneCh, _ := s.GetChannels()
	log.Println("Get server channels", addCh, delCh, doneCh)

Loop:
	for {
		select {
		case <-doneCh:
			log.Println("doneCh got message")
			break Loop
		case <-ctx.Done():
			log.Println("Context destroyed")
			break Loop
		case cli := <-addCh:
			log.Println("processClientConnection got add client notification", cli)
			clientContext := context.WithValue(ctx, "client", cli)
			go handleClient(clientContext)
			break
		case cli := <-delCh:
			log.Println("delCh got client", cli)
			for i, v := range clients {
				if v.client == cli {
					clients = append(clients[:i], clients[i+1:]...)
					log.Println("Removed client", cli)
				}
			}
			break
			/*		case msg := <-ctx.Value("stateUpdateChannel").(chan *bson.M):
					out := wsock.MessageT{}
					out["state"] = msg
					for _, v := range clients {
						_, toWS, _ := v.client.GetChannels()
						toWS <- &out
					}
			*/
		}
	}
	log.Println("processClientConnection exited")
}
func processClientConnection(s *wsock.Server, props property.PropSet) {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	log.Println("Enter processClientConnection")
	addCh, delCh, doneCh, _ := s.GetChannels()
	log.Println("Get server channels", addCh, delCh, doneCh)
Loop:
	for {
		select {
		case <-doneCh:
			log.Println("doneCh got message")
			break Loop
		case <-ctx.Done():
			log.Println("Context destroyed")
			break Loop
		case cli := <-addCh:
			log.Println("processClientConnection got add client notification", cli.Request().FormValue("id"))
			streamName := cli.Conn().Request().FormValue("stream")
			if streamName == "" {
				streamName = props["mongodb.stream"]
			}
			ctx, cancel := context.WithCancel(context.Background())
			defer cancel()
			log.Println("Stream name", streamName)
			evStore, err := evstore.Dial(props["mongodb.url"], props["mongodb.db"], streamName)
			defer evStore.Close()
			if err != nil {
				log.Fatalln("Error connecting to event store. ", err)
				return
			}
			go handleClientRequest(ctx, cli, evStore)
			break
		case cli := <-delCh:
			log.Println("delCh go client", cli)
			break
		}
	}
	log.Println("processClientConnection exited")
}
Exemple #4
0
func processClientConnection(s *wsock.Server, f *RPCFunction) {
	log.Println("Enter processClientConnection")
	addCh, delCh, doneCh, _ := s.GetChannels()
	log.Println("Get server channels", addCh, delCh, doneCh)
Loop:
	for {
		select {
		case cli := <-addCh:
			log.Println("processClientConnection got add client notification", cli.Request().FormValue("id"))
			ctx, cancel := context.WithCancel(context.Background())
			defer cancel()
			go clientHandler(ctx, cli, f)
			break
		case cli := <-delCh:
			log.Println("delCh go client", cli)
			break
		case <-doneCh:
			log.Println("doneCh got message")
			break Loop
		}
	}
	log.Println("processClientConnection exited")
}