25#include <citrusleaf/cf_ll.h>
28#if defined(AS_USE_LIBEV)
30#elif defined(AS_USE_LIBUV)
33#elif defined(AS_USE_LIBEVENT)
34#include <event2/event.h>
46#define AS_ASYNC_STATE_UNREGISTERED 0
47#define AS_ASYNC_STATE_REGISTERED 1
48#define AS_ASYNC_STATE_DELAY_QUEUE 2
49#define AS_ASYNC_STATE_CONNECT 3
50#define AS_ASYNC_STATE_TLS_CONNECT 4
51#define AS_ASYNC_STATE_AUTH_WRITE 5
52#define AS_ASYNC_STATE_AUTH_READ_HEADER 6
53#define AS_ASYNC_STATE_AUTH_READ_BODY 7
54#define AS_ASYNC_STATE_COMMAND_WRITE 8
55#define AS_ASYNC_STATE_COMMAND_READ_HEADER 9
56#define AS_ASYNC_STATE_COMMAND_READ_BODY 10
57#define AS_ASYNC_STATE_QUEUE_ERROR 11
58#define AS_ASYNC_STATE_RETRY 12
60#define AS_ASYNC_FLAGS_DESERIALIZE 1
61#define AS_ASYNC_FLAGS_READ 2
62#define AS_ASYNC_FLAGS_HAS_TIMER 4
63#define AS_ASYNC_FLAGS_USING_SOCKET_TIMER 8
64#define AS_ASYNC_FLAGS_EVENT_RECEIVED 16
65#define AS_ASYNC_FLAGS_FREE_BUF 32
66#define AS_ASYNC_FLAGS_LINEARIZE 64
67#define AS_ASYNC_FLAGS_HEAP_REC 128
69#define AS_ASYNC_AUTH_RETURN_CODE 1
71#define AS_EVENT_CONNECTION_COMPLETE 0
72#define AS_EVENT_CONNECTION_PENDING 1
73#define AS_EVENT_CONNECTION_ERROR 2
75#define AS_EVENT_QUEUE_INITIAL_CAPACITY 256
81#if defined(AS_USE_LIBEV)
84#elif defined(AS_USE_LIBUV)
86 struct as_uv_tls* tls;
93#elif defined(AS_USE_LIBEVENT)
117#if defined(AS_USE_LIBEV)
118 struct ev_timer timer;
119#elif defined(AS_USE_LIBUV)
121#elif defined(AS_USE_LIBEVENT)
306#if defined(AS_USE_LIBEV)
308void as_ev_timer_cb(
struct ev_loop* loop, ev_timer* timer,
int revents);
309void as_ev_repeat_cb(
struct ev_loop* loop, ev_timer* timer,
int revents);
339 conn->socket.last_used = cf_getns();
345 ev_timer_init(&cmd->timer, as_ev_timer_cb, (
double)timeout / 1000.0, 0.0);
346 cmd->timer.data = cmd;
354 ev_init(&cmd->timer, as_ev_repeat_cb);
355 cmd->timer.repeat = (double)repeat / 1000.0;
356 cmd->timer.data = cmd;
398#elif defined(AS_USE_LIBUV)
400void as_uv_timer_cb(uv_timer_t* timer);
401void as_uv_repeat_cb(uv_timer_t* timer);
422 if (uv_fileno((uv_handle_t*)&
conn->socket, &fd) == 0) {
431 conn->last_used = cf_getns();
439 cmd->timer.data = cmd;
441 uv_timer_start(&cmd->timer, as_uv_timer_cb, timeout, 0);
450 cmd->timer.data = cmd;
452 uv_timer_start(&cmd->timer, as_uv_repeat_cb, repeat, repeat);
466 uv_timer_stop(&cmd->timer);
476 uv_read_stop((uv_stream_t*)
conn);
482 uv_read_stop((uv_stream_t*)
conn);
486as_uv_timer_closed(uv_handle_t* handle);
493 uv_close((uv_handle_t*)&cmd->timer, as_uv_timer_closed);
504#elif defined(AS_USE_LIBEVENT)
506void as_libevent_timer_cb(evutil_socket_t sock,
short events,
void*
udata);
507void as_libevent_repeat_cb(evutil_socket_t sock,
short events,
void*
udata);
537 conn->socket.last_used = cf_getns();
543 evtimer_assign(&cmd->timer, cmd->
event_loop->
loop, as_libevent_timer_cb, cmd);
545 tv.tv_sec = (uint32_t)timeout / 1000;
546 tv.tv_usec = ((uint32_t)timeout % 1000) * 1000;
547 evtimer_add(&cmd->timer, &tv);
554 event_assign(&cmd->timer, cmd->
event_loop->
loop, -1, EV_PERSIST, as_libevent_repeat_cb, cmd);
556 tv.tv_sec = (uint32_t)repeat / 1000;
557 tv.tv_usec = ((uint32_t)repeat % 1000) * 1000;
558 evtimer_add(&cmd->timer, &tv);
572 evtimer_del(&cmd->timer);
579 event_del(&conn->watcher);
691 cmd->
len =
sizeof(as_proto);
700 as_proto*
proto = (as_proto*)cmd->
buf;
724 pool->
limit = max_size;
828 pthread_mutex_destroy(&event_loop->
lock);
uint32_t as_authenticate_set(struct as_cluster_s *cluster, struct as_session_s *session, uint8_t *buffer)
static void as_node_incr_error_rate(as_node *node)
bool as_event_command_parse_success_failure(as_event_command *cmd)
static void as_event_decr_conn(as_event_command *cmd)
bool as_event_command_retry(as_event_command *cmd, bool timeout)
void as_event_notify_error(as_event_command *cmd, as_error *err)
static void as_event_set_write(as_event_command *cmd)
bool as_event_command_parse_info(as_event_command *cmd)
void as_event_error_callback(as_event_command *cmd, as_error *err)
static bool as_event_conn_current_tran(as_event_connection *conn, uint64_t max_socket_idle_ns)
void as_event_query_complete(as_event_command *cmd)
static void as_event_stop_read(as_event_connection *conn)
static void as_event_timer_once(as_event_command *cmd, uint64_t timeout)
bool as_event_decompress(as_event_command *cmd)
bool as_event_proto_parse(as_event_command *cmd, as_proto *proto)
static bool as_event_set_auth_parse_header(as_event_command *cmd)
void(* as_event_executable)(as_event_loop *event_loop, void *udata)
void as_event_parse_error(as_event_command *cmd, as_error *err)
static void as_event_command_release(as_event_command *cmd)
void as_event_executor_cancel(as_event_executor *executor, uint32_t queued_count)
static bool as_async_conn_pool_incr_total(as_async_conn_pool *pool)
#define AS_ASYNC_FLAGS_HAS_TIMER
void as_event_socket_timeout(as_event_command *cmd)
static void as_event_set_auth_write(as_event_command *cmd, as_session *session)
bool as_event_command_parse_result(as_event_command *cmd)
void as_event_command_schedule(as_event_command *cmd)
#define AS_ASYNC_FLAGS_USING_SOCKET_TIMER
bool as_event_command_parse_header(as_event_command *cmd)
static void as_event_release_connection(as_event_connection *conn, as_async_conn_pool *pool)
void as_event_socket_error(as_event_command *cmd, as_error *err)
static void as_event_release_async_connection(as_event_command *cmd)
void as_event_connector_success(as_event_command *cmd)
static void as_event_command_destroy(as_event_command *cmd)
as_status as_event_command_execute(as_event_command *cmd, as_error *err)
bool(* as_event_parse_results_fn)(struct as_event_command *cmd)
#define AS_ASYNC_STATE_AUTH_READ_BODY
static void as_event_stop_watcher(as_event_command *cmd, as_event_connection *conn)
void as_event_connect(as_event_command *cmd, as_async_conn_pool *pool)
bool as_event_proto_parse_auth(as_event_command *cmd, as_proto *proto)
void(* as_event_executor_complete_fn)(struct as_event_executor *executor)
static as_event_loop * as_event_assign(as_event_loop *event_loop)
void as_event_connection_complete(as_event_command *cmd)
void as_event_node_destroy(as_node *node)
void as_event_executor_error(as_event_executor *executor, as_error *err, uint32_t command_count)
static void as_event_timer_stop(as_event_command *cmd)
bool as_event_create_loop(as_event_loop *event_loop)
void as_event_response_error(as_event_command *cmd, as_error *err)
static bool as_event_socket_retry(as_event_command *cmd)
void as_event_process_timer(as_event_command *cmd)
static void as_event_loop_destroy(as_event_loop *event_loop)
#define AS_ASYNC_STATE_AUTH_READ_HEADER
static void as_event_close_connection(as_event_connection *conn)
static bool as_async_conn_pool_push_head(as_async_conn_pool *pool, as_event_connection *conn)
static void as_event_connection_timeout(as_event_command *cmd, as_async_conn_pool *pool)
void as_event_executor_complete(as_event_executor *executor)
static void as_event_set_conn_last_used(as_event_connection *conn)
static void as_event_timer_repeat(as_event_command *cmd, uint64_t repeat)
void as_event_command_free(as_event_command *cmd)
void as_event_execute_retry(as_event_command *cmd)
void as_event_close_cluster(as_cluster *cluster)
static bool as_async_conn_pool_push(as_async_conn_pool *pool, as_event_connection *conn)
void as_event_create_connections(as_node *node, as_async_conn_pool *pools)
bool as_event_execute(as_event_loop *event_loop, as_event_executable executable, void *udata)
static bool as_event_conn_current_trim(as_event_connection *conn, uint64_t max_socket_idle_ns)
void as_event_command_write_start(as_event_command *cmd)
void as_event_batch_complete(as_event_command *cmd)
static void as_async_conn_pool_init(as_async_conn_pool *pool, uint32_t min_size, uint32_t max_size)
static void as_event_timer_again(as_event_command *cmd)
static void as_event_set_auth_read_header(as_event_command *cmd)
static int as_event_conn_validate(as_event_connection *conn)
void as_event_total_timeout(as_event_command *cmd)
void as_event_register_external_loop(as_event_loop *event_loop)
void(* as_pipe_listener)(void *udata, as_event_loop *event_loop)
static void as_node_release(as_node *node)
AS_EXTERN bool as_queue_push_head(as_queue *queue, const void *ptr)
AS_EXTERN void as_queue_destroy(as_queue *queue)
static void as_queue_decr_total(as_queue *queue)
AS_EXTERN bool as_queue_init(as_queue *queue, uint32_t item_size, uint32_t capacity)
AS_EXTERN bool as_queue_push(as_queue *queue, const void *ptr)
int as_socket_validate_fd(as_socket_fd fd)
static bool as_socket_current_tran(uint64_t last_used, uint64_t max_socket_idle_ns)
void as_socket_close(as_socket *sock)
static bool as_socket_current_trim(uint64_t last_used, uint64_t max_socket_idle_ns)
static as_event_loop * as_event_loop_get(void)
struct as_event_command * cmd
as_latency_type latency_type
as_event_loop * event_loop
as_pipe_listener pipe_listener
uint32_t command_sent_counter
as_event_parse_results_fn parse_results
as_policy_replica replica
as_event_connection * conn
as_event_state * event_state
as_event_executable executable
as_event_loop * event_loop
struct as_event_command ** commands
as_event_executor_complete_fn complete_fn
as_async_conn_pool * pipe_conn_pools
as_async_conn_pool * async_conn_pools
as_pipe_listener listener