Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sol-socket.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Soletta (TM) Project
3  *
4  * Copyright (C) 2015 Intel Corporation. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 
21 #include <sol-network.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
41 struct sol_socket;
42 typedef struct sol_socket sol_socket;
43 
51 };
52 
56 typedef struct sol_socket_options {
57 #ifndef SOL_NO_API_VERSION
58 #define SOL_SOCKET_OPTIONS_API_VERSION (1)
62  uint16_t api_version;
63 
66  uint16_t sub_api;
67 #endif
68 
77  bool (*on_can_read)(void *data, struct sol_socket *s);
78 
87  bool (*on_can_write)(void *data, struct sol_socket *s);
88 
93  const void *data;
95 
100 typedef struct sol_socket_ip_options {
102 #ifndef SOL_NO_API_VERSION
103 #define SOL_SOCKET_IP_OPTIONS_SUB_API_VERSION (1)
104 #endif
105 
111 
115  bool secure;
116 
122 
128 
135 
142 
150 typedef struct sol_socket_type {
151 #ifndef SOL_NO_API_VERSION
152 #define SOL_SOCKET_TYPE_API_VERSION (1)
156  uint16_t api_version;
157 #endif
158 
164  void (*del)(struct sol_socket *s);
165 
175  int (*set_read_monitor)(struct sol_socket *s, bool on);
176 
186  int (*set_write_monitor)(struct sol_socket *s, bool on);
187 
202  ssize_t (*recvmsg)(struct sol_socket *s, struct sol_buffer *buffer,
203  struct sol_network_link_addr *cliaddr);
204 
214  ssize_t (*sendmsg)(struct sol_socket *s, const struct sol_buffer *buffer,
215  const struct sol_network_link_addr *cliaddr);
216 
228  int (*join_group)(struct sol_socket *s, int ifindex,
229  const struct sol_network_link_addr *group);
230 
239  int (*bind)(struct sol_socket *s, const struct sol_network_link_addr *addr);
241 
247 typedef struct sol_socket {
248  const struct sol_socket_type *type;
249 } sol_socket;
250 
264 struct sol_socket *sol_socket_ip_new(const struct sol_socket_options *options);
265 
275 void sol_socket_del(struct sol_socket *s);
276 
290 int sol_socket_set_read_monitor(struct sol_socket *s, bool on);
291 
305 int sol_socket_set_write_monitor(struct sol_socket *s, bool on);
306 
330 ssize_t sol_socket_recvmsg(struct sol_socket *s, struct sol_buffer *buffer,
331  struct sol_network_link_addr *cliaddr);
332 
344 ssize_t sol_socket_sendmsg(struct sol_socket *s, const struct sol_buffer *buffer,
345  const struct sol_network_link_addr *cliaddr);
346 
362 int sol_socket_join_group(struct sol_socket *s, int ifindex, const struct sol_network_link_addr *group);
363 
378 int sol_socket_bind(struct sol_socket *s, const struct sol_network_link_addr *addr);
379 
384 #ifdef __cplusplus
385 }
386 #endif
uint16_t cipher_suites_len
If secure is true, this should be considered.
Definition: sol-socket.h:140
Structure to represent a socket.
Definition: sol-socket.h:247
const struct sol_socket_type * type
Definition: sol-socket.h:248
bool reuse_addr
Allow reuse of local addresses.
Definition: sol-socket.h:127
void(* del)(struct sol_socket *s)
Function to be called when the socket is deleted.
Definition: sol-socket.h:164
ssize_t(* sendmsg)(struct sol_socket *s, const struct sol_buffer *buffer, const struct sol_network_link_addr *cliaddr)
Function to be called to write data in the socket.
Definition: sol-socket.h:214
ssize_t sol_socket_sendmsg(struct sol_socket *s, const struct sol_buffer *buffer, const struct sol_network_link_addr *cliaddr)
Transmits a message using the socket.
Definition: sol-socket.h:49
int sol_socket_set_read_monitor(struct sol_socket *s, bool on)
Adds a function to be called when the socket had data to be read.
struct sol_socket_ip_options sol_socket_ip_options
Defines specific IP layer related behaviour of a socket instance.
struct sol_socket_options sol_socket_options
Defines the behaviour of a socket instance.
int(* set_write_monitor)(struct sol_socket *s, bool on)
Starts or stops monitoring the socket for writing.
Definition: sol-socket.h:186
ssize_t sol_socket_recvmsg(struct sol_socket *s, struct sol_buffer *buffer, struct sol_network_link_addr *cliaddr)
Receive a message from a socket.
bool(* on_can_read)(void *data, struct sol_socket *s)
Register a function to be called when the socket has data to be read.
Definition: sol-socket.h:77
enum sol_network_family family
The family that should be used when creating the socket.
Definition: sol-socket.h:110
bool secure
If the socket's data should be encrypted or not.
Definition: sol-socket.h:115
void sol_socket_del(struct sol_socket *s)
Destroy the socket instance.
int(* set_read_monitor)(struct sol_socket *s, bool on)
Starts or stops monitoring the socket for reading.
Definition: sol-socket.h:175
bool reuse_port
Allows multiple sockets to be bound to the same socket address.
Definition: sol-socket.h:121
int(* bind)(struct sol_socket *s, const struct sol_network_link_addr *addr)
Function to be called to bind the socket to a network address.
Definition: sol-socket.h:239
struct sol_socket_type sol_socket_type
Structure to represent a socket class.
Structure to represent a socket class.
Definition: sol-socket.h:150
Defines the behaviour of a socket instance.
Definition: sol-socket.h:56
int(* join_group)(struct sol_socket *s, int ifindex, const struct sol_network_link_addr *group)
Function to be called to join a multicast group.
Definition: sol-socket.h:228
Defines specific IP layer related behaviour of a socket instance.
Definition: sol-socket.h:100
bool(* on_can_write)(void *data, struct sol_socket *s)
Register a function to be called when the socket is ready to be written.
Definition: sol-socket.h:87
const void * data
User data data will be given in on_can_read() and on_can_write()
Definition: sol-socket.h:93
sol_network_family
Type of a network address.
Definition: sol-network.h:114
struct sol_socket_options base
Definition: sol-socket.h:101
struct sol_socket sol_socket
Structure to represent a socket.
Definition: sol-socket.h:42
int sol_socket_bind(struct sol_socket *s, const struct sol_network_link_addr *addr)
Binds the socket to a specific address.
uint16_t sub_api
To version each subclass.
Definition: sol-socket.h:66
ssize_t(* recvmsg)(struct sol_socket *s, struct sol_buffer *buffer, struct sol_network_link_addr *cliaddr)
Function to be called to read data from socket.
Definition: sol-socket.h:202
int sol_socket_join_group(struct sol_socket *s, int ifindex, const struct sol_network_link_addr *group)
Joins a multicast group.
enum sol_socket_dtls_cipher * cipher_suites
If secure is true, this should be considered.
Definition: sol-socket.h:134
int sol_socket_set_write_monitor(struct sol_socket *s, bool on)
Adds a function to be called when the socket is able to send data.
sol_socket_dtls_cipher
Represents supported Cipher Suites for use with DTLS.
Definition: sol-socket.h:47
struct sol_socket * sol_socket_ip_new(const struct sol_socket_options *options)
Creates an endpoint for communication.
A sol_buffer is a dynamic array, that can be resized if needed.
Definition: sol-buffer.h:130
These are routines that Soletta provides for handling network link interfaces, making it possible to ...