forked from naver/arcus-memcached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmc_util.h
98 lines (87 loc) · 3.16 KB
/
mc_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* arcus-memcached - Arcus memory cache server
* Copyright 2018 JaM2in Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MC_UTIL_H
#define MC_UTIL_H
#include <memcached/extension.h>
/* length of string representing 4 bytes integer is 10 */
#define UINT32_STR_LENG 10
/*
* token buffer structure
*/
typedef struct _token_buff {
token_t *array;
uint32_t count;
uint32_t nused;
} token_buff_t;
/*
* memory block structure
*/
typedef struct _mblck_node {
struct _mblck_node *next;
char data[1];
} mblck_node_t;
typedef struct _mblck_list {
void *pool;
mblck_node_t *head;
mblck_node_t *tail;
uint32_t blck_cnt;
uint32_t body_len;
uint32_t item_cnt;
uint32_t item_len;
} mblck_list_t;
typedef struct _mblck_pool {
mblck_node_t *head;
mblck_node_t *tail;
uint32_t blck_len;
uint32_t body_len;
uint32_t used_cnt;
uint32_t free_cnt;
} mblck_pool_t;
/*
* memory block macros
*/
#define MBLCK_GET_HEADBLK(l) ((l)->head)
#define MBLCK_GET_TAILBLK(l) ((l)->tail)
#define MBLCK_GET_NUMBLKS(l) ((l)->blck_cnt)
#define MBLCK_GET_BODYLEN(l) ((l)->body_len)
#define MBLCK_GET_ITEMCNT(l) ((l)->item_cnt)
#define MBLCK_GET_ITEMLEN(l) ((l)->item_len)
#define MBLCK_GET_NEXTBLK(b) ((b)->next)
#define MBLCK_GET_BODYPTR(b) ((b)->data)
/* memory block functions */
int mblck_pool_create(mblck_pool_t *pool, uint32_t blck_len, uint32_t blck_cnt);
void mblck_pool_destroy(mblck_pool_t *pool);
int mblck_list_alloc(mblck_pool_t *pool, uint32_t item_len, uint32_t item_cnt,
mblck_list_t *list);
void mblck_list_merge(mblck_list_t *pri_list, mblck_list_t *add_list);
void mblck_list_free(mblck_pool_t *pool, mblck_list_t *list);
/* token buffer functions */
int token_buff_create(token_buff_t *buff, uint32_t count);
void token_buff_destroy(token_buff_t *buff);
void *token_buff_get(token_buff_t *buff, uint32_t count);
void token_buff_release(token_buff_t *buff, void *tokens);
/* tokenize functions */
size_t tokenize_command(char *command, int cmdlen, token_t *tokens, const size_t max_tokens);
int detokenize(token_t *tokens, int ntokens, char *buffer, int length);
int tokenize_keys(char *keystr, int keylen, int keycnt, char delimiter, token_t *tokens);
ENGINE_ERROR_CODE tokenize_mblocks(mblck_list_t *blist, int keylen, int keycnt,
int maxklen, bool must_backward_compatible,
token_t *tokens);
ENGINE_ERROR_CODE tokenize_sblocks(mblck_list_t *blist, int keylen, int keycnt,
int maxklen, bool must_backward_compatible,
token_t *tokens);
#endif