-memcached_return memcached_do(memcached_server_st *ptr, const char *commmand,
- size_t command_length, uint8_t with_flush);
-memcached_return memcached_version(memcached_st *ptr);
-memcached_return value_fetch(memcached_server_st *ptr,
- char *buffer,
- memcached_result_st *result);
-void server_list_free(memcached_st *ptr, memcached_server_st *servers);
+// These are private
+#define memcached_is_allocated(__object) ((__object)->options.is_allocated)
+#define memcached_is_initialized(__object) ((__object)->options.is_initialized)
+#define memcached_is_purging(__object) ((__object)->state.is_purging)
+#define memcached_is_processing_input(__object) ((__object)->state.is_processing_input)
+#define memcached_set_purging(__object, __value) ((__object)->state.is_purging= (__value))
+#define memcached_set_processing_input(__object, __value) ((__object)->state.is_processing_input= (__value))
+#define memcached_set_initialized(__object, __value) ((__object)->options.is_initialized(= (__value))
+#define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated(= (__value))
+
+
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_do(memcached_server_instance_st *ptr, const void *commmand,
+ size_t command_length, uint8_t with_flush);
+LIBMEMCACHED_LOCAL
+memcached_return_t value_fetch(memcached_server_instance_st *ptr,
+ char *buffer,
+ memcached_result_st *result);
+LIBMEMCACHED_LOCAL
+void server_list_free(memcached_st *ptr, memcached_server_instance_st *servers);
+
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_key_test(const char * const *keys,
+ const size_t *key_length,
+ size_t number_of_keys);
+
+
+LIBMEMCACHED_LOCAL
+uint32_t generate_hash(memcached_st *ptr, const char *key, size_t key_length);
+
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_purge(memcached_server_instance_st *ptr);
+
+static inline memcached_return_t memcached_validate_key_length(size_t key_length, bool binary)
+{
+ unlikely (key_length == 0)
+ return MEMCACHED_BAD_KEY_PROVIDED;
+
+ if (binary)
+ {
+ unlikely (key_length > 0xffff)
+ return MEMCACHED_BAD_KEY_PROVIDED;
+ }
+ else
+ {
+ unlikely (key_length >= MEMCACHED_MAX_KEY)
+ return MEMCACHED_BAD_KEY_PROVIDED;
+ }
+
+ return MEMCACHED_SUCCESS;
+}
+
+#ifdef TCP_CORK
+ #define CORK TCP_CORK
+#elif defined TCP_NOPUSH
+ #define CORK TCP_NOPUSH
+#endif
+
+/*
+ test_cork() tries to enable TCP_CORK. IF TCP_CORK is not an option
+ on the system it returns false but sets errno to 0. Otherwise on
+ failure errno is set.
+*/
+static inline memcached_ternary_t test_cork(memcached_server_st *ptr, int enable)
+{
+#ifdef CORK
+ if (ptr->type != MEMCACHED_CONNECTION_TCP)
+ return MEM_FALSE;
+
+ int err= setsockopt(ptr->fd, IPPROTO_TCP, CORK,
+ &enable, (socklen_t)sizeof(int));
+ if (! err)
+ {
+ return MEM_TRUE;
+ }
+
+ perror(strerror(errno));
+ ptr->cached_errno= errno;
+
+ return MEM_FALSE;
+#else
+ (void)ptr;
+ (void)enable;
+
+ ptr->cached_errno= 0;
+
+ return MEM_NOT;
+#endif
+}