2 #include "memcached_io.h"
4 char *memcached_fetch(memcached_st
*ptr
, char *key
, size_t *key_length
,
7 memcached_return
*error
)
9 memcached_result_st
*result_buffer
= &ptr
->result
;
11 unlikely (ptr
->flags
& MEM_USE_UDP
)
13 *error
= MEMCACHED_NOT_SUPPORTED
;
17 result_buffer
= memcached_fetch_result(ptr
, result_buffer
, error
);
19 if (result_buffer
== NULL
|| *error
!= MEMCACHED_SUCCESS
)
21 WATCHPOINT_ASSERT(result_buffer
== NULL
);
26 *value_length
= memcached_string_length(&result_buffer
->value
);
30 strncpy(key
, result_buffer
->key
, result_buffer
->key_length
);
31 *key_length
= result_buffer
->key_length
;
34 if (result_buffer
->flags
)
35 *flags
= result_buffer
->flags
;
39 return memcached_string_c_copy(&result_buffer
->value
);
42 memcached_result_st
*memcached_fetch_result(memcached_st
*ptr
,
43 memcached_result_st
*result
,
44 memcached_return
*error
)
46 memcached_server_st
*server
;
48 unlikely (ptr
->flags
& MEM_USE_UDP
)
50 *error
= MEMCACHED_NOT_SUPPORTED
;
55 if ((result
= memcached_result_create(ptr
, NULL
)) == NULL
)
58 while ((server
= memcached_io_get_readable_server(ptr
)) != NULL
)
60 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
61 *error
= memcached_response(server
, buffer
, sizeof(buffer
), result
);
63 if (*error
== MEMCACHED_SUCCESS
)
65 else if (*error
== MEMCACHED_END
)
66 memcached_server_response_reset(server
);
71 /* We have completed reading data */
72 if (result
->is_allocated
)
73 memcached_result_free(result
);
75 memcached_string_reset(&result
->value
);
80 memcached_return
memcached_fetch_execute(memcached_st
*ptr
,
81 memcached_execute_function
*callback
,
83 unsigned int number_of_callbacks
)
85 memcached_result_st
*result
= &ptr
->result
;
86 memcached_return rc
= MEMCACHED_FAILURE
;
89 while ((result
= memcached_fetch_result(ptr
, result
, &rc
)) != NULL
)
91 if (rc
== MEMCACHED_SUCCESS
)
93 for (x
= 0; x
< number_of_callbacks
; x
++)
95 rc
= (*callback
[x
])(ptr
, result
, context
);
96 if (rc
!= MEMCACHED_SUCCESS
)