3 char *memcached_fetch(memcached_st
*ptr
, char *key
, size_t *key_length
,
6 memcached_return_t
*error
)
8 memcached_result_st
*result_buffer
= &ptr
->result
;
10 unlikely (ptr
->flags
.use_udp
)
12 *error
= MEMCACHED_NOT_SUPPORTED
;
16 result_buffer
= memcached_fetch_result(ptr
, result_buffer
, error
);
18 if (result_buffer
== NULL
|| *error
!= MEMCACHED_SUCCESS
)
20 WATCHPOINT_ASSERT(result_buffer
== NULL
);
25 *value_length
= memcached_string_length(&result_buffer
->value
);
29 if (result_buffer
->key_length
> MEMCACHED_MAX_KEY
)
31 *error
= MEMCACHED_KEY_TOO_BIG
;
36 strncpy(key
, result_buffer
->item_key
, result_buffer
->key_length
); // For the binary protocol we will cut off the key :(
37 *key_length
= result_buffer
->key_length
;
40 *flags
= result_buffer
->item_flags
;
42 return memcached_string_c_copy(&result_buffer
->value
);
45 memcached_result_st
*memcached_fetch_result(memcached_st
*ptr
,
46 memcached_result_st
*result
,
47 memcached_return_t
*error
)
49 memcached_server_st
*server
;
51 unlikely (ptr
->flags
.use_udp
)
53 *error
= MEMCACHED_NOT_SUPPORTED
;
58 if ((result
= memcached_result_create(ptr
, NULL
)) == NULL
)
61 while ((server
= memcached_io_get_readable_server(ptr
)) != NULL
)
63 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
64 *error
= memcached_response(server
, buffer
, sizeof(buffer
), result
);
66 if (*error
== MEMCACHED_SUCCESS
)
68 else if (*error
== MEMCACHED_END
)
69 memcached_server_response_reset(server
);
70 else if (*error
!= MEMCACHED_NOTFOUND
)
74 /* We have completed reading data */
75 if (memcached_is_allocated(result
))
77 memcached_result_free(result
);
81 memcached_string_reset(&result
->value
);
87 memcached_return_t
memcached_fetch_execute(memcached_st
*ptr
,
88 memcached_execute_fn
*callback
,
90 uint32_t number_of_callbacks
)
92 memcached_result_st
*result
= &ptr
->result
;
93 memcached_return_t rc
= MEMCACHED_FAILURE
;
95 while ((result
= memcached_fetch_result(ptr
, result
, &rc
)) != NULL
)
97 if (rc
== MEMCACHED_SUCCESS
)
99 for (uint32_t x
= 0; x
< number_of_callbacks
; x
++)
101 rc
= (*callback
[x
])(ptr
, result
, context
);
102 if (rc
!= MEMCACHED_SUCCESS
)