Ejemplo n.º 1
0
func GetServer(serverClass string, serverAddress string) (iface.IServer, error) {
	listener, err := net.Listen("tcp", serverAddress)
	if err != nil {
		return nil, err
	}
	if serverClass == SIMPLE_SERVER {
		log.Info("Listening at %s", serverAddress)
		return NewSimpleServer(listener), nil
	}
	return nil, errors.New("Invalid server class!")
}
Ejemplo n.º 2
0
// Connection dispatcher. Entry point to start connection handling.
func (s *SessionHandler) DispatchConn() {
	go s.quitListenter()
	addr := s.conn.RemoteAddr().String()
	log.Info("Client connected: %s", addr)
	s.writeResponse(common.NewStrResponse("HELLO FIREMPQ-0.1"))
	for s.active {
		cmdTokens, err := s.tokenizer.ReadTokens(s.conn)
		if err == nil {
			err = s.processCmdTokens(cmdTokens)
		}
		if err != nil {
			errTxt := err.Error()
			if err != io.EOF && !(strings.Index(errTxt, "use of closed") > 0) {
				log.Error(errTxt)
			}
			break
		}
	}
	log.Debug("Client disconnected: %s", addr)
}
Ejemplo n.º 3
0
func (this *CommandServer) Stop() {
	log.Notice("Server has been told to stop.")
	log.Info("Disconnection all clients...")
	this.listener.Close()
	close(this.quitChan)
}
Ejemplo n.º 4
0
func (this *CommandServer) Shutdown() {
	this.waitGroup.Wait()
	log.Info("Closing database...")
	this.facade.Close()
	log.Info("Server stopped.")
}