return MEMCACHED_CONNECTION_FAILURE;
}
-static ssize_t _io_write(memcached_server_write_instance_st ptr,
- const void *buffer, size_t length, bool with_flush)
+static bool _io_write(memcached_server_write_instance_st ptr,
+ const void *buffer, size_t length, bool with_flush,
+ size_t& written)
{
WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET);
assert(memcached_is_udp(ptr->root) == false);
- size_t original_length= length;
const char *buffer_ptr= static_cast<const char *>(buffer);
+ const size_t original_length= length;
+
while (length)
{
char *write_ptr;
memcached_return_t rc;
if (io_flush(ptr, with_flush, rc) == false)
{
- return -1;
+ written= original_length -length;
+ return false;
}
}
}
WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET);
if (io_flush(ptr, with_flush, rc) == false)
{
- return -1;
+ written= original_length -length;
+ return false;
}
}
- return ssize_t(original_length);
+ written= original_length -length;
+
+ return true;
}
bool memcached_io_write(memcached_server_write_instance_st ptr)
{
- return (_io_write(ptr, NULL, 0, true) >= 0);
+ size_t written;
+ return _io_write(ptr, NULL, 0, true, written);
}
ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
const void *buffer, const size_t length, const bool with_flush)
{
- return _io_write(ptr, buffer, length, with_flush);
+ size_t written;
+
+ if (_io_write(ptr, buffer, length, with_flush, written) == false)
+ {
+ return -1;
+ }
+
+ return ssize_t(written);
}
ssize_t memcached_io_writev(memcached_server_write_instance_st ptr,
for (size_t x= 0; x < number_of; x++, vector++)
{
- ssize_t returnable;
-
if (vector->length)
{
- if ((returnable= _io_write(ptr, vector->buffer, vector->length, false)) == -1)
+ size_t written;
+ if ((_io_write(ptr, vector->buffer, vector->length, false, written)) == false)
{
return -1;
}
- total+= returnable;
+ total+= written;
}
}
case PROTOCOL_BINARY_RESPONSE_AUTH_ERROR:
errstr = "Auth failure.";
break;
- case PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE:
- assert(false);
- case PROTOCOL_BINARY_RESPONSE_SUCCESS:
- assert(false);
default:
assert(false);
errstr = "UNHANDLED ERROR";
case DELTA_ITEM_CAS_MISMATCH:
write_bin_error(c, PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS, 0);
break;
-
- default:
- assert(0);
- abort();
}
}
eno = PROTOCOL_BINARY_RESPONSE_NOT_STORED;
}
write_bin_error(c, eno, 0);
- default:
- assert(false);
- abort();
}
item_remove(c->item); /* release the c->item reference */
case bin_reading_sasl_auth_data:
process_bin_complete_sasl_auth(c);
break;
- case bin_reading_cas_header:
- assert(0);
- case bin_no_state:
- assert(0);
default:
fprintf(stderr, "Not handling substate %d\n", c->substate);
assert(0);
break;
case DELTA_ITEM_CAS_MISMATCH:
break; /* Should never get here */
- default:
- assert(false);
- abort();
}
}
case REASSIGN_SRC_DST_SAME:
out_string(c, "SAME src and dst class are identical");
break;
- default:
- assert(false);
- abort();
}
return;
} else if (ntokens == 4 &&
case READ_MEMORY_ERROR: /* Failed to allocate more memory */
/* State already set by try_read_network */
break;
- default:
- assert(false);
- abort();
}
break;
case TRANSMIT_SOFT_ERROR:
stop = true;
break;
- default:
- assert(false);
- abort();
}
break;
case conn_max_state:
assert(false);
break;
- default:
- assert(false);
- abort();
}
}
test_return_t check_replication_sanity_TEST(memcached_st *memc)
{
test_true(memc);
- test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
+ test_compare(uint64_t(1),
+ memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
/*
* Make sure that we store the item on all servers
test_return_t replication_set_test(memcached_st *memc)
{
- memcached_return_t rc;
memcached_st *memc_clone= memcached_clone(NULL, memc);
- memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0);
+ test_true(memc_clone);
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0));
test_compare(MEMCACHED_SUCCESS,
memcached_set(memc, "bubba", 5, "0", 1, 0, 0));
const char key[2]= { (char)x, 0 };
size_t len;
uint32_t flags;
+ memcached_return_t rc;
char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5,
&len, &flags, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
test_return_t replication_get_test(memcached_st *memc)
{
- memcached_return_t rc;
/*
* Don't do the following in your code. I am abusing the internal details
const char key[2]= { (char)x, 0 };
size_t len;
uint32_t flags;
+ memcached_return_t rc;
char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5,
&len, &flags, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
test_return_t replication_mget_test(memcached_st *memc)
{
- memcached_return_t rc;
memcached_st *memc_clone= memcached_clone(NULL, memc);
- memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0);
+ test_true(memc_clone);
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0));
const char *keys[]= { "bubba", "key1", "key2", "key3" };
size_t len[]= { 5, 4, 4, 4 };
for (size_t x= 0; x< 4; ++x)
{
- rc= memcached_set(memc, keys[x], len[x], "0", 1, 0, 0);
- test_true(rc == MEMCACHED_SUCCESS);
+ test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys[x], len[x], "0", 1, 0, 0));
}
/*
{
char key[2]= { (char)x, 0 };
- rc= memcached_mget_by_key(new_clone, key, 1, keys, len, 4);
- test_true(rc == MEMCACHED_SUCCESS);
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_mget_by_key(new_clone, key, 1, keys, len, 4));
memcached_result_st *results= memcached_result_create(new_clone, &result_obj);
test_true(results);
int hits= 0;
+ memcached_return_t rc;
while ((results= memcached_fetch_result(new_clone, &result_obj, &rc)) != NULL)
{
hits++;
test_return_t replication_randomize_mget_test(memcached_st *memc)
{
memcached_result_st result_obj;
- memcached_return_t rc;
memcached_st *memc_clone= memcached_clone(NULL, memc);
memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 3);
memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, 1);
for (size_t x= 0; x< 7; ++x)
{
- rc= memcached_set(memc, keys[x], len[x], "1", 1, 0, 0);
- test_true(rc == MEMCACHED_SUCCESS);
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_set(memc, keys[x], len[x], "1", 1, 0, 0));
}
memcached_quit(memc);
test_true(results);
int hits= 0;
+ memcached_return_t rc;
while ((results= memcached_fetch_result(memc_clone, &result_obj, &rc)) != NULL)
{
++hits;
memcached_result_free(&result_obj);
}
memcached_free(memc_clone);
+
return TEST_SUCCESS;
}
memcached_st *memc_replicated= memcached_clone(NULL, memc_just_cloned);
const char *keys[]= { "bubba", "key1", "key2", "key3", "key4" };
- test_true(memcached_behavior_get(memc_replicated, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
+ test_compare(uint64_t(1), memcached_behavior_get(memc_replicated, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc_replicated, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, false));
// Make one copy
for (int x= int(MEMCACHED_SUCCESS); x < int(MEMCACHED_MAXIMUM_RETURN); ++x)
{
const char *key= memcached_strerror(NULL, memcached_return_t(x));
- memcached_return_t rc;
uint32_t flags;
size_t value_length;
+ memcached_return_t rc;
char *value= memcached_get(memc_clone, key, strlen(key), &value_length, &flags, &rc);
- test_true(rc == MEMCACHED_SUCCESS);
+ test_compare(MEMCACHED_SUCCESS, rc);
test_compare(strlen(key), value_length);
test_strcmp(key, value);
free(value);