Skip to content

Commit

Permalink
cdp: keep the ser_clock_gettime() inside the module
Browse files Browse the repository at this point in the history
- some oses want librt for it
  • Loading branch information
miconda committed May 6, 2016
1 parent 75a077e commit ab0a437
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion modules/cdp/routing.c
Expand Up @@ -34,7 +34,10 @@
*
*/

#include "../../ser_time.h"
#ifdef __OS_darwin
#include <mach/clock.h>
#include <mach/mach.h>
#endif

#include "routing.h"
#include "config.h"
Expand All @@ -47,6 +50,27 @@
extern dp_config *config; /**< Configuration for this diameter peer */
int gcount = 0;

/**
* portable implementation for clock_gettime(CLOCK_REALTIME, ts)
*/
int ser_clock_gettime(struct timespec *ts)
{
#ifdef __OS_darwin
clock_serv_t cclock;
mach_timespec_t mts;

/* OS X does not have clock_gettime, use clock_get_time */
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
ts->tv_sec = mts.tv_sec;
ts->tv_nsec = mts.tv_nsec;
return 0;
#else
return clock_gettime(CLOCK_REALTIME, ts);
#endif
}

/**
* Returns if the peer advertised support for an Application ID
* @param p - the peer to check
Expand Down

0 comments on commit ab0a437

Please sign in to comment.