Add support for FreeRTOS and lwIP (#166)

Add support for FreeRTOS and lwIP

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
Jeroen Koekkoek 2019-05-23 14:27:56 +02:00 committed by eboasson
parent dba4e6d391
commit aa2715f4fe
67 changed files with 3691 additions and 200 deletions

View file

@ -23,6 +23,7 @@ extern "C" {
#endif
/* LOG_THREAD_CPUTIME must be considered private. */
#if DDSRT_HAVE_RUSAGE
#define LOG_THREAD_CPUTIME(guard) \
do { \
if (dds_get_log_mask() & DDS_LC_TIMING) { \
@ -40,6 +41,9 @@ extern "C" {
} \
} \
} while (0)
#else
#define LOG_THREAD_CPUTIME(guard) (void)(guard)
#endif /* DDSRT_HAVE_RUSAGE */
#if defined (__cplusplus)
}

View file

@ -24,7 +24,7 @@
#include "dds/ddsrt/log.h"
#include "dds/ddsrt/sockets.h"
#ifdef __linux
#if defined(__linux) && !LWIP_SOCKET
#include <linux/if_packet.h>
#include <sys/types.h>
#include <ifaddrs.h>

View file

@ -368,7 +368,13 @@ static bool ddsi_tcp_select (ddsrt_socket_t sock, bool read, size_t pos)
int32_t ready = 0;
FD_ZERO (&fds);
#if LWIP_SOCKET == 1
DDSRT_WARNING_GNUC_OFF(sign-conversion)
#endif
FD_SET (sock, &fds);
#if LWIP_SOCKET == 1
DDSRT_WARNING_GNUC_ON(sign-conversion)
#endif
DDS_LOG(DDS_LC_TCP, "%s blocked %s: sock %d\n", ddsi_name, read ? "read" : "write", (int) sock);
do {

View file

@ -118,13 +118,14 @@ static uint32_t threadmon_thread (struct ddsi_threadmon *sl)
was_alive = false;
}
#if DDSRT_HAVE_RUSAGE
if (dds_get_log_mask() & DDS_LC_TIMING)
{
ddsrt_rusage_t u;
if (ddsrt_getrusage (DDSRT_RUSAGE_SELF, &u) == DDS_RETCODE_OK)
{
DDS_LOG(DDS_LC_TIMING,
"rusage: utime %d.%09d stime %d.%09d maxrss %ld data %ld vcsw %ld ivcsw %ld\n",
"rusage: utime %d.%09d stime %d.%09d maxrss %zu data %zu vcsw %zu ivcsw %zu\n",
(int) (u.utime / DDS_NSECS_IN_SEC),
(int) (u.utime % DDS_NSECS_IN_SEC),
(int) (u.stime / DDS_NSECS_IN_SEC),
@ -132,6 +133,7 @@ static uint32_t threadmon_thread (struct ddsi_threadmon *sl)
u.maxrss, u.idrss, u.nvcsw, u.nivcsw);
}
}
#endif /* DDSRT_HAVE_RUSAGE */
/* While deaf, we need to make sure the receive thread wakes up
every now and then to try recreating sockets & rejoining multicast

View file

@ -138,9 +138,10 @@ static ssize_t ddsi_udp_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *d
#if DDSRT_MSGHDR_FLAGS
msg.msg_flags = (int) flags;
#else
msg.msg_flags = 0;
DDSRT_UNUSED_ARG(flags);
#endif
#ifdef MSG_NOSIGNAL
#if MSG_NOSIGNAL && !LWIP_SOCKET
sendflags |= MSG_NOSIGNAL;
#endif
do {

View file

@ -96,12 +96,18 @@ static int set_rcvbuf (ddsrt_socket_t socket)
uint32_t ReceiveBufferSize;
socklen_t optlen = (socklen_t) sizeof (ReceiveBufferSize);
uint32_t socket_min_rcvbuf_size;
dds_retcode_t rc;
if (config.socket_min_rcvbuf_size.isdefault)
socket_min_rcvbuf_size = 1048576;
else
socket_min_rcvbuf_size = config.socket_min_rcvbuf_size.value;
if (ddsrt_getsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) &ReceiveBufferSize, &optlen) != DDS_RETCODE_OK)
{
rc = ddsrt_getsockopt(
socket, SOL_SOCKET, SO_RCVBUF, (char *) &ReceiveBufferSize, &optlen);
/* TCP/IP stack may not support SO_RCVBUF. */
if (rc == DDS_RETCODE_BAD_PARAMETER) {
DDS_LOG(DDS_LC_CONFIG, "cannot retrieve socket receive buffer size\n");
return 0;
} else if (rc != DDS_RETCODE_OK) {
print_sockerror ("get SO_RCVBUF");
return -2;
}
@ -139,8 +145,13 @@ static int set_sndbuf (ddsrt_socket_t socket)
{
unsigned SendBufferSize;
socklen_t optlen = (socklen_t) sizeof(SendBufferSize);
if (ddsrt_getsockopt(socket, SOL_SOCKET, SO_SNDBUF,(char *)&SendBufferSize, &optlen) != DDS_RETCODE_OK)
{
dds_retcode_t rc;
rc = ddsrt_getsockopt(
socket, SOL_SOCKET, SO_SNDBUF,(char *)&SendBufferSize, &optlen);
if (rc == DDS_RETCODE_BAD_PARAMETER) {
DDS_LOG(DDS_LC_CONFIG, "cannot retrieve socket send buffer size\n");
return 0;
} else if (rc != DDS_RETCODE_OK) {
print_sockerror ("get SO_SNDBUF");
return -2;
}
@ -191,12 +202,16 @@ static int set_reuse_options (ddsrt_socket_t socket)
/* Set REUSEADDR (if available on platform) for
multicast sockets, leave unicast sockets alone. */
int one = 1;
if (ddsrt_setsockopt (socket, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof (one)) != DDS_RETCODE_OK)
{
dds_retcode_t rc = ddsrt_setsockopt (
socket, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof (one));
if (rc == DDS_RETCODE_BAD_PARAMETER) {
DDS_LOG(DDS_LC_CONFIG, "cannot enable address reuse on socket\n");
return 0;
} else if (rc != DDS_RETCODE_OK) {
print_sockerror ("SO_REUSEADDR");
return -2;
}
return 0;
}
@ -266,7 +281,7 @@ static int set_mc_options_transmit_ipv4 (ddsrt_socket_t socket)
unsigned char loop;
dds_retcode_t ret;
#if defined __linux || defined __APPLE__
#if (defined(__linux) || defined(__APPLE__)) && !LWIP_SOCKET
if (config.use_multicast_if_mreqn)
{
struct ip_mreqn mreqn;
@ -470,7 +485,7 @@ int find_own_ip (const char *requested_address)
continue;
}
#ifdef __linux
#if defined(__linux) && !LWIP_SOCKET
if (ifa->addr->sa_family == AF_PACKET)
{
/* FIXME: weirdo warning warranted */

View file

@ -509,7 +509,7 @@ int os_sockWaitsetNextEvent (os_sockWaitsetCtx ctx, ddsi_tran_conn_t * conn)
#define OSPL_PIPENAMESIZE 26
#endif
#ifndef _WIN32
#if !_WIN32 && !LWIP_SOCKET
#ifndef __VXWORKS__
#include <sys/fcntl.h>
@ -524,7 +524,7 @@ int os_sockWaitsetNextEvent (os_sockWaitsetCtx ctx, ddsi_tran_conn_t * conn)
#include <fcntl.h>
#endif
#endif /* _WIN32 */
#endif /* !_WIN32 && !LWIP_SOCKET */
typedef struct os_sockWaitsetSet
{
@ -586,7 +586,7 @@ fail:
closesocket (s2);
return -1;
}
#elif defined (VXWORKS_RTP) || defined (_WRS_KERNEL)
#elif defined(__VXWORKS__)
static int make_pipe (int pfd[2])
{
char pipename[OSPL_PIPENAMESIZE];
@ -609,7 +609,7 @@ fail_open0:
fail_pipedev:
return -1;
}
#else
#elif !defined(LWIP_SOCKET)
static int make_pipe (int pfd[2])
{
return pipe (pfd);
@ -644,7 +644,11 @@ os_sockWaitset os_sockWaitsetNew (void)
ws->fdmax_plus_1 = FD_SETSIZE;
#endif
#if defined (VXWORKS_RTP) || defined (_WRS_KERNEL)
#if defined(LWIP_SOCKET)
ws->pipe[0] = -1;
ws->pipe[1] = -1;
result = 0;
#elif defined(__VXWORKS__)
int make_pipe (int pfd[2])
{
char pipename[OSPL_PIPENAMESIZE];
@ -679,15 +683,21 @@ os_sockWaitset os_sockWaitsetNew (void)
assert (result != -1);
(void) result;
#if !defined(LWIP_SOCKET)
ws->set.fds[0] = ws->pipe[0];
#else
ws->set.fds[0] = 0;
#endif
ws->set.conns[0] = NULL;
#if ! defined (VXWORKS_RTP) && ! defined ( _WRS_KERNEL ) && ! defined (_WIN32)
#if !defined(__VXWORKS__) && !defined(_WIN32) && !defined(LWIP_SOCKET)
fcntl (ws->pipe[0], F_SETFD, fcntl (ws->pipe[0], F_GETFD) | FD_CLOEXEC);
fcntl (ws->pipe[1], F_SETFD, fcntl (ws->pipe[1], F_GETFD) | FD_CLOEXEC);
#endif
#if !defined(LWIP_SOCKET)
FD_SET (ws->set.fds[0], &ws->ctx.rdset);
#if ! defined (_WIN32)
#endif
#if !defined(_WIN32)
ws->fdmax_plus_1 = ws->set.fds[0] + 1;
#endif
@ -716,18 +726,18 @@ static void os_sockWaitsetFreeCtx (os_sockWaitsetCtx ctx)
void os_sockWaitsetFree (os_sockWaitset ws)
{
#ifdef VXWORKS_RTP
#if defined(__VXWORKS__) && defined(__RTP__)
char nameBuf[OSPL_PIPENAMESIZE];
ioctl (ws->pipe[0], FIOGETNAME, &nameBuf);
#endif
#if defined (_WIN32)
#if defined(_WIN32)
closesocket (ws->pipe[0]);
closesocket (ws->pipe[1]);
#else
#elif !defined(LWIP_SOCKET)
close (ws->pipe[0]);
close (ws->pipe[1]);
#endif
#ifdef VXWORKS_RTP
#if defined(__VXWORKS__) && defined(__RTP__)
pipeDevDelete ((char*) &nameBuf, 0);
#endif
os_sockWaitsetFreeSet (&ws->set);
@ -738,6 +748,9 @@ void os_sockWaitsetFree (os_sockWaitset ws)
void os_sockWaitsetTrigger (os_sockWaitset ws)
{
#if defined(LWIP_SOCKET)
(void)ws;
#else
char buf = 0;
int n;
@ -750,6 +763,7 @@ void os_sockWaitsetTrigger (os_sockWaitset ws)
{
DDS_WARNING("os_sockWaitsetTrigger: write failed on trigger pipe\n");
}
#endif
}
int os_sockWaitsetAdd (os_sockWaitset ws, ddsi_tran_conn_t conn)
@ -863,10 +877,19 @@ os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws)
rdset = &ctx->rdset;
FD_ZERO (rdset);
#if !defined(LWIP_SOCKET)
for (u = 0; u < dst->n; u++)
{
FD_SET (dst->fds[u], rdset);
}
#else
for (u = 1; u < dst->n; u++)
{
DDSRT_WARNING_GNUC_OFF(sign-conversion)
FD_SET (dst->fds[u], rdset);
DDSRT_WARNING_GNUC_ON(sign-conversion)
}
#endif /* LWIP_SOCKET */
do
{
@ -883,6 +906,7 @@ os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws)
{
/* this simply skips the trigger fd */
ctx->index = 1;
#if ! defined(LWIP_SOCKET)
if (FD_ISSET (dst->fds[0], rdset))
{
char buf;
@ -898,19 +922,26 @@ os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws)
assert (0);
}
}
#endif /* LWIP_SOCKET */
return ctx;
}
return NULL;
}
#if defined(LWIP_SOCKET)
DDSRT_WARNING_GNUC_OFF(sign-conversion)
#endif
int os_sockWaitsetNextEvent (os_sockWaitsetCtx ctx, ddsi_tran_conn_t * conn)
{
while (ctx->index < ctx->set.n)
{
unsigned idx = ctx->index++;
ddsrt_socket_t fd = ctx->set.fds[idx];
#if ! defined (LWIP_SOCKET)
assert(idx > 0);
#endif
if (FD_ISSET (fd, &ctx->rdset))
{
*conn = ctx->set.conns[idx];
@ -921,6 +952,10 @@ int os_sockWaitsetNextEvent (os_sockWaitsetCtx ctx, ddsi_tran_conn_t * conn)
return -1;
}
#if defined(LWIP_SOCKET)
DDSRT_WARNING_GNUC_ON(sign-conversion)
#endif
#else
#error "no mode selected"
#endif

View file

@ -20,7 +20,7 @@
#include "dds/ddsi/q_config.h"
#include "dds/ddsi/sysdeps.h"
#if !(defined __APPLE__ || defined __linux) || (__GNUC__ > 0 && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40100)
#if DDSRT_WITH_FREERTOS || !(defined __APPLE__ || defined __linux) || (__GNUC__ > 0 && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40100)
void log_stacktrace (const char *name, ddsrt_thread_t tid)
{
DDSRT_UNUSED_ARG (name);