Skip to content
Newer
Older
100644 77 lines (65 sloc) 2.26 KB
3ca2e51 Initial commit
Manju Rajashekhar authored Feb 22, 2012
1 /*
2 * twemproxy - A fast and lightweight proxy for memcached protocol.
3 * Copyright (C) 2011 Twitter, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #ifndef _NC_MBUF_H_
19 #define _NC_MBUF_H_
20
21 #include <nc_core.h>
22
23 #define MCOPY_CODEC(ACTION) \
24 ACTION( MCOPY_GET, "get " ) \
25 ACTION( MCOPY_GETS, "gets " ) \
26 ACTION( MCOPY_CRLF, "\r\n" ) \
27 ACTION( MCOPY_NIL, "" ) \
28
29 #define DEFINE_ACTION(_type, _str) _type,
30 typedef enum mcopy_type {
31 MCOPY_CODEC( DEFINE_ACTION )
32 MCOPY_SENTINEL
33 } mcopy_type_t;
34 #undef DEFINE_ACTION
35
36 struct mbuf {
37 uint32_t magic; /* mbuf magic (const) */
38 STAILQ_ENTRY(mbuf) next; /* next mbuf */
39 uint8_t *pos; /* read marker */
40 uint8_t *last; /* write marker */
41 uint8_t *start; /* start of buffer (const) */
42 uint8_t *end; /* end of buffer (const) */
43 };
44
45 STAILQ_HEAD(mhdr, mbuf);
46
47 #define MBUF_MAGIC 0xdeadbeef
c9d0c17 command line option to set mbuf chunk size
Manju Rajashekhar authored Jun 19, 2012
48 #define MBUF_MIN_SIZE 512
49 #define MBUF_MAX_SIZE 65536
3ca2e51 Initial commit
Manju Rajashekhar authored Feb 22, 2012
50 #define MBUF_SIZE 16384
51 #define MBUF_HSIZE sizeof(struct mbuf)
52
53 static inline bool
54 mbuf_empty(struct mbuf *mbuf)
55 {
56 return mbuf->pos == mbuf->last ? true : false;
57 }
58
59 static inline bool
60 mbuf_full(struct mbuf *mbuf)
61 {
62 return mbuf->last == mbuf->end ? true : false;
63 }
64
c9d0c17 command line option to set mbuf chunk size
Manju Rajashekhar authored Jun 20, 2012
65 void mbuf_init(struct instance *nci);
3ca2e51 Initial commit
Manju Rajashekhar authored Feb 22, 2012
66 void mbuf_deinit(void);
67 struct mbuf *mbuf_get(void);
68 void mbuf_put(struct mbuf *mbuf);
69 uint32_t mbuf_length(struct mbuf *mbuf);
70 uint32_t mbuf_size(struct mbuf *mbuf);
71 void mbuf_insert(struct mhdr *mhdr, struct mbuf *mbuf);
72 void mbuf_remove(struct mhdr *mhdr, struct mbuf *mbuf);
73 void mbuf_copy(struct mbuf *mbuf, uint8_t *pos, size_t n);
74 struct mbuf *mbuf_split(struct mhdr *h, uint8_t *pos, mcopy_type_t headcopy, mcopy_type_t tailcopy);
75
76 #endif
Something went wrong with that request. Please try again.