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 WATCHPOINT_ASSERT(!(value
== NULL
&& value_length
> 0));
51 WATCHPOINT_ASSERT(!(value
&& value_length
== 0));
53 unlikely (key_length
== 0)
54 return MEMCACHED_NO_KEY_PROVIDED
;
56 unlikely (ptr
->number_of_hosts
== 0)
57 return MEMCACHED_NO_SERVERS
;
59 if ((ptr
->flags
& MEM_VERIFY_KEY
) && (memcachd_key_test(&key
, &key_length
, 1) == MEMCACHED_BAD_KEY_PROVIDED
))
60 return MEMCACHED_BAD_KEY_PROVIDED
;
62 server_key
= memcached_generate_hash(ptr
, master_key
, master_key_length
);
65 write_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
66 "%s %.*s %u %llu %zu %llu\r\n", storage_op_string(verb
),
67 (int)key_length
, key
, flags
,
68 (unsigned long long)expiration
, value_length
,
69 (unsigned long long)cas
);
71 write_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
72 "%s %.*s %u %llu %zu\r\n", storage_op_string(verb
),
73 (int)key_length
, key
, flags
,
74 (unsigned long long)expiration
, value_length
);
76 if (write_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
)
78 rc
= MEMCACHED_WRITE_FAILURE
;
82 rc
= memcached_do(&ptr
->hosts
[server_key
], buffer
, write_length
, 0);
83 if (rc
!= MEMCACHED_SUCCESS
)
86 if ((sent_length
= memcached_io_write(&ptr
->hosts
[server_key
], value
, value_length
, 0)) == -1)
88 rc
= MEMCACHED_WRITE_FAILURE
;
92 if ((ptr
->flags
& MEM_BUFFER_REQUESTS
) && verb
== SET_OP
)
97 if ((sent_length
= memcached_io_write(&ptr
->hosts
[server_key
], "\r\n", 2, to_write
)) == -1)
99 rc
= MEMCACHED_WRITE_FAILURE
;
104 return MEMCACHED_BUFFERED
;
106 rc
= memcached_response(&ptr
->hosts
[server_key
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
108 if (rc
== MEMCACHED_STORED
)
109 return MEMCACHED_SUCCESS
;
114 memcached_io_reset(&ptr
->hosts
[server_key
]);