Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 174 lines (158 sloc) 6.396 kB
ccb56f4 @trondn Use an "api" to build a packet
trondn authored
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
0a7576a @trondn Update copyright year
trondn authored
3 * Copyright 2010, 2011 Couchbase, Inc.
ccb56f4 @trondn Use an "api" to build a packet
trondn authored
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 /**
19 * This file contains the functions to operate on the packets
20 *
21 * @author Trond Norbye
22 * @todo add more documentation
23 */
24
25 #include "internal.h"
26
19a3e34 @trondn Refactor the API
trondn authored
27 void lcb_server_buffer_start_packet(lcb_server_t *c,
28 const void *command_cookie,
29 ringbuffer_t *buff,
30 ringbuffer_t *buff_cookie,
31 const void *data,
32 lcb_size_t size)
db39157 @trondn Connect should be async
trondn authored
33 {
19a3e34 @trondn Refactor the API
trondn authored
34 struct lcb_command_data_st ct;
35 memset(&ct, 0, sizeof(struct lcb_command_data_st));
227b0f4 @trondn Implement operation timeouts (CCBC-20)
trondn authored
36 /* @todo we don't want to call gethrtime for each operation, */
37 /* so I need to pass it down the chain so that a large */
38 /* multiget can reuse the same timer... */
39 ct.start = gethrtime();
be66533 @trondn Update the NMakefile to include the new files
trondn authored
40 ct.cookie = command_cookie;
668f683 @trondn Add a ringbuffer to use instead of the buffer_t
trondn authored
41
00ca15d @trondn Refactor: rename libcouchbase_ringbuffer_ to ringbuffer_
trondn authored
42 if (!ringbuffer_ensure_capacity(buff, size) ||
43 !ringbuffer_ensure_capacity(&c->cmd_log, size) ||
44 !ringbuffer_ensure_capacity(buff_cookie, sizeof(ct)) ||
45 ringbuffer_write(buff, data, size) != size ||
46 ringbuffer_write(&c->cmd_log, data, size) != size ||
47 ringbuffer_write(buff_cookie, &ct, sizeof(ct)) != sizeof(ct)) {
668f683 @trondn Add a ringbuffer to use instead of the buffer_t
trondn authored
48 abort();
49 }
db39157 @trondn Connect should be async
trondn authored
50 }
51
19a3e34 @trondn Refactor the API
trondn authored
52 void lcb_server_buffer_retry_packet(lcb_server_t *c,
53 struct lcb_command_data_st *ct,
54 ringbuffer_t *buff,
55 ringbuffer_t *buff_cookie,
56 const void *data,
57 lcb_size_t size)
839a4aa @avsej Handle PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET
avsej authored
58 {
19a3e34 @trondn Refactor the API
trondn authored
59 lcb_size_t ct_size = sizeof(struct lcb_command_data_st);
839a4aa @avsej Handle PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET
avsej authored
60
00ca15d @trondn Refactor: rename libcouchbase_ringbuffer_ to ringbuffer_
trondn authored
61 if (!ringbuffer_ensure_capacity(buff, size) ||
62 !ringbuffer_ensure_capacity(&c->cmd_log, size) ||
63 !ringbuffer_ensure_capacity(buff_cookie, ct_size) ||
64 ringbuffer_write(buff, data, size) != size ||
65 ringbuffer_write(&c->cmd_log, data, size) != size ||
66 ringbuffer_write(buff_cookie, ct, ct_size) != ct_size) {
839a4aa @avsej Handle PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET
avsej authored
67 abort();
68 }
69 }
70
19a3e34 @trondn Refactor the API
trondn authored
71 void lcb_server_buffer_write_packet(lcb_server_t *c,
72 ringbuffer_t *buff,
73 const void *data,
74 lcb_size_t size)
db39157 @trondn Connect should be async
trondn authored
75 {
7b8acf8 @trondn Fix compile errors for unused parameters
trondn authored
76 (void)c;
00ca15d @trondn Refactor: rename libcouchbase_ringbuffer_ to ringbuffer_
trondn authored
77 if (!ringbuffer_ensure_capacity(buff, size) ||
78 !ringbuffer_ensure_capacity(&c->cmd_log, size) ||
79 ringbuffer_write(buff, data, size) != size ||
80 ringbuffer_write(&c->cmd_log, data, size) != size) {
668f683 @trondn Add a ringbuffer to use instead of the buffer_t
trondn authored
81 abort();
82 }
db39157 @trondn Connect should be async
trondn authored
83 }
84
19a3e34 @trondn Refactor the API
trondn authored
85 void lcb_server_buffer_end_packet(lcb_server_t *c,
86 ringbuffer_t *buff)
db39157 @trondn Connect should be async
trondn authored
87 {
7b8acf8 @trondn Fix compile errors for unused parameters
trondn authored
88 (void)c;
89 (void)buff;
db39157 @trondn Connect should be async
trondn authored
90 }
91
19a3e34 @trondn Refactor the API
trondn authored
92 void lcb_server_buffer_complete_packet(lcb_server_t *c,
93 const void *command_cookie,
94 ringbuffer_t *buff,
95 ringbuffer_t *buff_cookie,
96 const void *data,
97 lcb_size_t size)
db39157 @trondn Connect should be async
trondn authored
98 {
fe77402 @trondn Refactor: Add client-cookies to the command callbacks
trondn authored
99
19a3e34 @trondn Refactor the API
trondn authored
100 lcb_server_buffer_start_packet(c, command_cookie,
101 buff, buff_cookie, data, size);
102 lcb_server_buffer_end_packet(c, buff);
db39157 @trondn Connect should be async
trondn authored
103 }
104
19a3e34 @trondn Refactor the API
trondn authored
105 void lcb_server_retry_packet(lcb_server_t *c,
106 struct lcb_command_data_st *command_data,
107 const void *data,
108 lcb_size_t size)
839a4aa @avsej Handle PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET
avsej authored
109 {
110 if (c->connected) {
19a3e34 @trondn Refactor the API
trondn authored
111 lcb_server_buffer_retry_packet(c, command_data,
112 &c->output,
113 &c->output_cookies,
114 data, size);
839a4aa @avsej Handle PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET
avsej authored
115 } else {
19a3e34 @trondn Refactor the API
trondn authored
116 lcb_server_buffer_retry_packet(c, command_data,
117 &c->pending,
118 &c->pending_cookies,
119 data, size);
839a4aa @avsej Handle PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET
avsej authored
120 }
121 }
122
19a3e34 @trondn Refactor the API
trondn authored
123 void lcb_server_start_packet(lcb_server_t *c,
124 const void *command_cookie,
125 const void *data,
126 lcb_size_t size)
ccb56f4 @trondn Use an "api" to build a packet
trondn authored
127 {
db39157 @trondn Connect should be async
trondn authored
128 if (c->connected) {
19a3e34 @trondn Refactor the API
trondn authored
129 lcb_server_buffer_start_packet(c, command_cookie,
130 &c->output,
131 &c->output_cookies,
132 data, size);
db39157 @trondn Connect should be async
trondn authored
133 } else {
19a3e34 @trondn Refactor the API
trondn authored
134 lcb_server_buffer_start_packet(c, command_cookie,
135 &c->pending,
136 &c->pending_cookies,
137 data, size);
9a0229f @trondn Add support for packet filter
trondn authored
138 }
ccb56f4 @trondn Use an "api" to build a packet
trondn authored
139 }
140
19a3e34 @trondn Refactor the API
trondn authored
141 void lcb_server_write_packet(lcb_server_t *c,
142 const void *data,
143 lcb_size_t size)
ccb56f4 @trondn Use an "api" to build a packet
trondn authored
144 {
db39157 @trondn Connect should be async
trondn authored
145 if (c->connected) {
19a3e34 @trondn Refactor the API
trondn authored
146 lcb_server_buffer_write_packet(c, &c->output, data, size);
db39157 @trondn Connect should be async
trondn authored
147 } else {
19a3e34 @trondn Refactor the API
trondn authored
148 lcb_server_buffer_write_packet(c, &c->pending, data, size);
db39157 @trondn Connect should be async
trondn authored
149 }
ccb56f4 @trondn Use an "api" to build a packet
trondn authored
150 }
151
19a3e34 @trondn Refactor the API
trondn authored
152 void lcb_server_end_packet(lcb_server_t *c)
ccb56f4 @trondn Use an "api" to build a packet
trondn authored
153 {
668f683 @trondn Add a ringbuffer to use instead of the buffer_t
trondn authored
154 (void)c;
ccb56f4 @trondn Use an "api" to build a packet
trondn authored
155 }
156
19a3e34 @trondn Refactor the API
trondn authored
157 void lcb_server_complete_packet(lcb_server_t *c,
158 const void *command_cookie,
159 const void *data,
160 lcb_size_t size)
ccb56f4 @trondn Use an "api" to build a packet
trondn authored
161 {
668f683 @trondn Add a ringbuffer to use instead of the buffer_t
trondn authored
162 if (c->connected) {
19a3e34 @trondn Refactor the API
trondn authored
163 lcb_server_buffer_complete_packet(c, command_cookie,
164 &c->output,
165 &c->output_cookies,
166 data, size);
668f683 @trondn Add a ringbuffer to use instead of the buffer_t
trondn authored
167 } else {
19a3e34 @trondn Refactor the API
trondn authored
168 lcb_server_buffer_complete_packet(c, command_cookie,
169 &c->pending,
170 &c->pending_cookies,
171 data, size);
9a0229f @trondn Add support for packet filter
trondn authored
172 }
ccb56f4 @trondn Use an "api" to build a packet
trondn authored
173 }
Something went wrong with that request. Please try again.