Brief description of class still missing. More...
#include <BeaconTimer.h>
Public Member Functions | |
BeaconTimer (uint16_t port, int beaconDelay=2000) | |
virtual bool | exec () |
Brief description of class still missing.
Full description of class still missing
BeaconTimer::BeaconTimer | ( | uint16_t | port, |
int | beaconDelay = 2000 |
||
) |
Description of constructor still missing
References GpCoreTools::Timer::setInterval().
: Timer() { setInterval(beaconDelay); _fd=socket(AF_INET,SOCK_DGRAM,0); if(_fd<0) { Log::write(0, "beacon socket error: [%i] %s\n", errno, strerror(errno)); CoreApplication::exit(2); } int optval=1; if(setsockopt(_fd,SOL_SOCKET,SO_BROADCAST,&optval,sizeof(optval)) < 0) { Log::write(0, "beacon broadcast: [%i] %s\n", errno, strerror(errno)); CoreApplication::exit(2); } _addr.sin_family=AF_INET; _addr.sin_addr.s_addr=Address::me().subnet().value(); _addr.sin_port=htons(port); }
bool BeaconTimer::exec | ( | ) | [virtual] |
Performs action after timeout. If it returns true the timer is not single shot, i.e. deleted right after exec().
Implements GpCoreTools::Timer.
{ if(_fd<0) { return false; } static const char * msg="WAUB"; if(sendto(_fd, msg, 4, 0,(struct sockaddr *) &_addr, sizeof(_addr))<0) { Log::write(0, "beacon sendto error: %s\n", strerror(errno)); } return true; }