[ovs-dev] [PATCH 2/4] lib: Add Mac OSX compatability

Thomas Graf tgraf at noironetworks.com
Fri Jan 23 11:37:37 UTC 2015


On 01/23/15 at 01:17am, Dave Tucker wrote:
> diff --git a/lib/socket-util.c b/lib/socket-util.c
> index 8949da7..732fd89 100644
> --- a/lib/socket-util.c
> +++ b/lib/socket-util.c
> @@ -112,6 +112,11 @@ set_dscp(int fd, uint8_t dscp)
>      return 0;
>  #endif
>  
> +#ifdef __APPLE__
> +    /* ToDo: Look at OSX QoS API */
> +    return 0;
> +#endif

I think IP_TOS should work fine on MacOSX [0]

[0] https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man4/ip.4.html

Maybe you can just #ifndef the TCLASS socket option call for OSX?

> diff --git a/lib/timeval.c b/lib/timeval.c
> index 6173aff..2c354de 100644
> --- a/lib/timeval.c
> +++ b/lib/timeval.c
> @@ -56,6 +56,19 @@ typedef unsigned int clockid_t;
>  const static unsigned long long unix_epoch = 116444736000000000;
>  #endif /* _WIN32 */
>  
> +#ifdef  __APPLE__
> +typedef unsigned int clockid_t;
> +
> +#ifndef CLOCK_MONOTONIC
> +#define CLOCK_MONOTONIC 0
> +#endif
> +
> +#ifndef CLOCK_REALTIME
> +#define CLOCK_REALTIME 0
> +#endif

An alternative would be to move the definitions for _WIN32 out of
the ifdef and use CLOCK_MONOTONIC=1 CLOCK_REALTIME=2 for both
WIN32 and OSX. I realize that it doesn't really mater for now as
both map to just a gettimeofday() call.

> +
> +#endif /* __APPLE__ */
> +
>  /* Structure set by unixctl time/warp command. */
>  struct large_warp {
>      struct unixctl_conn *conn; /* Connection waiting for warp response. */
> @@ -417,6 +430,19 @@ clock_gettime(clock_t id, struct timespec *ts)
>  }
>  #endif /* _WIN32 */
>  
> +#ifdef __APPLE__
> +//clock_gettime is not implemented on OSX
> +int
> +clock_gettime(clock_t id, struct timespec* ts) {
> +    struct timeval now;
> +    int rv = gettimeofday(&now, NULL);
> +    if (rv) return rv;
> +    ts->tv_sec  = now.tv_sec;
> +    ts->tv_nsec = now.tv_usec * 1000;
> +    return 0;
> +}

This needs some style changes ;-)



More information about the dev mailing list