예제 #1
0
파일: server.go 프로젝트: kij/gocode
func (self *ACRServer) Loop() {
	conn_in := make(chan net.Conn)
	go acceptConnections(conn_in, self.listener)
	for {
		// handle connections or server CMDs (currently one CMD)
		select {
		case c := <-conn_in:
			rpc.ServeConn(c)
			runtime.GC()
		case cmd := <-self.cmd_in:
			switch cmd {
			case ACR_CLOSE:
				return
			}
		case sig := <-signal.Incoming:
			usig, ok := sig.(signal.UnixSignal)
			if !ok {
				break
			}
			if usig == signal.SIGINT || usig == signal.SIGTERM {
				return
			}
		}
	}
}
예제 #2
0
func test_rpc() {
	fmt.Println("Testing rpc with TimeService...")
	cli, srv := net.Pipe()
	go rpc.ServeConn(srv)

	client := rpc.NewClient(cli)
	defer client.Close()

	// Synchronous calls
	args := &Args{"GMT"}
	reply := new(Reply)
	for i := 0; i < 10; i++ {
		err := client.Call("TimeService.GetTime", args, reply)
		if err != nil {
			fmt.Errorf("TimeService.GetTime: expected no error but got string %q", err.String())
		}

		fmt.Printf("time:%s\n rpc.counter:%d\n", reply.Time, reply.Counter)
	}
}
예제 #3
0
파일: server.go 프로젝트: swcai/gocode
func (s *Server) Loop() {
	conn_in := make(chan net.Conn)
	go acceptConnections(conn_in, s.listener)
	for {
		// handle connections or server CMDs (currently one CMD)
		select {
		case c := <-conn_in:
			rpc.ServeConn(c)
			runtime.GC()
		case cmd := <-s.cmd_in:
			switch cmd {
			case SERVER_CLOSE:
				return
			}
		case sig := <-signal.Incoming:
			if IsTerminationSignal(sig) {
				return
			}
		}
	}
}
예제 #4
0
func main() {
	flag.Parse()
	if *logFile == "stderr" {
		log.SetOutput(os.Stderr)
	} else {
		logger, err := os.Open(*logFile, os.O_WRONLY|os.O_CREATE, 0640)
		if err != nil {
			log.SetOutput(os.Stderr)
			log.Exit(err)
		}
		log.SetOutput(logger)
	}

	if *displayHelp {
		flag.PrintDefaults()
		return
	}
	userMap = make(map[string]*Auth)
	err := loadUsersFromFile()
	if err != nil {
		log.Exit("Error reading config file. Have you created it?\nCaused By: ", err)
	}

	var t *LunchTracker

	if *dataFile != "" {
		stat, err := os.Stat(*dataFile)
		if err != nil {
			panic(err)
		}

		if stat.IsRegular() {
			file, ferr := os.Open(*dataFile, os.O_RDONLY, 0600)
			if ferr != nil {
				panic(ferr)
			}
			t = oldPollChan(file)
		}
	} else {
		t = newPollChan()
	}
	*dataFile = "poll.gob"

	rpc.Register(t)
	l, e := net.Listen("tcp", ":"+strconv.Uitoa(*port))
	if e != nil {
		log.Exit("listen error:", e)
	}
	for {
		conn, err := l.Accept()
		if err != nil {
			log.Println("Failed to accept client", err)
		} else {
			go func() {
				defer func() {
					if x := recover(); x != nil {
						log.Println("Fatal Exception", x)
					}
				}()
				rpc.ServeConn(conn)
			}()
		}
	}
}