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 void finalize_dds(dds_entity_t participant, dds_entity_t writer, ThroughputModule_DataType sample);
 | 
			
		||||
 | 
			
		||||
/* Functions to handle Ctrl-C presses. */
 | 
			
		||||
#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)
 | 
			
		||||
static void sigint (int sig)
 | 
			
		||||
{
 | 
			
		||||
  (void)sig;
 | 
			
		||||
  done = true;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int main (int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -82,25 +71,11 @@ int main (int argc, char **argv)
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  /* 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
 | 
			
		||||
  signal (SIGINT, sigint);
 | 
			
		||||
 | 
			
		||||
  /* Register the sample instance and write samples repeatedly or until time out */
 | 
			
		||||
  start_writing(writer, &sample, burstInterval, burstSize, timeOut);
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
  SetConsoleCtrlHandler (0, false);
 | 
			
		||||
#else
 | 
			
		||||
  sigaction (SIGINT, &oldAction, 0);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  /* Cleanup */
 | 
			
		||||
  finalize_dds(participant, writer, sample);
 | 
			
		||||
  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 void finalize_dds(dds_entity_t participant);
 | 
			
		||||
 | 
			
		||||
/* Functions to handle Ctrl-C presses. */
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
#include <Windows.h>
 | 
			
		||||
static int CtrlHandler (DWORD fdwCtrlType)
 | 
			
		||||
static void sigint (int sig)
 | 
			
		||||
{
 | 
			
		||||
  dds_waitset_set_trigger (waitSet, true);
 | 
			
		||||
  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);
 | 
			
		||||
  (void) sig;
 | 
			
		||||
  done = true;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int main (int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -88,16 +75,6 @@ int main (int argc, char **argv)
 | 
			
		|||
  dds_entity_t participant;
 | 
			
		||||
  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);
 | 
			
		||||
 | 
			
		||||
  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 */
 | 
			
		||||
  /* has been reached (0 = infinite) */
 | 
			
		||||
  signal (SIGINT, sigint);
 | 
			
		||||
  process_samples(reader, maxCycles);
 | 
			
		||||
 | 
			
		||||
  /* Finished, disable callbacks */
 | 
			
		||||
  dds_set_status_mask (reader, 0);
 | 
			
		||||
  HandleMap__free (imap);
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
  SetConsoleCtrlHandler (0, FALSE);
 | 
			
		||||
#else
 | 
			
		||||
  sigaction (SIGINT, &oldAction, 0);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  /* Clean up */
 | 
			
		||||
  finalize_dds(participant);
 | 
			
		||||
 | 
			
		||||
  finalize_dds (participant);
 | 
			
		||||
  return EXIT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue