New version update
[m6w6/libmemcached] / libmemcached / common.h
1 /*
2 Common include file for libmemached
3 */
4
5 #ifndef __COMMON_H__
6 #define __COMMON_H__
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <arpa/inet.h>
16 #include <netdb.h>
17 #include <unistd.h>
18 #include <limits.h>
19 #include <assert.h>
20 #include <errno.h>
21 #include <fcntl.h>
22 #include <sys/un.h>
23 #include <netinet/tcp.h>
24
25 #if TIME_WITH_SYS_TIME
26 # include <sys/time.h>
27 # include <time.h>
28 #else
29 # if HAVE_SYS_TIME_H
30 # include <sys/time.h>
31 # else
32 # include <time.h>
33 # endif
34 #endif
35
36
37
38 #include <memcached.h>
39 #include "memcached_io.h"
40
41 #include <libmemcached_config.h>
42
43 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
44 #define __builtin_expect(x, expected_value) (x)
45
46 #define likely(x) __builtin_expect((x),1)
47 #define unlikely(x) __builtin_expect((x),0)
48
49 #else
50
51 #define likely(x) if((x))
52 #define unlikely(x) if((x))
53
54 #endif
55
56 #ifdef HAVE_DTRACE
57 #define _DTRACE_VERSION 1
58 #else
59 #undef _DTRACE_VERSION
60 #endif
61
62 #include "libmemcached_probes.h"
63
64 #define MEMCACHED_BLOCK_SIZE 1024
65 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350
66 #define SMALL_STRING_LEN 1024
67 #define HUGE_STRING_LEN 8196
68
69
70 typedef enum {
71 MEM_NO_BLOCK= (1 << 0),
72 MEM_TCP_NODELAY= (1 << 1),
73 MEM_REUSE_MEMORY= (1 << 2),
74 MEM_USE_MD5= (1 << 3),
75 MEM_USE_KETAMA= (1 << 4),
76 MEM_USE_CRC= (1 << 5),
77 MEM_USE_CACHE_LOOKUPS= (1 << 6),
78 MEM_SUPPORT_CAS= (1 << 7),
79 MEM_BUFFER_REQUESTS= (1 << 8),
80 MEM_USE_SORT_HOSTS= (1 << 9),
81 MEM_VERIFY_KEY= (1 << 10),
82 } memcached_flags;
83
84 /* Hashing algo */
85 void md5_signature(unsigned char *key, unsigned int length, unsigned char *result);
86 uint32_t hash_crc32(const char *data,
87 size_t data_len);
88 uint32_t hsieh_hash(char *key, size_t key_length);
89 uint32_t murmur_hash(char *key, size_t key_length);
90
91 memcached_return memcached_connect(memcached_server_st *ptr);
92 memcached_return memcached_response(memcached_server_st *ptr,
93 char *buffer, size_t buffer_length,
94 memcached_result_st *result);
95 unsigned int memcached_generate_hash(memcached_st *ptr, char *key, size_t key_length);
96 void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death);
97
98 #define memcached_server_response_increment(A) (A)->cursor_active++
99 #define memcached_server_response_decrement(A) (A)->cursor_active--
100 #define memcached_server_response_reset(A) (A)->cursor_active=0
101
102 memcached_return memcached_do(memcached_server_st *ptr, char *commmand,
103 size_t command_length, uint8_t with_flush);
104 memcached_return memcached_version(memcached_st *ptr);
105 memcached_return value_fetch(memcached_server_st *ptr,
106 char *buffer,
107 memcached_result_st *result);
108 void server_list_free(memcached_st *ptr, memcached_server_st *servers);
109
110 memcached_return memcachd_key_test(char **keys, size_t *key_length,
111 unsigned int number_of_keys);
112
113 #endif /* __COMMON_H__ */