Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 116 lines (86 sloc) 2.878 kb
045594e add missing files
ttung authored
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
f045fd8 flat memory allocator
ttung authored
3 /**
4 * the contents of this file must be separate from slabs_items.h because it
5 * depends on the full contents of memcached.h. the last part of memcached.h
6 * does not get processed until after slabs_items.h gets processed, so we have
7 * to do it separately.
8 */
045594e add missing files
ttung authored
9
f045fd8 flat memory allocator
ttung authored
10 #if defined(USE_SLAB_ALLOCATOR)
11 #if !defined(_slabs_items_support_h_)
12 #define _slabs_items_support_h_
13
14 #include <ctype.h>
045594e add missing files
ttung authored
15 #include <stdlib.h>
16 #include <string.h>
f045fd8 flat memory allocator
ttung authored
17
045594e add missing files
ttung authored
18 #include "generic.h"
19
f045fd8 flat memory allocator
ttung authored
20 #include "slabs_items.h"
21 #include "memcached.h"
045594e add missing files
ttung authored
22
7a1f4fa fixes to flat allocator, merge from trunk
ttung authored
23
f045fd8 flat memory allocator
ttung authored
24 #define ITEM_data(item) ((char*) &((item)->end) + (item)->nkey)
045594e add missing files
ttung authored
25
7a1f4fa fixes to flat allocator, merge from trunk
ttung authored
26
e8cee26 fix slab allocator
ttung authored
27 static inline int add_item_key_to_iov(conn *c, const item* it) {
28 return add_iov(c, ITEM_key_const(it), ITEM_nkey(it), false);
29 }
30
31
32 static inline int add_item_value_to_iov(conn *c, const item* it, bool send_cr_lf) {
045594e add missing files
ttung authored
33 if (send_cr_lf) {
f045fd8 flat memory allocator
ttung authored
34 return (add_iov(c, ITEM_data(it), it->nbytes, false) ||
35 add_iov(c, "\r\n", 2, false));
045594e add missing files
ttung authored
36 } else {
f045fd8 flat memory allocator
ttung authored
37 return add_iov(c, ITEM_data(it), it->nbytes, false);
045594e add missing files
ttung authored
38 }
39 }
40
41
5d88e64 connection buffer sharing
ttung authored
42 static inline bool item_setup_receive(item* it, conn* c) {
43 size_t iov_len_required;
44
45 if (c->binary == false) {
46 iov_len_required = 2;
47
48 assert(c->riov == NULL);
49 assert(c->riov_size == 0);
c0dbcaf connection buffers are per-thread to avoid lock contention
ttung authored
50 c->riov = (struct iovec*) alloc_conn_buffer(c->cbg, sizeof(struct iovec) * iov_len_required);
5d88e64 connection buffer sharing
ttung authored
51 if (c->riov == NULL) {
52 return false;
53 }
54 } else {
55 iov_len_required = 1;
56 }
57
c0dbcaf connection buffers are per-thread to avoid lock contention
ttung authored
58 report_max_rusage(c->cbg, c->riov, sizeof(struct iovec) * iov_len_required);
5d88e64 connection buffer sharing
ttung authored
59 c->riov_size = iov_len_required;
60 c->riov_left = iov_len_required;
61 c->riov_curr = 0;
62
63 c->riov[0].iov_base = ITEM_data(it);
64 c->riov[0].iov_len = it->nbytes;
f045fd8 flat memory allocator
ttung authored
65
5d88e64 connection buffer sharing
ttung authored
66 if (c->binary) {
67 return true;
045594e add missing files
ttung authored
68 } else {
5d88e64 connection buffer sharing
ttung authored
69 c->riov[1].iov_base = c->crlf;
70 c->riov[1].iov_len = 2;
045594e add missing files
ttung authored
71
5d88e64 connection buffer sharing
ttung authored
72 return true;
f045fd8 flat memory allocator
ttung authored
73 }
045594e add missing files
ttung authored
74 }
75
f045fd8 flat memory allocator
ttung authored
76 static inline int item_strtoul(const item* it, int base) {
77 uint32_t value = 0;
78 char* src;
79 int i;
80
81 for (i = 0, src = ITEM_data(it);
82 i < ITEM_nbytes(it);
83 i ++, src ++) {
84 if (! isdigit(*src)) {
85 return 0;
86 } else {
87 uint32_t prev_value = value;
88
89 value = (value * 10) + (*src - '0');
90
91 if (prev_value > value) {
92 /* overflowed. return 0. */
93 return 0;
94 }
95 }
96 }
7a1f4fa fixes to flat allocator, merge from trunk
ttung authored
97
f045fd8 flat memory allocator
ttung authored
98 return value;
045594e add missing files
ttung authored
99 }
100
7a1f4fa fixes to flat allocator, merge from trunk
ttung authored
101
f045fd8 flat memory allocator
ttung authored
102 static inline void item_memset(item* it, size_t offset, int c, size_t nbytes) {
103 memset(ITEM_data(it) + offset, c, nbytes);
045594e add missing files
ttung authored
104 }
105
7a1f4fa fixes to flat allocator, merge from trunk
ttung authored
106
045594e add missing files
ttung authored
107 // undefine the macro to resist catch inappropriate use of the macro.
7a1f4fa fixes to flat allocator, merge from trunk
ttung authored
108 #if defined(__need_ITEM_data)
109 #undef __need_ITEM_data
110 #else
045594e add missing files
ttung authored
111 #undef ITEM_data
7a1f4fa fixes to flat allocator, merge from trunk
ttung authored
112 #endif /* #if defined(__need_ITEM_data) */
045594e add missing files
ttung authored
113
f045fd8 flat memory allocator
ttung authored
114 #endif /* #if !defined(_slabs_items_support_h_) */
115 #endif /* #if defined(USE_SLAB_ALLOCATOR) */
Something went wrong with that request. Please try again.