1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 * Copyright (C) 2006-2009 Brian Aker All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
20 * * The names of its contributors may not be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <libmemcached/common.h>
39 #include <libmemcached/string.hpp>
41 static memcached_return_t
textual_value_fetch(memcached_server_write_instance_st ptr
,
43 memcached_result_st
*result
)
46 ssize_t read_length
= 0;
49 WATCHPOINT_ASSERT(ptr
->root
);
50 char *end_ptr
= buffer
+ MEMCACHED_DEFAULT_COMMAND_SIZE
;
52 memcached_result_reset(result
);
54 char *string_ptr
= buffer
;
55 string_ptr
+= 6; /* "VALUE " */
63 key
= result
->item_key
;
64 result
->key_length
= 0;
66 for (prefix_length
= memcached_array_size(ptr
->root
->_namespace
); !(iscntrl(*string_ptr
) || isspace(*string_ptr
)) ; string_ptr
++)
68 if (prefix_length
== 0)
77 result
->item_key
[result
->key_length
]= 0;
80 if (end_ptr
== string_ptr
)
85 /* Flags fetch move past space */
87 if (end_ptr
== string_ptr
)
92 for (next_ptr
= string_ptr
; isdigit(*string_ptr
); string_ptr
++) {};
93 result
->item_flags
= (uint32_t) strtoul(next_ptr
, &string_ptr
, 10);
95 if (end_ptr
== string_ptr
)
100 /* Length fetch move past space*/
102 if (end_ptr
== string_ptr
)
107 for (next_ptr
= string_ptr
; isdigit(*string_ptr
); string_ptr
++) {};
108 value_length
= (size_t)strtoull(next_ptr
, &string_ptr
, 10);
110 if (end_ptr
== string_ptr
)
116 if (*string_ptr
== '\r')
118 /* Skip past the \r\n */
124 for (next_ptr
= string_ptr
; isdigit(*string_ptr
); string_ptr
++) {};
125 result
->item_cas
= strtoull(next_ptr
, &string_ptr
, 10);
128 if (end_ptr
< string_ptr
)
133 /* We add two bytes so that we can walk the \r\n */
134 if (memcached_failed(memcached_string_check(&result
->value
, value_length
+2)))
136 return memcached_set_error(*ptr
, MEMCACHED_MEMORY_ALLOCATION_FAILURE
, MEMCACHED_AT
);
140 char *value_ptr
= memcached_string_value_mutable(&result
->value
);
142 We read the \r\n into the string since not doing so is more
143 cycles then the waster of memory to do so.
145 We are null terminating through, which will most likely make
146 some people lazy about using the return length.
148 size_t to_read
= (value_length
) + 2;
149 memcached_return_t rrc
= memcached_io_read(ptr
, value_ptr
, to_read
, read_length
);
150 if (memcached_failed(rrc
) and rrc
== MEMCACHED_IN_PROGRESS
)
152 memcached_quit_server(ptr
, true);
153 return memcached_set_error(*ptr
, MEMCACHED_IN_PROGRESS
, MEMCACHED_AT
);
155 else if (memcached_failed(rrc
))
161 if (read_length
!= (ssize_t
)(value_length
+ 2))
166 /* This next bit blows the API, but this is internal....*/
169 char_ptr
= memcached_string_value_mutable(&result
->value
);;
170 char_ptr
[value_length
]= 0;
171 char_ptr
[value_length
+1]= 0;
172 memcached_string_set_length(&result
->value
, value_length
);
175 return MEMCACHED_SUCCESS
;
178 memcached_io_reset(ptr
);
180 return MEMCACHED_PARTIAL_READ
;
183 static memcached_return_t
textual_read_one_response(memcached_server_write_instance_st ptr
,
184 char *buffer
, const size_t buffer_length
,
185 memcached_result_st
*result
)
188 memcached_return_t rc
= memcached_io_readline(ptr
, buffer
, buffer_length
, total_read
);
190 if (memcached_failed(rc
))
201 if (buffer
[1] == 'A' and buffer
[2] == 'L' and buffer
[3] == 'U' and buffer
[4] == 'E') /* VALUE */
203 /* We add back in one because we will need to search for END */
204 memcached_server_response_increment(ptr
);
205 return textual_value_fetch(ptr
, buffer
, result
);
208 else if (buffer
[1] == 'E' and buffer
[2] == 'R' and buffer
[3] == 'S' and buffer
[4] == 'I' and buffer
[5] == 'O' and buffer
[6] == 'N') /* VERSION */
210 return MEMCACHED_SUCCESS
;
218 if (buffer
[1] == 'K')
220 return MEMCACHED_SUCCESS
;
228 if (buffer
[1] == 'T' and buffer
[2] == 'A' and buffer
[3] == 'T') /* STORED STATS */
230 memcached_server_response_increment(ptr
);
231 return MEMCACHED_STAT
;
234 else if (buffer
[1] == 'E' and buffer
[2] == 'R' and buffer
[3] == 'V' and buffer
[4] == 'E' and buffer
[5] == 'R'
236 and buffer
[7] == 'E' and buffer
[8] == 'R' and buffer
[9] == 'R' and buffer
[10] == 'O' and buffer
[11] == 'R' )
238 if (total_read
== memcached_literal_param_size("SERVER_ERROR"))
240 return MEMCACHED_SERVER_ERROR
;
243 if (total_read
>= memcached_literal_param_size("SERVER_ERROR object too large for cache") and
244 (memcmp(buffer
, memcached_literal_param("SERVER_ERROR object too large for cache")) == 0))
246 return MEMCACHED_E2BIG
;
249 if (total_read
>= memcached_literal_param_size("SERVER_ERROR out of memory storing object") and
250 (memcmp(buffer
, memcached_literal_param("SERVER_ERROR out of memory storing object")) == 0))
252 return MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE
;
255 // Move past the basic error message and whitespace
256 char *startptr
= buffer
+ memcached_literal_param_size("SERVER_ERROR");
257 if (startptr
[0] == ' ')
262 char *endptr
= startptr
;
263 while (*endptr
!= '\r' && *endptr
!= '\n') endptr
++;
265 return memcached_set_error(*ptr
, MEMCACHED_SERVER_ERROR
, MEMCACHED_AT
, startptr
, size_t(endptr
- startptr
));
268 else if (buffer
[1] == 'T' and buffer
[2] == 'O' and buffer
[3] == 'R') // and buffer[4] == 'E' and buffer[5] == 'D')
270 return MEMCACHED_STORED
;
278 if (buffer
[1] == 'E' and buffer
[2] == 'L' and buffer
[3] == 'E' and buffer
[4] == 'T' and buffer
[5] == 'E' and buffer
[6] == 'D')
280 return MEMCACHED_DELETED
;
288 if (buffer
[1] == 'O' and buffer
[2] == 'T'
290 and buffer
[4] == 'F' and buffer
[5] == 'O' and buffer
[6] == 'U' and buffer
[7] == 'N' and buffer
[8] == 'D')
292 return MEMCACHED_NOTFOUND
;
295 else if (buffer
[1] == 'O' and buffer
[2] == 'T'
297 and buffer
[4] == 'S' and buffer
[5] == 'T' and buffer
[6] == 'O' and buffer
[7] == 'R' and buffer
[8] == 'E' and buffer
[9] == 'D')
299 return MEMCACHED_NOTSTORED
;
304 case 'E': /* PROTOCOL ERROR or END */
307 if (buffer
[1] == 'N' and buffer
[2] == 'D')
309 return MEMCACHED_END
;
313 else if (buffer
[1] == 'R' and buffer
[2] == 'O' and buffer
[3] == 'T' and buffer
[4] == 'O' and buffer
[5] == 'C' and buffer
[6] == 'O' and buffer
[7] == 'L'
315 and buffer
[9] == 'E' and buffer
[10] == 'R' and buffer
[11] == 'R' and buffer
[12] == 'O' and buffer
[13] == 'R')
317 return MEMCACHED_PROTOCOL_ERROR
;
321 else if (buffer
[1] == 'R' and buffer
[2] == 'R' and buffer
[3] == 'O' and buffer
[4] == 'R')
323 return MEMCACHED_ERROR
;
326 else if (buffer
[1] == 'X' and buffer
[2] == 'I' and buffer
[3] == 'S' and buffer
[4] == 'T' and buffer
[5] == 'S')
328 return MEMCACHED_DATA_EXISTS
;
333 case 'T': /* TOUCHED */
336 if (buffer
[1] == 'O' and buffer
[2] == 'U' and buffer
[3] == 'C' and buffer
[4] == 'H' and buffer
[5] == 'E' and buffer
[6] == 'D')
338 return MEMCACHED_SUCCESS
;
346 if (buffer
[1] == 'T' and buffer
[2] == 'E' and buffer
[3] == 'M')
348 /* We add back in one because we will need to search for END */
349 memcached_server_response_increment(ptr
);
350 return MEMCACHED_ITEM
;
355 case 'C': /* CLIENT ERROR */
358 if (buffer
[1] == 'L' and buffer
[2] == 'I' and buffer
[3] == 'E' and buffer
[4] == 'N' and buffer
[5] == 'T'
360 and buffer
[7] == 'E' and buffer
[8] == 'R' and buffer
[9] == 'R' and buffer
[10] == 'O' and buffer
[11] == 'R')
362 return MEMCACHED_CLIENT_ERROR
;
367 case '0': /* INCR/DECR response */
368 case '1': /* INCR/DECR response */
369 case '2': /* INCR/DECR response */
370 case '3': /* INCR/DECR response */
371 case '4': /* INCR/DECR response */
372 case '5': /* INCR/DECR response */
373 case '6': /* INCR/DECR response */
374 case '7': /* INCR/DECR response */
375 case '8': /* INCR/DECR response */
376 case '9': /* INCR/DECR response */
378 unsigned long long int auto_return_value
= strtoull(buffer
, (char **)NULL
, 10);
380 if (auto_return_value
== ULLONG_MAX
and errno
== ERANGE
)
382 result
->numeric_value
= UINT64_MAX
;
383 return memcached_set_error(*ptr
, MEMCACHED_UNKNOWN_READ_FAILURE
, MEMCACHED_AT
,
384 memcached_literal_param("Numeric response was out of range"));
386 else if (errno
== EINVAL
)
388 result
->numeric_value
= UINT64_MAX
;
389 return memcached_set_error(*ptr
, MEMCACHED_UNKNOWN_READ_FAILURE
, MEMCACHED_AT
,
390 memcached_literal_param("Numeric response was out of range"));
393 result
->numeric_value
= uint64_t(auto_return_value
);
395 WATCHPOINT_STRING(buffer
);
396 return MEMCACHED_SUCCESS
;
403 buffer
[total_read
]= 0;
405 if (total_read
>= sizeof("STORSTORED") -1)
407 fprintf(stderr
, "%s:%d '%s', %.*s\n", __FILE__
, __LINE__
,
408 buffer
, MEMCACHED_MAX_BUFFER
, ptr
->read_buffer
);
409 assert(memcmp(buffer
,"STORSTORED", sizeof("STORSTORED") -1));
412 return memcached_set_error(*ptr
, MEMCACHED_UNKNOWN_READ_FAILURE
, MEMCACHED_AT
,
416 static memcached_return_t
binary_read_one_response(memcached_server_write_instance_st ptr
,
417 char *buffer
, const size_t buffer_length
,
418 memcached_result_st
*result
)
420 memcached_return_t rc
;
421 protocol_binary_response_header header
;
423 if ((rc
= memcached_safe_read(ptr
, &header
.bytes
, sizeof(header
.bytes
))) != MEMCACHED_SUCCESS
)
425 WATCHPOINT_ERROR(rc
);
429 if (header
.response
.magic
!= PROTOCOL_BINARY_RES
)
431 return memcached_set_error(*ptr
, MEMCACHED_UNKNOWN_READ_FAILURE
, MEMCACHED_AT
);
435 ** Convert the header to host local endian!
437 header
.response
.keylen
= ntohs(header
.response
.keylen
);
438 header
.response
.status
= ntohs(header
.response
.status
);
439 header
.response
.bodylen
= ntohl(header
.response
.bodylen
);
440 header
.response
.cas
= memcached_ntohll(header
.response
.cas
);
441 uint32_t bodylen
= header
.response
.bodylen
;
443 if (header
.response
.status
== PROTOCOL_BINARY_RESPONSE_SUCCESS
or
444 header
.response
.status
== PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE
)
446 switch (header
.response
.opcode
)
448 case PROTOCOL_BINARY_CMD_GETKQ
:
450 * We didn't increment the response counter for the GETKQ packet
451 * (only the final NOOP), so we need to increment the counter again.
453 memcached_server_response_increment(ptr
);
455 case PROTOCOL_BINARY_CMD_GETK
:
457 uint16_t keylen
= header
.response
.keylen
;
458 memcached_result_reset(result
);
459 result
->item_cas
= header
.response
.cas
;
461 if ((rc
= memcached_safe_read(ptr
, &result
->item_flags
, sizeof (result
->item_flags
))) != MEMCACHED_SUCCESS
)
463 WATCHPOINT_ERROR(rc
);
464 return MEMCACHED_UNKNOWN_READ_FAILURE
;
467 result
->item_flags
= ntohl(result
->item_flags
);
468 bodylen
-= header
.response
.extlen
;
470 result
->key_length
= keylen
;
471 if (memcached_failed(rc
= memcached_safe_read(ptr
, result
->item_key
, keylen
)))
473 WATCHPOINT_ERROR(rc
);
474 return MEMCACHED_UNKNOWN_READ_FAILURE
;
477 // Only bother with doing this if key_length > 0
478 if (result
->key_length
)
480 if (memcached_array_size(ptr
->root
->_namespace
) and memcached_array_size(ptr
->root
->_namespace
) >= result
->key_length
)
482 return memcached_set_error(*ptr
, MEMCACHED_UNKNOWN_READ_FAILURE
, MEMCACHED_AT
);
485 if (memcached_array_size(ptr
->root
->_namespace
))
487 result
->key_length
-= memcached_array_size(ptr
->root
->_namespace
);
488 memmove(result
->item_key
, result
->item_key
+memcached_array_size(ptr
->root
->_namespace
), result
->key_length
);
493 if (memcached_failed(memcached_string_check(&result
->value
, bodylen
)))
495 return MEMCACHED_MEMORY_ALLOCATION_FAILURE
;
498 char *vptr
= memcached_string_value_mutable(&result
->value
);
499 if (memcached_failed(rc
= memcached_safe_read(ptr
, vptr
, bodylen
)))
501 WATCHPOINT_ERROR(rc
);
502 return MEMCACHED_UNKNOWN_READ_FAILURE
;
505 memcached_string_set_length(&result
->value
, bodylen
);
509 case PROTOCOL_BINARY_CMD_INCREMENT
:
510 case PROTOCOL_BINARY_CMD_DECREMENT
:
512 if (bodylen
!= sizeof(uint64_t))
514 result
->numeric_value
= UINT64_MAX
;
515 return memcached_set_error(*ptr
, MEMCACHED_UNKNOWN_READ_FAILURE
, MEMCACHED_AT
);
519 if ((rc
= memcached_safe_read(ptr
, &val
, sizeof(val
))) != MEMCACHED_SUCCESS
)
521 result
->numeric_value
= UINT64_MAX
;
522 return MEMCACHED_UNKNOWN_READ_FAILURE
;
525 result
->numeric_value
= memcached_ntohll(val
);
529 case PROTOCOL_BINARY_CMD_SASL_LIST_MECHS
:
530 case PROTOCOL_BINARY_CMD_VERSION
:
532 memset(buffer
, 0, buffer_length
);
533 if (bodylen
>= buffer_length
)
535 /* not enough space in buffer.. should not happen... */
536 return MEMCACHED_UNKNOWN_READ_FAILURE
;
538 else if ((rc
= memcached_safe_read(ptr
, buffer
, bodylen
)) != MEMCACHED_SUCCESS
)
540 WATCHPOINT_ERROR(rc
);
541 return MEMCACHED_UNKNOWN_READ_FAILURE
;
545 case PROTOCOL_BINARY_CMD_FLUSH
:
546 case PROTOCOL_BINARY_CMD_QUIT
:
547 case PROTOCOL_BINARY_CMD_SET
:
548 case PROTOCOL_BINARY_CMD_ADD
:
549 case PROTOCOL_BINARY_CMD_REPLACE
:
550 case PROTOCOL_BINARY_CMD_APPEND
:
551 case PROTOCOL_BINARY_CMD_PREPEND
:
552 case PROTOCOL_BINARY_CMD_DELETE
:
553 case PROTOCOL_BINARY_CMD_TOUCH
:
555 WATCHPOINT_ASSERT(bodylen
== 0);
556 return MEMCACHED_SUCCESS
;
559 case PROTOCOL_BINARY_CMD_NOOP
:
561 WATCHPOINT_ASSERT(bodylen
== 0);
562 return MEMCACHED_END
;
565 case PROTOCOL_BINARY_CMD_STAT
:
569 return MEMCACHED_END
;
571 else if (bodylen
+ 1 > buffer_length
)
573 /* not enough space in buffer.. should not happen... */
574 return MEMCACHED_UNKNOWN_READ_FAILURE
;
578 size_t keylen
= header
.response
.keylen
;
579 memset(buffer
, 0, buffer_length
);
580 if ((rc
= memcached_safe_read(ptr
, buffer
, keylen
)) != MEMCACHED_SUCCESS
||
581 (rc
= memcached_safe_read(ptr
, buffer
+ keylen
+ 1, bodylen
- keylen
)) != MEMCACHED_SUCCESS
)
583 WATCHPOINT_ERROR(rc
);
584 return MEMCACHED_UNKNOWN_READ_FAILURE
;
590 case PROTOCOL_BINARY_CMD_SASL_AUTH
:
591 case PROTOCOL_BINARY_CMD_SASL_STEP
:
593 memcached_result_reset(result
);
594 result
->item_cas
= header
.response
.cas
;
596 if (memcached_string_check(&result
->value
,
597 bodylen
) != MEMCACHED_SUCCESS
)
598 return MEMCACHED_MEMORY_ALLOCATION_FAILURE
;
600 char *vptr
= memcached_string_value_mutable(&result
->value
);
601 if ((rc
= memcached_safe_read(ptr
, vptr
, bodylen
)) != MEMCACHED_SUCCESS
)
603 WATCHPOINT_ERROR(rc
);
604 return MEMCACHED_UNKNOWN_READ_FAILURE
;
607 memcached_string_set_length(&result
->value
, bodylen
);
612 /* Command not implemented yet! */
613 return memcached_set_error(*ptr
, MEMCACHED_UNKNOWN_READ_FAILURE
, MEMCACHED_AT
);
617 else if (header
.response
.bodylen
)
619 /* What should I do with the error message??? just discard it for now */
620 char hole
[SMALL_STRING_LEN
];
623 size_t nr
= (bodylen
> SMALL_STRING_LEN
) ? SMALL_STRING_LEN
: bodylen
;
624 if ((rc
= memcached_safe_read(ptr
, hole
, nr
)) != MEMCACHED_SUCCESS
)
626 WATCHPOINT_ERROR(rc
);
627 return memcached_set_error(*ptr
, MEMCACHED_UNKNOWN_READ_FAILURE
, MEMCACHED_AT
);
629 bodylen
-= (uint32_t) nr
;
632 /* This might be an error from one of the quiet commands.. if
633 * so, just throw it away and get the next one. What about creating
634 * a callback to the user with the error information?
636 switch (header
.response
.opcode
)
638 case PROTOCOL_BINARY_CMD_SETQ
:
639 case PROTOCOL_BINARY_CMD_ADDQ
:
640 case PROTOCOL_BINARY_CMD_REPLACEQ
:
641 case PROTOCOL_BINARY_CMD_APPENDQ
:
642 case PROTOCOL_BINARY_CMD_PREPENDQ
:
643 return binary_read_one_response(ptr
, buffer
, buffer_length
, result
);
650 rc
= MEMCACHED_SUCCESS
;
651 if (header
.response
.status
!= 0)
653 switch (header
.response
.status
)
655 case PROTOCOL_BINARY_RESPONSE_KEY_ENOENT
:
656 rc
= MEMCACHED_NOTFOUND
;
659 case PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS
:
660 rc
= MEMCACHED_DATA_EXISTS
;
663 case PROTOCOL_BINARY_RESPONSE_NOT_STORED
:
664 rc
= MEMCACHED_NOTSTORED
;
667 case PROTOCOL_BINARY_RESPONSE_E2BIG
:
671 case PROTOCOL_BINARY_RESPONSE_ENOMEM
:
672 rc
= MEMCACHED_MEMORY_ALLOCATION_FAILURE
;
675 case PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE
:
676 rc
= MEMCACHED_AUTH_CONTINUE
;
679 case PROTOCOL_BINARY_RESPONSE_AUTH_ERROR
:
680 rc
= MEMCACHED_AUTH_FAILURE
;
683 case PROTOCOL_BINARY_RESPONSE_EINVAL
:
684 case PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND
:
686 return memcached_set_error(*ptr
, MEMCACHED_UNKNOWN_READ_FAILURE
, MEMCACHED_AT
);
694 static memcached_return_t
_read_one_response(memcached_server_write_instance_st ptr
,
695 char *buffer
, const size_t buffer_length
,
696 memcached_result_st
*result
)
698 memcached_server_response_decrement(ptr
);
702 memcached_st
*root
= (memcached_st
*)ptr
->root
;
703 result
= &root
->result
;
706 memcached_return_t rc
;
707 if (memcached_is_binary(ptr
->root
))
709 rc
= binary_read_one_response(ptr
, buffer
, buffer_length
, result
);
713 rc
= textual_read_one_response(ptr
, buffer
, buffer_length
, result
);
714 assert(rc
!= MEMCACHED_PROTOCOL_ERROR
);
717 if (memcached_fatal(rc
))
719 memcached_io_reset(ptr
);
725 memcached_return_t
memcached_read_one_response(memcached_server_write_instance_st ptr
,
726 memcached_result_st
*result
)
728 char buffer
[SMALL_STRING_LEN
];
730 if (memcached_is_udp(ptr
->root
))
732 return memcached_set_error(*ptr
, MEMCACHED_NOT_SUPPORTED
, MEMCACHED_AT
);
736 return _read_one_response(ptr
, buffer
, sizeof(buffer
), result
);
739 memcached_return_t
memcached_response(memcached_server_write_instance_st ptr
,
740 memcached_result_st
*result
)
744 return memcached_response(ptr
, buffer
, sizeof(buffer
), result
);
747 memcached_return_t
memcached_response(memcached_server_write_instance_st ptr
,
748 char *buffer
, size_t buffer_length
,
749 memcached_result_st
*result
)
751 if (memcached_is_udp(ptr
->root
))
753 return memcached_set_error(*ptr
, MEMCACHED_NOT_SUPPORTED
, MEMCACHED_AT
);
756 /* We may have old commands in the buffer not set, first purge */
757 if ((ptr
->root
->flags
.no_block
) and (memcached_is_processing_input(ptr
->root
) == false))
759 (void)memcached_io_write(ptr
);
763 * The previous implementation purged all pending requests and just
764 * returned the last one. Purge all pending messages to ensure backwards
767 if (memcached_is_binary(ptr
->root
) == false and memcached_server_response_count(ptr
) > 1)
769 memcached_result_st junked_result
;
770 memcached_result_st
*junked_result_ptr
= memcached_result_create(ptr
->root
, &junked_result
);
772 assert(junked_result_ptr
);
774 while (memcached_server_response_count(ptr
) > 1)
776 memcached_return_t rc
= _read_one_response(ptr
, buffer
, buffer_length
, junked_result_ptr
);
778 // @TODO should we return an error on another but a bad read case?
780 rc
!= MEMCACHED_DATA_EXISTS
and
781 rc
!= MEMCACHED_DELETED
and
782 rc
!= MEMCACHED_E2BIG
and
783 rc
!= MEMCACHED_END
and
784 rc
!= MEMCACHED_ERROR
and
785 rc
!= MEMCACHED_ITEM
and
786 rc
!= MEMCACHED_NOTFOUND
and
787 rc
!= MEMCACHED_NOTSTORED
and
788 rc
!= MEMCACHED_SERVER_ERROR
and
789 rc
!= MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE
and
790 rc
!= MEMCACHED_STAT
and
791 rc
!= MEMCACHED_STORED
and
792 rc
!= MEMCACHED_SUCCESS
and
793 rc
!= MEMCACHED_VALUE
796 memcached_result_free(junked_result_ptr
);
800 memcached_result_free(junked_result_ptr
);
803 return _read_one_response(ptr
, buffer
, buffer_length
, result
);