MCPcopy
hub / github.com/bradfitz/gomemcache / parseGetResponse

Function parseGetResponse

memcache/memcache.go:517–548  ·  view source on GitHub ↗

parseGetResponse reads a GET response from r and calls cb for each read and allocated Item

(r *bufio.Reader, conn *conn, cb func(*Item))

Source from the content-addressed store, hash-verified

515// parseGetResponse reads a GET response from r and calls cb for each
516// read and allocated Item
517func parseGetResponse(r *bufio.Reader, conn *conn, cb func(*Item)) error {
518 for {
519 // extend deadline before each additional call, otherwise all cumulative
520 // calls use the same overall deadline
521 conn.extendDeadline()
522
523 line, err := r.ReadSlice('\n')
524 if err != nil {
525 return err
526 }
527 if bytes.Equal(line, resultEnd) {
528 return nil
529 }
530 it := new(Item)
531 size, err := scanGetResponseLine(line, it)
532 if err != nil {
533 return err
534 }
535 it.Value = make([]byte, size+2)
536 _, err = io.ReadFull(r, it.Value)
537 if err != nil {
538 it.Value = nil
539 return err
540 }
541 if !bytes.HasSuffix(it.Value, crlf) {
542 it.Value = nil
543 return fmt.Errorf("memcache: corrupt get result read")
544 }
545 it.Value = it.Value[:size]
546 cb(it)
547 }
548}
549
550// scanGetResponseLine populates it and returns the declared size of the item.
551// It does not read the bytes of the item.

Callers 2

getFromAddrMethod · 0.85
getAndTouchFromAddrMethod · 0.85

Calls 2

scanGetResponseLineFunction · 0.85
extendDeadlineMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…