socket.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Kubos Corporation
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 
24 #pragma once
25 
26 #include <arpa/inet.h>
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <sys/socket.h>
30 
34 typedef struct
35 {
37  bool is_active;
41  struct sockaddr_in socket_addr;
42 } socket_conn;
43 
51 bool kprv_socket_server_setup(socket_conn * conn, uint16_t port, uint8_t num_connections);
52 
59 bool kprv_socket_server_accept(const socket_conn * server_conn, socket_conn * client_conn);
60 
67 bool kprv_socket_client_connect(socket_conn * conn, uint16_t port);
68 
74 bool kprv_socket_close(socket_conn * conn);
75 
83 bool kprv_socket_send(const socket_conn * conn, const uint8_t * data_buffer, uint32_t data_length);
84 
93 bool kprv_socket_recv(const socket_conn * conn, uint8_t * data_buffer, uint32_t data_length, uint32_t * length_read);
94 
95 /* @} */
bool kprv_socket_server_setup(socket_conn *conn, uint16_t port, uint8_t num_connections)
Performs the low level init and setup of the server side tcp socket.
bool kprv_socket_close(socket_conn *conn)
Performs low level shutdown and closure of connection.
bool kprv_socket_recv(const socket_conn *conn, uint8_t *data_buffer, uint32_t data_length, uint32_t *length_read)
Performs socket receive.
PubSub connection structure.
Definition: socket.h:34
int socket_handle
Definition: socket.h:39
bool kprv_socket_send(const socket_conn *conn, const uint8_t *data_buffer, uint32_t data_length)
Performs socket send.
bool kprv_socket_client_connect(socket_conn *conn, uint16_t port)
Attempts to open a socket connection.
bool kprv_socket_server_accept(const socket_conn *server_conn, socket_conn *client_conn)
Attempts to accept a new socket connection - currently blocking.
bool is_active
Definition: socket.h:37