parseGetResponse reads a GET response from r and calls cb for each read and allocated Item
(r *bufio.Reader, conn *conn, cb func(*Item))
| 515 | // parseGetResponse reads a GET response from r and calls cb for each |
| 516 | // read and allocated Item |
| 517 | func 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. |
no test coverage detected
searching dependent graphs…