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