Exemplo n.º 1
0
// Listen starts listen.
func (app *App) Listen(l net.Listener) error {
	log.Infof("Listening at %s", l.Addr().String())
	log.Infof("Worker ID = %d", app.gen.WorkerID)

	app.Listener = l
	app.ready = true

	for {
		conn, err := l.Accept()
		if err != nil {
			log.Warnf("Error on accept connection: %s", err)
			continue
		}
		log.Debugf("Connected by %s", conn.RemoteAddr().String())

		go app.handleConn(conn)
	}
}
Exemplo n.º 2
0
// Execute generates new ID.
func (cmd *MemdCmdGet) Execute(app *App, conn net.Conn) error {
	values := make([]string, len(cmd.Keys))
	for i, _ := range cmd.Keys {
		id, err := app.NextID()
		if err != nil {
			log.Warn(err)
			if err = app.writeError(conn); err != nil {
				log.Warn("error on write error: %s", err)
				return err
			}
			return nil
		}
		log.Debugf("Generated ID: %d", id)
		values[i] = strconv.FormatUint(id, 10)
	}
	_, err := MemdValue{
		Keys:   cmd.Keys,
		Flags:  0,
		Values: values,
	}.WriteTo(conn)
	return err
}