mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-22 09:30:45 +00:00
Make posix.hh independent of reactor.hh
Move throw_system_error_on() and friends into it.
This commit is contained in:
21
posix.hh
21
posix.hh
@@ -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_ */
|
||||
|
||||
17
reactor.hh
17
reactor.hh
@@ -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); }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user