[lib-result] example: handle signals
Handle signals in the sample program owlps-resultreader-udp.
This commit is contained in:
parent
6fa903b143
commit
626242b5e2
|
@ -7,18 +7,31 @@
|
||||||
|
|
||||||
#include "owlps-resultreader-udp.h"
|
#include "owlps-resultreader-udp.h"
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
struct sigaction action ; // Signal handler structure
|
||||||
owl_result *result ;
|
owl_result *result ;
|
||||||
int sockfd ;
|
int sockfd ;
|
||||||
|
|
||||||
|
/* Set up signal handlers */
|
||||||
|
action.sa_flags = 0 ;
|
||||||
|
sigemptyset(&action.sa_mask) ;
|
||||||
|
action.sa_handler = owl_sigint_handler ;
|
||||||
|
sigaction(SIGINT, &action, NULL) ;
|
||||||
|
action.sa_handler = owl_sigterm_handler ;
|
||||||
|
sigaction(SIGTERM, &action, NULL) ;
|
||||||
|
|
||||||
|
/* Open the socket */
|
||||||
sockfd = owl_create_udp_listening_socket(MOBILE_DEFAULT_PORT) ;
|
sockfd = owl_create_udp_listening_socket(MOBILE_DEFAULT_PORT) ;
|
||||||
if (sockfd < 0)
|
if (sockfd < 0)
|
||||||
return 1 ;
|
return 1 ;
|
||||||
|
|
||||||
while (1)
|
/* Read loop */
|
||||||
|
owl_run = TRUE ;
|
||||||
|
while (owl_run)
|
||||||
{
|
{
|
||||||
if (! (result = owl_receive_position(sockfd)))
|
if (! (result = owl_receive_position(sockfd)))
|
||||||
return 1 ;
|
return 1 ;
|
||||||
|
@ -27,6 +40,7 @@ int main(void)
|
||||||
printf("--------------\n") ;
|
printf("--------------\n") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Cleaning */
|
||||||
close(sockfd) ;
|
close(sockfd) ;
|
||||||
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
|
|
Loading…
Reference in New Issue