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 if (result_buffer
->item_flags
)
41 *flags
= result_buffer
->item_flags
;
45 return memcached_string_c_copy(&result_buffer
->value
);
48 memcached_result_st
*memcached_fetch_result(memcached_st
*ptr
,
49 memcached_result_st
*result
,
50 memcached_return_t
*error
)
52 memcached_server_st
*server
;
54 unlikely (ptr
->flags
.use_udp
)
56 *error
= MEMCACHED_NOT_SUPPORTED
;
61 if ((result
= memcached_result_create(ptr
, NULL
)) == NULL
)
64 while ((server
= memcached_io_get_readable_server(ptr
)) != NULL
)
66 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
67 *error
= memcached_response(server
, buffer
, sizeof(buffer
), result
);
69 if (*error
== MEMCACHED_SUCCESS
)
71 else if (*error
== MEMCACHED_END
)
72 memcached_server_response_reset(server
);
73 else if (*error
!= MEMCACHED_NOTFOUND
)
77 /* We have completed reading data */
78 if (memcached_is_allocated(result
))
80 memcached_result_free(result
);
84 memcached_string_reset(&result
->value
);
90 memcached_return_t
memcached_fetch_execute(memcached_st
*ptr
,
91 memcached_execute_fn
*callback
,
93 uint32_t number_of_callbacks
)
95 memcached_result_st
*result
= &ptr
->result
;
96 memcached_return_t rc
= MEMCACHED_FAILURE
;
99 while ((result
= memcached_fetch_result(ptr
, result
, &rc
)) != NULL
)
101 if (rc
== MEMCACHED_SUCCESS
)
103 for (x
= 0; x
< number_of_callbacks
; x
++)
105 rc
= (*callback
[x
])(ptr
, result
, context
);
106 if (rc
!= MEMCACHED_SUCCESS
)