use standard-C SIGINT handling instead of platform-specific one in throughput example
Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
parent
6e7e1ca448
commit
84a25ab92d
2 changed files with 6 additions and 63 deletions
|
@ -29,22 +29,11 @@ static int parse_args(int argc, char **argv, uint32_t *payloadSize, int *burstIn
|
||||||
static dds_entity_t prepare_dds(dds_entity_t *writer, const char *partitionName);
|
static dds_entity_t prepare_dds(dds_entity_t *writer, const char *partitionName);
|
||||||
static void finalize_dds(dds_entity_t participant, dds_entity_t writer, ThroughputModule_DataType sample);
|
static void finalize_dds(dds_entity_t participant, dds_entity_t writer, ThroughputModule_DataType sample);
|
||||||
|
|
||||||
/* Functions to handle Ctrl-C presses. */
|
static void sigint (int sig)
|
||||||
#ifdef _WIN32
|
|
||||||
#include <Windows.h>
|
|
||||||
static int CtrlHandler (DWORD fdwCtrlType)
|
|
||||||
{
|
|
||||||
done = true;
|
|
||||||
return true; /* Don't let other handlers handle this key */
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
struct sigaction oldAction;
|
|
||||||
static void CtrlHandler (int sig)
|
|
||||||
{
|
{
|
||||||
(void)sig;
|
(void)sig;
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -82,25 +71,11 @@ int main (int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register handler for Ctrl-C */
|
/* Register handler for Ctrl-C */
|
||||||
#ifdef _WIN32
|
signal (SIGINT, sigint);
|
||||||
SetConsoleCtrlHandler ((PHANDLER_ROUTINE) CtrlHandler, true);
|
|
||||||
#else
|
|
||||||
struct sigaction sat;
|
|
||||||
sat.sa_handler = CtrlHandler;
|
|
||||||
sigemptyset (&sat.sa_mask);
|
|
||||||
sat.sa_flags = 0;
|
|
||||||
sigaction (SIGINT, &sat, &oldAction);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Register the sample instance and write samples repeatedly or until time out */
|
/* Register the sample instance and write samples repeatedly or until time out */
|
||||||
start_writing(writer, &sample, burstInterval, burstSize, timeOut);
|
start_writing(writer, &sample, burstInterval, burstSize, timeOut);
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
SetConsoleCtrlHandler (0, false);
|
|
||||||
#else
|
|
||||||
sigaction (SIGINT, &oldAction, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
finalize_dds(participant, writer, sample);
|
finalize_dds(participant, writer, sample);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -61,24 +61,11 @@ static void process_samples(dds_entity_t reader, unsigned long long maxCycles);
|
||||||
static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName);
|
static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName);
|
||||||
static void finalize_dds(dds_entity_t participant);
|
static void finalize_dds(dds_entity_t participant);
|
||||||
|
|
||||||
/* Functions to handle Ctrl-C presses. */
|
static void sigint (int sig)
|
||||||
#ifdef _WIN32
|
|
||||||
#include <Windows.h>
|
|
||||||
static int CtrlHandler (DWORD fdwCtrlType)
|
|
||||||
{
|
{
|
||||||
dds_waitset_set_trigger (waitSet, true);
|
(void) sig;
|
||||||
done = true;
|
|
||||||
return true; /* Don't let other handlers handle this key */
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
struct sigaction oldAction;
|
|
||||||
static void CtrlHandler (int sig)
|
|
||||||
{
|
|
||||||
(void)sig;
|
|
||||||
dds_waitset_set_trigger (waitSet, true);
|
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -88,16 +75,6 @@ int main (int argc, char **argv)
|
||||||
dds_entity_t participant;
|
dds_entity_t participant;
|
||||||
dds_entity_t reader;
|
dds_entity_t reader;
|
||||||
|
|
||||||
/* Register handler for Ctrl-C */
|
|
||||||
#ifdef _WIN32
|
|
||||||
SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, true);
|
|
||||||
#else
|
|
||||||
struct sigaction sat;
|
|
||||||
sat.sa_handler = CtrlHandler;
|
|
||||||
sigemptyset(&sat.sa_mask);
|
|
||||||
sat.sa_flags = 0;
|
|
||||||
sigaction (SIGINT, &sat, &oldAction);
|
|
||||||
#endif
|
|
||||||
setvbuf (stdout, NULL, _IOLBF, 0);
|
setvbuf (stdout, NULL, _IOLBF, 0);
|
||||||
|
|
||||||
if (parse_args(argc, argv, &maxCycles, &partitionName) == EXIT_FAILURE)
|
if (parse_args(argc, argv, &maxCycles, &partitionName) == EXIT_FAILURE)
|
||||||
|
@ -113,21 +90,12 @@ int main (int argc, char **argv)
|
||||||
|
|
||||||
/* Process samples until Ctrl-C is pressed or until maxCycles */
|
/* Process samples until Ctrl-C is pressed or until maxCycles */
|
||||||
/* has been reached (0 = infinite) */
|
/* has been reached (0 = infinite) */
|
||||||
|
signal (SIGINT, sigint);
|
||||||
process_samples(reader, maxCycles);
|
process_samples(reader, maxCycles);
|
||||||
|
|
||||||
/* Finished, disable callbacks */
|
|
||||||
dds_set_status_mask (reader, 0);
|
dds_set_status_mask (reader, 0);
|
||||||
HandleMap__free (imap);
|
HandleMap__free (imap);
|
||||||
|
finalize_dds (participant);
|
||||||
#ifdef _WIN32
|
|
||||||
SetConsoleCtrlHandler (0, FALSE);
|
|
||||||
#else
|
|
||||||
sigaction (SIGINT, &oldAction, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Clean up */
|
|
||||||
finalize_dds(participant);
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue