Kaa client C SDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ext_tcp_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 #ifndef EXT_TCP_UTILS_H_
26 #define EXT_TCP_UTILS_H_
27 
28 #include <platform/sock.h>
29 #include "kaa_error.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define KAA_TCP_SOCKET_NOT_SET -1
36 
37 
38 typedef enum {
44 
45 
46 typedef enum {
51 
52 
53 typedef enum {
58 
59 
69 typedef kaa_error_t (*on_dns_resolve_complete_fn)(void *context
70  , const kaa_sockaddr_t *addr
71  , kaa_socklen_t addr_size);
72 
73 
83 typedef kaa_error_t (*on_dns_resolve_failed_fn)(void *context);
84 
85 
91 typedef struct {
92  void *context;
96 
97 
103 typedef struct {
104  char *hostname;
106  uint16_t port;
108 
109 
131  , const kaa_dns_resolve_info_t *resolve_props
132  , kaa_sockaddr_t *result
133  , kaa_socklen_t *result_size);
134 
135 
145 
146 
158  , const kaa_sockaddr_t *destination
159  , kaa_socklen_t destination_size);
160 
161 
175  , const kaa_sockaddr_t *destination
176  , kaa_socklen_t destination_size);
177 
178 
192  , const char *buffer
193  , size_t buffer_size
194  , size_t *bytes_written);
195 
196 
211  , char *buffer
212  , size_t buffer_size
213  , size_t *bytes_read);
214 
215 
224 
225 #ifdef __cplusplus
226 } /* extern "C" */
227 #endif
228 
229 
230 #endif /* EXT_TCP_UTILS_H_ */
ext_tcp_socket_io_errors_t ext_tcp_utils_tcp_socket_read(kaa_fd_t fd, char *buffer, size_t buffer_size, size_t *bytes_read)
Reads bytes from the given socket.
ext_tcp_socket_io_errors_t ext_tcp_utils_tcp_socket_write(kaa_fd_t fd, const char *buffer, size_t buffer_size, size_t *bytes_written)
Writes the buffer into the given socket.
Definition: ext_tcp_utils.h:55
Definition: ext_tcp_utils.h:49
ext_tcp_utils_function_return_state_t ext_tcp_utils_getaddrbyhost(kaa_dns_resolve_listener_t *resolve_listener, const kaa_dns_resolve_info_t *resolve_props, kaa_sockaddr_t *result, kaa_socklen_t *result_size)
Resolves the address of the target host.
on_dns_resolve_failed_fn on_resolve_failed
Called when the host resolve was failed.
Definition: ext_tcp_utils.h:94
ext_tcp_socket_io_errors_t
Definition: ext_tcp_utils.h:53
Definition: ext_tcp_utils.h:54
size_t hostname_length
The target's hostname length.
Definition: ext_tcp_utils.h:105
uint16_t port
The target's port.
Definition: ext_tcp_utils.h:106
kaa_error_t
Definition: kaa_error.h:31
The target host information which is used for the DNS resolve needs.
Definition: ext_tcp_utils.h:103
Definition: ext_tcp_utils.h:48
struct sockaddr kaa_sockaddr_t
Definition: sock.h:76
Kaa error codes.
socklen_t kaa_socklen_t
Definition: sock.h:78
Definition: ext_tcp_utils.h:39
Definition: ext_tcp_utils.h:40
Definition: ext_tcp_utils.h:56
int kaa_fd_t
Definition: sock.h:74
on_dns_resolve_complete_fn on_host_resolved
Called when the host is successfully resolved.
Definition: ext_tcp_utils.h:93
Definition: ext_tcp_utils.h:41
kaa_error_t(* on_dns_resolve_failed_fn)(void *context)
The callback for negative host resolve results.
Definition: ext_tcp_utils.h:83
char * hostname
The target's hostname.
Definition: ext_tcp_utils.h:104
kaa_error_t ext_tcp_utils_set_sockaddr_port(kaa_sockaddr_t *addr, uint16_t port)
Sets a new port value to the given sockaddr structure.
Definition: ext_tcp_utils.h:42
ext_tcp_socket_state_t ext_tcp_utils_tcp_socket_check(kaa_fd_t fd, const kaa_sockaddr_t *destination, kaa_socklen_t destination_size)
Checks the state of the given socket descriptor.
kaa_error_t(* on_dns_resolve_complete_fn)(void *context, const kaa_sockaddr_t *addr, kaa_socklen_t addr_size)
The callback for successful DNS results.
Definition: ext_tcp_utils.h:69
Interface for the deferred DNS results.
Definition: ext_tcp_utils.h:91
ext_tcp_utils_function_return_state_t
Definition: ext_tcp_utils.h:38
ext_tcp_socket_state_t
Definition: ext_tcp_utils.h:46
void * context
The context to pass to all functions below.
Definition: ext_tcp_utils.h:92
kaa_error_t ext_tcp_utils_open_tcp_socket(kaa_fd_t *fd, const kaa_sockaddr_t *destination, kaa_socklen_t destination_size)
Creates a non-blocking TCP socket and connects it to the given target host.
Definition: ext_tcp_utils.h:47
kaa_error_t ext_tcp_utils_tcp_socket_close(kaa_fd_t fd)
Closes the given socket.