func (t *Instance) get(arg *getArgs) error { if arg.size > MaxGetBenchSize { return ErrBenchSizeTooLarge.Trace(arg.size) } msgs := make([]*mmq.Message, arg.size) var ( msg *mmq.Message err error ) var header mmq.HeaderBin // check offset r := &utils.Reader{t.file, arg.offset} p := 0 for i := 0; i < arg.size; i++ { msg, err = mmq.ReadMessage(&header, r, mmq.RF_RESEEK_ON_FAULT) err = logex.Trace(err, i) if logex.EqualAny(err, ErrNeedAddToWaiter) { // not finish, add to waiterList t.addWaiter(arg, r.Offset, p) break } if err != nil { break } msgs[p] = msg p++ } arg.reply <- msgs[:p] return err }
func pubHandler(w http.ResponseWriter, req *http.Request) { name := req.FormValue("topic") if name == "" { http.Error(w, "missing topic", 403) return } size, err := strconv.Atoi(req.FormValue("size")) if err != nil { http.Error(w, err.Error(), 403) return } var ( msg *mmq.Message header mmq.HeaderBin msgs = make([]*mmq.Message, 0, size) ) for !logex.Equal(err, io.EOF) { msg, err = mmq.ReadMessage(&header, req.Body, mmq.RF_DEFAULT) if err != nil { break } msgs = append(msgs, msg) } t, err := getTopic(name) if err != nil { http.Error(w, err.Error(), 500) return } t.PutSync(msgs) w.Write([]byte("hello")) }