Commit 16dd62fc authored by Dominik Charousset's avatar Dominik Charousset

Make predicates for CALL_CFUN inline

parent d9e63574
...@@ -46,7 +46,6 @@ set(LIBCAF_IO_SRCS ...@@ -46,7 +46,6 @@ set(LIBCAF_IO_SRCS
src/tcp.cpp src/tcp.cpp
src/udp.cpp src/udp.cpp
src/native_socket.cpp src/native_socket.cpp
src/call_cfun.cpp
src/socket_guard.cpp src/socket_guard.cpp
) )
......
...@@ -21,22 +21,32 @@ ...@@ -21,22 +21,32 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include "caf/error.hpp"
#include "caf/io/network/native_socket.hpp" #include "caf/io/network/native_socket.hpp"
#include "caf/sec.hpp"
namespace caf { namespace caf {
namespace detail { namespace detail {
// Predicate for `ccall` meaning "expected result of f is 0". /// Predicate for `ccall` meaning "expected result of f is 0".
bool cc_zero(int value); inline bool cc_zero(int value) {
return value == 0;
}
// Predicate for `ccall` meaning "expected result of f is 1". /// Predicate for `ccall` meaning "expected result of f is 1".
bool cc_one(int value); inline bool cc_one(int value) {
return value == 1;
}
// Predicate for `ccall` meaning "expected result of f is not -1". /// Predicate for `ccall` meaning "expected result of f is not -1".
bool cc_not_minus1(int value); inline bool cc_not_minus1(int value) {
return value != -1;
}
// Predicate for `ccall` meaning "expected result of f is a valid socket". /// Predicate for `ccall` meaning "expected result of f is a valid socket".
bool cc_valid_socket(caf::io::network::native_socket fd); inline bool cc_valid_socket(caf::io::network::native_socket fd) {
return fd != caf::io::network::invalid_native_socket;
}
/// Calls a C functions and returns an error if `predicate(var)` returns false. /// Calls a C functions and returns an error if `predicate(var)` returns false.
#define CALL_CFUN(var, predicate, fun_name, expr) \ #define CALL_CFUN(var, predicate, fun_name, expr) \
...@@ -45,7 +55,7 @@ bool cc_valid_socket(caf::io::network::native_socket fd); ...@@ -45,7 +55,7 @@ bool cc_valid_socket(caf::io::network::native_socket fd);
return make_error(sec::network_syscall_failed, \ return make_error(sec::network_syscall_failed, \
fun_name, last_socket_error_as_string()) fun_name, last_socket_error_as_string())
// Calls a C functions and calls exit() if `predicate(var)` returns false. /// Calls a C functions and calls exit() if `predicate(var)` returns false.
#define CALL_CRITICAL_CFUN(var, predicate, funname, expr) \ #define CALL_CRITICAL_CFUN(var, predicate, funname, expr) \
auto var = expr; \ auto var = expr; \
if (!predicate(var)) { \ if (!predicate(var)) { \
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/call_cfun.hpp"
namespace caf {
namespace detail {
bool cc_zero(int value) {
return value == 0;
}
bool cc_one(int value) {
return value == 1;
}
bool cc_not_minus1(int value) {
return value != -1;
}
bool cc_valid_socket(caf::io::network::native_socket fd) {
return fd != caf::io::network::invalid_native_socket;
}
} // namespace detail
} // namespace caf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment