if (rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED) {
*error = rc;
- *value_length = memcached_result_length(result_ptr);
- *flags = memcached_result_flags(result_ptr);
+ if (value_length) {
+ *value_length = memcached_result_length(result_ptr);
+ }
+ if (flags) {
+ *flags = memcached_result_flags(result_ptr);
+ }
char *result_value = memcached_string_take_value(&result_ptr->value);
memcached_result_free(result_ptr);
if (instance->response_count()) {
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- if (ptr->flags.no_block) {
+ if (ptr->flags.no_block || ptr->flags.buffer_requests) {
memcached_io_write(instance);
}
return MEMCACHED_SUCCESS;
}
-static inline memcached_return_t read_through_trigger(memcached_st *, char *, size_t,
+static inline memcached_return_t get_failure(memcached_st *, char *, size_t,
memcached_result_st *result) {
return memcached_result_set_value(result, S("updated by read through trigger"));
}
class ReturnMatcher : public Catch::MatcherBase<memcached_return_t> {
public:
- explicit ReturnMatcher(const memcached_st *memc_,
+ explicit ReturnMatcher(memcached_st *memc_,
memcached_return_t expected_ = MEMCACHED_SUCCESS)
: memc{memc_}
, expected{expected_} {}
string describe() const override;
private:
- const memcached_st *memc;
+ memcached_st *memc;
memcached_return_t expected{MEMCACHED_SUCCESS};
};
class LoneReturnMatcher {
public:
ReturnMatcher returns;
- explicit LoneReturnMatcher(const memcached_st *memc)
+ explicit LoneReturnMatcher(memcached_st *memc)
: returns{memc} {}
};
}
SECTION("get_failure callback") {
- void *gptr = reinterpret_cast<void *>(reinterpret_cast<intptr_t>(&read_through_trigger));
+ void *gptr = reinterpret_cast<void *>(reinterpret_cast<intptr_t>(&get_failure));
Malloced empty(memcached_get(memc, S(__func__), nullptr, nullptr, &rc));
REQUIRE_FALSE(*empty);
REQUIRE_RC(MEMCACHED_NOTFOUND, rc);
- REQUIRE_SUCCESS(memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE, gptr));
- REQUIRE(gptr == memcached_callback_get(memc, MEMCACHED_CALLBACK_GET_FAILURE, &rc));
- REQUIRE_SUCCESS(rc);
+ uint64_t buffering = GENERATE(0, 1);
+
+ DYNAMIC_SECTION("buffering: " << buffering) {
+ REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, buffering));
+ REQUIRE_SUCCESS(memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE, gptr));
+ REQUIRE(gptr == memcached_callback_get(memc, MEMCACHED_CALLBACK_GET_FAILURE, &rc));
+ REQUIRE_SUCCESS(rc);
- for (int twice = 0; twice < 2; ++twice) {
- uint32_t flags;
- size_t len;
- Malloced val(memcached_get(memc, S(__func__), &len, &flags, &rc));
+ for (int twice = 0; twice < 2; ++twice) {
+ uint32_t flags;
+ size_t len;
+ Malloced val(memcached_get(memc, S(__func__), &len, &flags, &rc));
+ REQUIRE_SUCCESS(rc);
+ REQUIRE(string("updated by read through trigger") == string(*val, len));
+ REQUIRE_FALSE((*val)[len]);
+ }
+
+ REQUIRE_SUCCESS(memcached_set(memc, S(__func__), S("changed"), 0, 0));
+ memcached_quit(memc);
+ Malloced val(memcached_get(memc, S(__func__), nullptr, nullptr, &rc));
REQUIRE_SUCCESS(rc);
- REQUIRE(string("updated by read through trigger") == string(*val, len));
- REQUIRE_FALSE((*val)[len]);
+ REQUIRE("changed"s == *val);
}
}
+
SECTION("clone callback") {
void *cptr = reinterpret_cast<void *>(reinterpret_cast<intptr_t>(&clone_callback));