#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <rtdk.h>
pthread_t svtid, cltid;
#define BUFP_SVPORT 12
static const char *msg[] = {
"Surfing With The Alien",
"Lords of Karma",
"Banana Mango",
"Psycho Monkey",
"Luminous Flesh Giants",
"Moroccan Sunset",
"Satch Boogie",
"Flying In A Blue Dream",
"Ride",
"Summer Song",
"Speed Of Light",
"Crystal Planet",
"Raspberry Jam Delta-V",
"Champagne?",
"Clouds Race Across The Sky",
"Engines Of Creation"
};
static void fail(const char *reason)
{
perror(reason);
exit(EXIT_FAILURE);
}
static void *server(void *arg)
{
char buf[128];
size_t bufsz;
int ret, s;
if (s < 0)
fail("socket");
bufsz = 16384;
&bufsz, sizeof(bufsz));
if (ret)
fail("setsockopt");
saddr.sipc_family = AF_RTIPC;
saddr.sipc_port = BUFP_SVPORT;
ret = bind(s, (struct sockaddr *)&saddr, sizeof(saddr));
if (ret)
fail("bind");
for (;;) {
ret = read(s, buf, sizeof(buf));
if (ret < 0) {
fail("read");
}
rt_printf("%s: received %d bytes, \"%.*s\"\n",
__FUNCTION__, ret, ret, buf);
}
return NULL;
}
static void *client(void *arg)
{
int ret, s, n = 0, len;
struct timespec ts;
if (s < 0)
fail("socket");
memset(&svsaddr, 0, sizeof(svsaddr));
svsaddr.sipc_family = AF_RTIPC;
svsaddr.sipc_port = BUFP_SVPORT;
ret = connect(s, (struct sockaddr *)&svsaddr, sizeof(svsaddr));
if (ret)
fail("connect");
for (;;) {
len = strlen(msg[n]);
ret = write(s, msg[n], len);
if (ret < 0) {
fail("write");
}
rt_printf("%s: sent %d bytes, \"%.*s\"\n",
__FUNCTION__, ret, ret, msg[n]);
n = (n + 1) % (sizeof(msg) / sizeof(msg[0]));
ts.tv_sec = 0;
ts.tv_nsec = 500000000;
}
return NULL;
}
static void cleanup_upon_sig(int sig)
{
signal(sig, SIG_DFL);
}
int main(int argc, char **argv)
{
struct sched_param svparam = {.sched_priority = 71 };
struct sched_param clparam = {.sched_priority = 70 };
pthread_attr_t svattr, clattr;
sigset_t mask, oldmask;
mlockall(MCL_CURRENT | MCL_FUTURE);
signal(SIGINT, cleanup_upon_sig);
signal(SIGTERM, cleanup_upon_sig);
signal(SIGHUP, cleanup_upon_sig);
rt_print_auto_init(1);
if (errno)
fail("pthread_create");
if (errno)
fail("pthread_create");
sigsuspend(&oldmask);
return 0;
}