Esempio n. 1
0
static bool
mc_action_match_entry(struct mc_action *action, struct mc_entry *entry)
{
	if (action->hash != entry->hash)
		return false;
	if (action->key_len != entry->key_len)
		return false;
	return !memcmp(action->key, mc_entry_getkey(entry), action->key_len);
}
Esempio n. 2
0
static void
mc_command_transmit_binary_entry(struct mc_state *state,
				 struct mc_command *command,
				 bool with_key)
{
	ENTER();

	struct mc_entry *entry = command->action.old_entry;
	uint16_t key_len = with_key ? entry->key_len : 0;
	char *value = mc_entry_getvalue(entry);
	uint32_t value_len = entry->value_len;

	struct
	{
		struct mc_binary_header header;
		uint32_t flags;
	} packet;

	packet.header.magic = MC_BINARY_RESPONSE;
	packet.header.status = MC_BINARY_STATUS_NO_ERROR;
	packet.header.opcode = command->binary.opcode;
	packet.header.opaque = command->binary.opaque;
	packet.header.key_len = mm_htons(key_len);
	packet.header.ext_len = 4;
	packet.header.data_type = 0;
	packet.header.body_len = mm_htonl(4 + key_len + entry->value_len);
	packet.header.stamp = mm_htonll(entry->stamp);
	packet.flags = mm_htonl(entry->flags);

	mm_netbuf_write(&state->sock, &packet, 28);
	if (with_key) {
		char *key = mc_entry_getkey(entry);
		mm_netbuf_splice(&state->sock, key, key_len, NULL, 0);
	}
	mm_netbuf_splice(&state->sock, value, value_len,
			 mc_command_transmit_unref, (uintptr_t) entry);

	LEAVE();
}
Esempio n. 3
0
static void
mc_command_transmit_entry(struct mc_state *state,
			  struct mc_command *command,
			  bool cas)
{
	ENTER();

	struct mc_entry *entry = command->action.old_entry;
	char *key = mc_entry_getkey(entry);
	char *value = mc_entry_getvalue(entry);
	uint8_t key_len = entry->key_len;
	uint32_t value_len = entry->value_len;

	if (cas) {
		mm_netbuf_printf(
			&state->sock,
			"VALUE %.*s %u %u %llu\r\n",
			key_len, key,
			entry->flags, value_len,
			(unsigned long long) entry->stamp);
	} else {
		mm_netbuf_printf(
			&state->sock,
			"VALUE %.*s %u %u\r\n",
			key_len, key,
			entry->flags, value_len);
	}

	mm_netbuf_splice(&state->sock, value, value_len,
			 mc_command_transmit_unref, (uintptr_t) entry);

	if (command->ascii.last)
		WRITE(&state->sock, mc_result_end2);
	else
		WRITE(&state->sock, mc_result_nl);

	LEAVE();
}