reactor-c
C Runtime for Lingua Franca
|
#include <sys/socket.h>
#include <regex.h>
#include <sys/types.h>
#include <stdbool.h>
#include "low_level_platform.h"
#include "tag.h"
Go to the source code of this file.
Macros | |
#define | NUM_SOCKET_RETRIES 10 |
#define | DELAY_BETWEEN_SOCKET_RETRIES MSEC(100) |
#define | HOST_LITTLE_ENDIAN 1 |
#define | HOST_BIG_ENDIAN 2 |
Functions | |
int | host_is_big_endian (void) |
void | encode_int64 (int64_t data, unsigned char *buffer) |
void | encode_int32 (int32_t data, unsigned char *buffer) |
void | encode_uint32 (uint32_t data, unsigned char *buffer) |
void | encode_uint16 (uint16_t data, unsigned char *buffer) |
int32_t | swap_bytes_if_big_endian_int32 (int32_t src) |
int64_t | swap_bytes_if_big_endian_int64 (int64_t src) |
uint16_t | swap_bytes_if_big_endian_uint16 (uint16_t src) |
int32_t | extract_int32 (unsigned char *bytes) |
int64_t | extract_int64 (unsigned char *bytes) |
uint16_t | extract_uint16 (unsigned char *bytes) |
Copyright (c) 2020, The University of California at Berkeley.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Header file for network utility functions for Lingua Franca programs. Note that these functions do not acquire any mutexes. To use them, you must ensure either that only one thread ever sends on each socket and one thread receives on each socket (these two can be the same thread) or that the caller handles mutual exclusion to prevent more than one thread from accessing the socket at a time.
#define DELAY_BETWEEN_SOCKET_RETRIES MSEC(100) |
#define HOST_BIG_ENDIAN 2 |
#define HOST_LITTLE_ENDIAN 1 |
#define NUM_SOCKET_RETRIES 10 |
void encode_int32 | ( | int32_t | data, |
unsigned char * | buffer ) |
Write the specified data as a sequence of bytes starting at the specified address. This encodes the data in little-endian order (lowest order byte first). This works for int32_t.
data | The data to write. |
buffer | The location to start writing. |
void encode_int64 | ( | int64_t | data, |
unsigned char * | buffer ) |
Write the specified data as a sequence of bytes starting at the specified address. This encodes the data in little-endian order (lowest order byte first).
data | The data to write. |
buffer | The location to start writing. |
void encode_uint16 | ( | uint16_t | data, |
unsigned char * | buffer ) |
Write the specified data as a sequence of bytes starting at the specified address. This encodes the data in little-endian order (lowest order byte first).
data | The data to write. |
buffer | The location to start writing. |
void encode_uint32 | ( | uint32_t | data, |
unsigned char * | buffer ) |
Write the specified data as a sequence of bytes starting at the specified address. This encodes the data in little-endian order (lowest order byte first). This works for uint32_t.
data | The data to write. |
buffer | The location to start writing. |
int32_t extract_int32 | ( | unsigned char * | bytes | ) |
This will swap the order of the bytes if this machine is big endian.
bytes | The address of the start of the sequence of bytes. |
int64_t extract_int64 | ( | unsigned char * | bytes | ) |
This will swap the order of the bytes if this machine is big endian.
bytes | The address of the start of the sequence of bytes. |
uint16_t extract_uint16 | ( | unsigned char * | bytes | ) |
Extract an uint16_t from the specified byte sequence. This will swap the order of the bytes if this machine is big endian.
bytes | The address of the start of the sequence of bytes. |
int host_is_big_endian | ( | void | ) |
Return true (1) if the host is big endian. Otherwise, return false.
int32_t swap_bytes_if_big_endian_int32 | ( | int32_t | src | ) |
If this host is little endian, then reverse the order of the bytes of the argument. Otherwise, return the argument unchanged. This can be used to convert the argument to network order (big endian) and then back again. Network transmissions, by convention, are big endian, meaning that the high-order byte is sent first. But many platforms, including my Mac, are little endian, meaning that the low-order byte is first in memory.
src | The argument to convert. |
int64_t swap_bytes_if_big_endian_int64 | ( | int64_t | src | ) |
If this host is little endian, then reverse the order of the bytes of the argument. Otherwise, return the argument unchanged. This can be used to convert the argument to network order (big endian) and then back again. Network transmissions, by convention, are big endian, meaning that the high-order byte is sent first. But many platforms, including my Mac, are little endian, meaning that the low-order byte is first in memory.
src | The argument to convert. |
uint16_t swap_bytes_if_big_endian_uint16 | ( | uint16_t | src | ) |
If this host is little endian, then reverse the order of the bytes of the argument. Otherwise, return the argument unchanged. This can be used to convert the argument to network order (big endian) and then back again. Network transmissions, by convention, are big endian, meaning that the high-order byte is sent first. But many platforms, including my Mac, are little endian, meaning that the low-order byte is first in memory.
src | The argument to convert. |