Define posixCall

Define Documentation

posixCall(f)

Calling a posix function with automated error handling. If the posix function returns void you do not need to use posixCall since it cannot fail, (see: man errno). We use a builder pattern to create a design which sets the usage contract so that it cannot be used in the wrong way.

iox::posix::posixCall(sem_timedwait)(handle, timeout)
     .successReturnValue(0)
     .ignoreErrnos(ETIMEDOUT) // can be a comma separated list of errnos
     .evaluate()
     .and_then([](auto & result){
         std::cout << result.value << std::endl; // return value of sem_timedwait
         std::cout << result.errno << std::endl; // errno which was set by sem_timedwait
         std::cout << result.getHumanReadableErrnum() << std::endl; // get string returned by strerror(errno)
     })
     .or_else([](auto & result){
         std::cout << result.value << std::endl; // return value of sem_timedwait
         std::cout << result.errno << std::endl; // errno which was set by sem_timedwait
         std::cout << result.getHumanReadableErrnum() << std::endl; // get string returned by strerror(errno)
     })

// when your posix call signals failure with one specific return value use
// .failureReturnValue(_) instead of .successReturnValue(_)
// when your posix call signals failure by returning the errno value instead of setting the errno use
// .returnValueMatchesErrno() instead of .successReturnValue(_)