13 static char *storage_op_string(memcached_storage_action verb
)
34 memcached_return
memcached_send(memcached_st
*ptr
,
35 char *master_key
, size_t master_key_length
,
36 char *key
, size_t key_length
,
37 char *value
, size_t value_length
,
41 memcached_storage_action verb
)
47 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
48 unsigned int server_key
;
50 unlikely (key_length
== 0)
51 return MEMCACHED_NO_KEY_PROVIDED
;
53 unlikely (ptr
->number_of_hosts
== 0)
54 return MEMCACHED_NO_SERVERS
;
56 if ((ptr
->flags
& MEM_VERIFY_KEY
) && (memcachd_key_test(&key
, &key_length
, 1) == MEMCACHED_BAD_KEY_PROVIDED
))
57 return MEMCACHED_BAD_KEY_PROVIDED
;
59 server_key
= memcached_generate_hash(ptr
, master_key
, master_key_length
);
62 write_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
63 "%s %.*s %u %llu %zu %llu\r\n", storage_op_string(verb
),
64 (int)key_length
, key
, flags
,
65 (unsigned long long)expiration
, value_length
,
66 (unsigned long long)cas
);
68 write_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
69 "%s %.*s %u %llu %zu\r\n", storage_op_string(verb
),
70 (int)key_length
, key
, flags
,
71 (unsigned long long)expiration
, value_length
);
73 if (write_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
)
75 rc
= MEMCACHED_WRITE_FAILURE
;
79 rc
= memcached_do(&ptr
->hosts
[server_key
], buffer
, write_length
, 0);
80 if (rc
!= MEMCACHED_SUCCESS
)
83 if ((sent_length
= memcached_io_write(&ptr
->hosts
[server_key
], value
, value_length
, 0)) == -1)
85 rc
= MEMCACHED_WRITE_FAILURE
;
89 if ((ptr
->flags
& MEM_BUFFER_REQUESTS
) && verb
== SET_OP
)
94 if ((sent_length
= memcached_io_write(&ptr
->hosts
[server_key
], "\r\n", 2, to_write
)) == -1)
96 rc
= MEMCACHED_WRITE_FAILURE
;
101 return MEMCACHED_BUFFERED
;
103 rc
= memcached_response(&ptr
->hosts
[server_key
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
105 if (rc
== MEMCACHED_STORED
)
106 return MEMCACHED_SUCCESS
;
111 memcached_io_reset(&ptr
->hosts
[server_key
]);