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 strncpy(key
, result_buffer
->key
, result_buffer
->key_length
);
30 *key_length
= result_buffer
->key_length
;
33 if (result_buffer
->flags
)
34 *flags
= result_buffer
->flags
;
38 return memcached_string_c_copy(&result_buffer
->value
);
41 memcached_result_st
*memcached_fetch_result(memcached_st
*ptr
,
42 memcached_result_st
*result
,
43 memcached_return_t
*error
)
45 memcached_server_st
*server
;
47 unlikely (ptr
->flags
.use_udp
)
49 *error
= MEMCACHED_NOT_SUPPORTED
;
54 if ((result
= memcached_result_create(ptr
, NULL
)) == NULL
)
57 while ((server
= memcached_io_get_readable_server(ptr
)) != NULL
)
59 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
60 *error
= memcached_response(server
, buffer
, sizeof(buffer
), result
);
62 if (*error
== MEMCACHED_SUCCESS
)
64 else if (*error
== MEMCACHED_END
)
65 memcached_server_response_reset(server
);
66 else if (*error
!= MEMCACHED_NOTFOUND
)
70 /* We have completed reading data */
71 if (memcached_is_allocated(result
))
73 memcached_result_free(result
);
77 memcached_string_reset(&result
->value
);
83 memcached_return_t
memcached_fetch_execute(memcached_st
*ptr
,
84 memcached_execute_fn
*callback
,
86 uint32_t number_of_callbacks
)
88 memcached_result_st
*result
= &ptr
->result
;
89 memcached_return_t rc
= MEMCACHED_FAILURE
;
92 while ((result
= memcached_fetch_result(ptr
, result
, &rc
)) != NULL
)
94 if (rc
== MEMCACHED_SUCCESS
)
96 for (x
= 0; x
< number_of_callbacks
; x
++)
98 rc
= (*callback
[x
])(ptr
, result
, context
);
99 if (rc
!= MEMCACHED_SUCCESS
)