Make posix.hh independent of reactor.hh

Move throw_system_error_on() and friends into it.
This commit is contained in:
Avi Kivity
2014-08-27 17:37:10 +03:00
parent 34667e8dfe
commit 268d24170d
2 changed files with 21 additions and 17 deletions

View File

@@ -5,7 +5,6 @@
#ifndef FILE_DESC_HH_
#define FILE_DESC_HH_
#include "reactor.hh"
#include "sstring.hh"
#include <unistd.h>
#include <assert.h>
@@ -13,6 +12,12 @@
#include <fcntl.h>
#include <sys/ioctl.h>
inline void throw_system_error_on(bool condition);
template <typename T>
inline void throw_kernel_error(T r);
class file_desc {
int _fd;
public:
@@ -82,6 +87,20 @@ private:
file_desc(int fd) : _fd(fd) {}
};
inline
void throw_system_error_on(bool condition) {
if (condition) {
throw std::system_error(errno, std::system_category());
}
}
template <typename T>
inline
void throw_kernel_error(T r) {
static_assert(std::is_signed<T>::value, "kernel error variables must be signed");
if (r < 0) {
throw std::system_error(-r, std::system_category());
}
}
#endif /* FILE_DESC_HH_ */

View File

@@ -27,6 +27,7 @@
#include <system_error>
#include <boost/lockfree/queue.hpp>
#include <boost/optional.hpp>
#include "posix.hh"
#include "apply.hh"
#include "sstring.hh"
@@ -335,22 +336,6 @@ future<T...> make_exception_future(std::exception_ptr ex) {
return future<T...>::do_make_exception_future(std::move(ex));
}
inline
void throw_system_error_on(bool condition) {
if (condition) {
throw std::system_error(errno, std::system_category());
}
}
template <typename T>
inline
void throw_kernel_error(T r) {
static_assert(std::is_signed<T>::value, "kernel error variables must be signed");
if (r < 0) {
throw std::system_error(-r, std::system_category());
}
}
struct free_deleter {
void operator()(void* p) { ::free(p); }
};