Loading...
Searching...
No Matches
as_lookup.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2018 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
20#include <aerospike/as_error.h>
21#include <aerospike/as_status.h>
22
23#if !defined(_MSC_VER)
24#include <netdb.h>
25#endif
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/******************************************************************************
32 * TYPES
33 ******************************************************************************/
34
35/**
36 * @private
37 * Iterator for IP addresses.
38 */
39typedef struct as_sockaddr_iterator_s {
40 struct addrinfo* addresses;
41 struct addrinfo* current;
42 uint16_t port_be;
45
46struct as_cluster_s;
47struct as_node_info_s;
48struct as_host_s;
49
50/******************************************************************************
51 * FUNCTIONS
52 ******************************************************************************/
53
54/**
55 * @private
56 * Lookup hostname and initialize address iterator.
57 */
59as_lookup_host(as_address_iterator* iter, as_error* err, const char* hostname, uint16_t port);
60
61/**
62 * @private
63 * Get next socket address with assigned port. Return false when there are no more addresses.
64 */
65static inline bool
66as_lookup_next(as_address_iterator* iter, struct sockaddr** addr)
67{
68 if (! iter->current) {
69 return false;
70 }
71
72 struct sockaddr* sa = iter->current->ai_addr;
73 iter->current = iter->current->ai_next;
74
75 if (sa->sa_family == AF_INET) {
76 ((struct sockaddr_in*)sa)->sin_port = iter->port_be;
77 }
78 else {
79 ((struct sockaddr_in6*)sa)->sin6_port = iter->port_be;
80 }
81 *addr = sa;
82 return true;
83}
84
85/**
86 * @private
87 * Release memory associated with address iterator.
88 */
89static inline void
91{
92 freeaddrinfo(iter->addresses);
93}
94
95/**
96 * @private
97 * Lookup and validate node.
98 */
101 struct as_cluster_s* cluster, as_error* err, struct as_host_s* host, struct sockaddr* addr,
102 bool detect_load_balancer, struct as_node_info_s* node_info
103 );
104
105#ifdef __cplusplus
106} // end extern "C"
107#endif
static bool as_lookup_next(as_address_iterator *iter, struct sockaddr **addr)
Definition as_lookup.h:66
as_status as_lookup_host(as_address_iterator *iter, as_error *err, const char *hostname, uint16_t port)
as_status as_lookup_node(struct as_cluster_s *cluster, as_error *err, struct as_host_s *host, struct sockaddr *addr, bool detect_load_balancer, struct as_node_info_s *node_info)
static void as_lookup_end(as_address_iterator *iter)
Definition as_lookup.h:90
as_status
Definition as_status.h:30
struct addrinfo * current
Definition as_lookup.h:41
struct addrinfo * addresses
Definition as_lookup.h:40