Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
aerospike
as_async.h
Go to the documentation of this file.
1
/*
2
* Copyright 2008-2017 Aerospike, Inc.
3
*
4
* Portions may be licensed to Aerospike, Inc. under one or more contributor
5
* license agreements.
6
*
7
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
8
* use this file except in compliance with the License. You may obtain a copy of
9
* the License at 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, WITHOUT
13
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
* License for the specific language governing permissions and limitations under
15
* the License.
16
*/
17
#pragma once
18
19
#include <
aerospike/as_async_proto.h
>
20
#include <
aerospike/as_cluster.h
>
21
#include <
aerospike/as_event_internal.h
>
22
#include <
aerospike/as_listener.h
>
23
#include <citrusleaf/alloc.h>
24
25
#ifdef __cplusplus
26
extern
"C"
{
27
#endif
28
29
/******************************************************************************
30
* TYPES
31
*****************************************************************************/
32
33
#define AS_ASYNC_TYPE_WRITE 0
34
#define AS_ASYNC_TYPE_RECORD 1
35
#define AS_ASYNC_TYPE_VALUE 2
36
#define AS_ASYNC_TYPE_BATCH 3
37
#define AS_ASYNC_TYPE_SCAN 4
38
#define AS_ASYNC_TYPE_QUERY 5
39
#define AS_ASYNC_TYPE_MASK 7
40
#define AS_ASYNC_TYPE_REGISTERED 128
41
42
#define AS_AUTHENTICATION_MAX_SIZE 158
43
44
#define AS_ASYNC_CONNECTION_COMPLETE 0
45
#define AS_ASYNC_CONNECTION_PENDING 1
46
#define AS_ASYNC_CONNECTION_ERROR 2
47
48
typedef
struct
as_async_write_command
{
49
as_event_command
command
;
50
as_async_write_listener
listener
;
51
uint8_t
space
[];
52
}
as_async_write_command
;
53
54
typedef
struct
as_async_record_command
{
55
as_event_command
command
;
56
as_async_record_listener
listener
;
57
uint8_t
space
[];
58
}
as_async_record_command
;
59
60
typedef
struct
as_async_value_command
{
61
as_event_command
command
;
62
as_async_value_listener
listener
;
63
uint8_t
space
[];
64
}
as_async_value_command
;
65
66
/******************************************************************************
67
* FUNCTIONS
68
*****************************************************************************/
69
70
static
inline
as_event_command
*
71
as_async_write_command_create
(
72
as_cluster
* cluster,
as_node
* node, uint32_t timeout_ms,
bool
deserialize,
73
as_async_write_listener
listener,
void
* udata,
as_event_loop
* event_loop,
74
as_pipe_listener
pipe_listener,
size_t
size,
as_event_parse_results_fn
parse_results
75
)
76
{
77
// Allocate enough memory to cover: struct size + write buffer size + auth max buffer size
78
// Then, round up memory size in 1KB increments.
79
size_t
s = (
sizeof
(
as_async_write_command
) + size +
AS_AUTHENTICATION_MAX_SIZE
+ 1023) & ~1023;
80
as_event_command
* cmd = (
as_event_command
*)cf_malloc(s);
81
as_async_write_command
* wcmd = (
as_async_write_command
*)cmd;
82
cmd->
event_loop
=
as_event_assign
(event_loop);
83
cmd->
conn
= 0;
84
cmd->
cluster
= cluster;
85
cmd->
node
= node;
86
cmd->
udata
= udata;
87
cmd->
parse_results
= parse_results;
88
cmd->
buf
= wcmd->
space
;
89
cmd->
capacity
= (uint32_t)(s -
sizeof
(
as_async_write_command
));
90
cmd->
len
= 0;
91
cmd->
pos
= 0;
92
cmd->
auth_len
= 0;
93
cmd->
timeout_ms
= timeout_ms;
94
cmd->
type
=
AS_ASYNC_TYPE_WRITE
;
95
cmd->
state
=
AS_ASYNC_STATE_UNREGISTERED
;
96
cmd->
pipe_listener
= pipe_listener;
97
cmd->
deserialize
= deserialize;
98
cmd->
free_buf
=
false
;
99
wcmd->
listener
= listener;
100
return
cmd;
101
}
102
103
static
inline
as_event_command
*
104
as_async_record_command_create
(
105
as_cluster
* cluster,
as_node
* node, uint32_t timeout_ms,
bool
deserialize,
106
as_async_record_listener
listener,
void
* udata,
as_event_loop
* event_loop,
107
as_pipe_listener
pipe_listener,
size_t
size,
as_event_parse_results_fn
parse_results
108
)
109
{
110
// Allocate enough memory to cover: struct size + write buffer size + auth max buffer size
111
// Then, round up memory size in 1KB increments to reduce fragmentation and to allow socket
112
// read to reuse buffer for small socket write sizes.
113
size_t
s = (
sizeof
(
as_async_record_command
) + size +
AS_AUTHENTICATION_MAX_SIZE
+ 1023) & ~1023;
114
as_event_command
* cmd = (
as_event_command
*)cf_malloc(s);
115
as_async_record_command
* rcmd = (
as_async_record_command
*)cmd;
116
cmd->
event_loop
=
as_event_assign
(event_loop);
117
cmd->
conn
= 0;
118
cmd->
cluster
= cluster;
119
cmd->
node
= node;
120
cmd->
udata
= udata;
121
cmd->
parse_results
= parse_results;
122
cmd->
buf
= rcmd->
space
;
123
cmd->
capacity
= (uint32_t)(s -
sizeof
(
as_async_record_command
));
124
cmd->
len
= 0;
125
cmd->
pos
= 0;
126
cmd->
auth_len
= 0;
127
cmd->
timeout_ms
= timeout_ms;
128
cmd->
type
=
AS_ASYNC_TYPE_RECORD
;
129
cmd->
state
=
AS_ASYNC_STATE_UNREGISTERED
;
130
cmd->
pipe_listener
= pipe_listener;
131
cmd->
deserialize
= deserialize;
132
cmd->
free_buf
=
false
;
133
rcmd->
listener
= listener;
134
return
cmd;
135
}
136
137
static
inline
as_event_command
*
138
as_async_value_command_create
(
139
as_cluster
* cluster,
as_node
* node, uint32_t timeout_ms,
bool
deserialize,
140
as_async_value_listener
listener,
void
* udata,
as_event_loop
* event_loop,
141
as_pipe_listener
pipe_listener,
size_t
size,
as_event_parse_results_fn
parse_results
142
)
143
{
144
// Allocate enough memory to cover: struct size + write buffer size + auth max buffer size
145
// Then, round up memory size in 1KB increments to reduce fragmentation and to allow socket
146
// read to reuse buffer for small socket write sizes.
147
size_t
s = (
sizeof
(
as_async_value_command
) + size +
AS_AUTHENTICATION_MAX_SIZE
+ 1023) & ~1023;
148
as_event_command
* cmd = (
as_event_command
*)cf_malloc(s);
149
as_async_value_command
* vcmd = (
as_async_value_command
*)cmd;
150
cmd->
event_loop
=
as_event_assign
(event_loop);
151
cmd->
conn
= 0;
152
cmd->
cluster
= cluster;
153
cmd->
node
= node;
154
cmd->
udata
= udata;
155
cmd->
parse_results
= parse_results;
156
cmd->
buf
= vcmd->
space
;
157
cmd->
capacity
= (uint32_t)(s -
sizeof
(
as_async_value_command
));
158
cmd->
len
= 0;
159
cmd->
pos
= 0;
160
cmd->
auth_len
= 0;
161
cmd->
timeout_ms
= timeout_ms;
162
cmd->
type
=
AS_ASYNC_TYPE_VALUE
;
163
cmd->
state
=
AS_ASYNC_STATE_UNREGISTERED
;
164
cmd->
pipe_listener
= pipe_listener;
165
cmd->
deserialize
= deserialize;
166
cmd->
free_buf
=
false
;
167
vcmd->
listener
= listener;
168
return
cmd;
169
}
170
171
#ifdef __cplusplus
172
}
// end extern "C"
173
#endif