Ejemplo n.º 1
0
func (prod *Websocket) serve() {
	defer prod.WorkerDone()

	listen, err := shared.NewStopListener(prod.address)
	if err != nil {
		Log.Error.Print("Websocket: ", err)
		return // ### return, could not connect ###
	}

	config, err := websocket.NewConfig(prod.address, prod.path)
	if err != nil {
		Log.Error.Print("Websocket: ", err)
		return // ### return, could not connect ###
	}

	srv := http.Server{
		Handler: websocket.Server{
			Handler: prod.handleConnection,
			Config:  *config,
		},
		ReadTimeout: prod.readTimeoutSec,
	}

	prod.listen = listen

	err = srv.Serve(prod.listen)
	_, isStopRequest := err.(shared.StopRequestError)
	if err != nil && !isStopRequest {
		Log.Error.Print("Websocket: ", err)
	}
}
Ejemplo n.º 2
0
// Consume opens a new http server listen on specified ip and port (address)
func (cons Http) Consume(workers *sync.WaitGroup) {
	listen, err := shared.NewStopListener(cons.address)
	if err != nil {
		Log.Error.Print("Http: ", err)
		return // ### return, could not connect ###
	}

	cons.listen = listen
	cons.AddMainWorker(workers)

	go cons.serve()
	defer cons.listen.Close()

	cons.ControlLoop()
}