func (app *App) handleConn(conn net.Conn) { atomic.AddInt64(&(app.totalConnections), 1) atomic.AddInt64(&(app.currConnections), 1) defer atomic.AddInt64(&(app.currConnections), -1) defer conn.Close() app.extendDeadline(conn) scanner := bufio.NewScanner(conn) for scanner.Scan() { app.extendDeadline(conn) cmd, err := app.BytesToCmd(scanner.Bytes()) if err != nil { if err := app.writeError(conn); err != nil { log.Warn("error on write error: %s", err) return } continue } err = cmd.Execute(app, conn) if err == io.EOF { return } else if err != nil { log.Warn("error on write to conn: %s", err) return } } }
func (app *App) writeError(conn net.Conn) (err error) { _, err = conn.Write(respError) if err != nil { log.Warn(err) } return }
func Warn(fields map[string]interface{}, msg string) { if fields == nil { jsonLog.Warn(msg) logrus.Warn(msg) } else { jsonLog.WithFields(fields).Warn(msg) logrus.WithFields(fields).Warn(msg) } }
// 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 }