| 381 | } |
| 382 | |
| 383 | int memcache::get_data(void* buf, size_t size) |
| 384 | { |
| 385 | acl_assert(content_length_ >= length_); |
| 386 | |
| 387 | if (length_ == content_length_) { |
| 388 | // ��ȡ����β���� "\r\n" |
| 389 | if (!conn_->gets(res_line_)) { |
| 390 | close(); |
| 391 | ebuf_.format("read data CRLF error"); |
| 392 | return -1; |
| 393 | } |
| 394 | // ��ȡ "END\r\n" |
| 395 | if (!conn_->gets(res_line_) |
| 396 | || res_line_.compare("END", false) != 0) { |
| 397 | |
| 398 | close(); |
| 399 | ebuf_.format("END flag not found"); |
| 400 | return -1; |
| 401 | } |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | size_t n = content_length_ - length_; |
| 406 | if (n > size) { |
| 407 | n = size; |
| 408 | } |
| 409 | if (conn_->read(buf, n) < 0) { |
| 410 | close(); |
| 411 | ebuf_.format("read data error!"); |
| 412 | return -1; |
| 413 | } |
| 414 | length_ += n; |
| 415 | return (int) n; |
| 416 | } |
| 417 | |
| 418 | bool memcache::get(const char* key, size_t klen, string& out, |
| 419 | unsigned short* flags) |