Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
f9f8efc1
Commit
f9f8efc1
authored
Jul 10, 2018
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move C function call macros to detail namespace
parent
48cd826e
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
153 additions
and
113 deletions
+153
-113
libcaf_io/CMakeLists.txt
libcaf_io/CMakeLists.txt
+1
-0
libcaf_io/caf/detail/call_cfun.hpp
libcaf_io/caf/detail/call_cfun.hpp
+61
-0
libcaf_io/src/call_cfun.cpp
libcaf_io/src/call_cfun.cpp
+41
-0
libcaf_io/src/default_multiplexer.cpp
libcaf_io/src/default_multiplexer.cpp
+10
-45
libcaf_io/src/socket_utils.cpp
libcaf_io/src/socket_utils.cpp
+40
-68
No files found.
libcaf_io/CMakeLists.txt
View file @
f9f8efc1
...
...
@@ -46,6 +46,7 @@ set(LIBCAF_IO_SRCS
src/tcp.cpp
src/udp.cpp
src/socket_utils.cpp
src/call_cfun.cpp
)
add_custom_target
(
libcaf_io
)
...
...
libcaf_io/caf/detail/call_cfun.hpp
0 → 100644
View file @
f9f8efc1
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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. *
******************************************************************************/
#pragma once
#include "caf/io/network/native_socket.hpp"
namespace
caf
{
namespace
detail
{
// Predicate for `ccall` meaning "expected result of f is 0".
bool
cc_zero
(
int
value
);
// Predicate for `ccall` meaning "expected result of f is 1".
bool
cc_one
(
int
value
);
// Predicate for `ccall` meaning "expected result of f is not -1".
bool
cc_not_minus1
(
int
value
);
// Predicate for `ccall` meaning "expected result of f is a valid socket".
bool
cc_valid_socket
(
caf
::
io
::
network
::
native_socket
fd
);
/// Calls a C functions and returns an error if `predicate(var)` returns false.
#define CALL_CFUN(var, predicate, fun_name, expr) \
auto var = expr; \
if (!predicate(var)) \
return make_error(sec::network_syscall_failed, \
fun_name, last_socket_error_as_string())
#ifdef CAF_WINDOWS
// Calls a C functions and calls exit() if `predicate(var)` returns false.
#define CALL_CRITICAL_CFUN(var, predicate, funname, expr) \
auto var = expr; \
if (!predicate(var)) { \
fprintf(stderr, "[FATAL] %s:%u: syscall failed: %s returned %s\n", \
__FILE__, __LINE__, funname, last_socket_error_as_string().c_str());\
abort(); \
} static_cast<void>(0)
#ifndef SIO_UDP_CONNRESET
#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR, 12)
#endif
#endif // CAF_WINDOWS
}
// namespace detail
}
// namespace caf
libcaf_io/src/call_cfun.cpp
0 → 100644
View file @
f9f8efc1
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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
libcaf_io/src/default_multiplexer.cpp
View file @
f9f8efc1
...
...
@@ -32,6 +32,8 @@
#include "caf/io/network/doorman_impl.hpp"
#include "caf/io/network/datagram_servant_impl.hpp"
#include "caf/detail/call_cfun.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#ifdef CAF_WINDOWS
...
...
@@ -59,43 +61,6 @@ namespace {
constexpr
auto
ipv4
=
caf
::
io
::
network
::
protocol
::
ipv4
;
constexpr
auto
ipv6
=
caf
::
io
::
network
::
protocol
::
ipv6
;
// predicate for `ccall` meaning "expected result of f is 0"
bool
cc_zero
(
int
value
)
{
return
value
==
0
;
}
// predicate for `ccall` meaning "expected result of f is 1"
bool
cc_one
(
int
value
)
{
return
value
==
1
;
}
// predicate for `ccall` meaning "expected result of f is a valid socket"
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
#define CALL_CFUN(var, predicate, fun_name, expr) \
auto var = expr; \
if (!predicate(var)) \
return make_error(sec::network_syscall_failed, \
fun_name, last_socket_error_as_string())
#ifdef CAF_WINDOWS
// calls a C functions and calls exit() if `predicate(var)` returns false
#define CALL_CRITICAL_CFUN(var, predicate, funname, expr) \
auto var = expr; \
if (!predicate(var)) { \
fprintf(stderr, "[FATAL] %s:%u: syscall failed: %s returned %s\n", \
__FILE__, __LINE__, funname, last_socket_error_as_string().c_str());\
abort(); \
} static_cast<void>(0)
#ifndef SIO_UDP_CONNRESET
#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR, 12)
#endif
#endif // CAF_WINDOWS
}
// namespace <anonymous>
namespace
caf
{
...
...
@@ -759,7 +724,7 @@ new_tcp_connection(const std::string& host, uint16_t port,
}
auto
proto
=
res
->
second
;
CAF_ASSERT
(
proto
==
ipv4
||
proto
==
ipv6
);
CALL_CFUN
(
fd
,
cc_valid_socket
,
"socket"
,
CALL_CFUN
(
fd
,
detail
::
cc_valid_socket
,
"socket"
,
socket
(
proto
==
ipv4
?
AF_INET
:
AF_INET6
,
SOCK_STREAM
,
0
));
socket_guard
sguard
(
fd
);
if
(
proto
==
ipv6
)
{
...
...
@@ -783,7 +748,7 @@ new_tcp_connection(const std::string& host, uint16_t port,
template
<
class
SockAddrType
>
expected
<
void
>
read_port
(
native_socket
fd
,
SockAddrType
&
sa
)
{
socklen_t
len
=
sizeof
(
SockAddrType
);
CALL_CFUN
(
res
,
cc_zero
,
"getsockname"
,
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"getsockname"
,
getsockname
(
fd
,
reinterpret_cast
<
sockaddr
*>
(
&
sa
),
&
len
));
return
unit
;
}
...
...
@@ -797,7 +762,7 @@ expected<void> set_inaddr_any(native_socket fd, sockaddr_in6& sa) {
sa
.
sin6_addr
=
in6addr_any
;
// also accept ipv4 requests on this socket
int
off
=
0
;
CALL_CFUN
(
res
,
cc_zero
,
"setsockopt"
,
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
fd
,
IPPROTO_IPV6
,
IPV6_V6ONLY
,
reinterpret_cast
<
setsockopt_ptr
>
(
&
off
),
static_cast
<
socklen_t
>
(
sizeof
(
off
))));
...
...
@@ -809,12 +774,12 @@ expected<native_socket> new_ip_acceptor_impl(uint16_t port, const char* addr,
bool
reuse_addr
,
bool
any
)
{
static_assert
(
Family
==
AF_INET
||
Family
==
AF_INET6
,
"invalid family"
);
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
", addr = "
<<
(
addr
?
addr
:
"nullptr"
));
CALL_CFUN
(
fd
,
cc_valid_socket
,
"socket"
,
socket
(
Family
,
SockType
,
0
));
CALL_CFUN
(
fd
,
detail
::
cc_valid_socket
,
"socket"
,
socket
(
Family
,
SockType
,
0
));
// sguard closes the socket in case of exception
socket_guard
sguard
{
fd
};
if
(
reuse_addr
)
{
int
on
=
1
;
CALL_CFUN
(
tmp1
,
cc_zero
,
"setsockopt"
,
CALL_CFUN
(
tmp1
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
reinterpret_cast
<
setsockopt_ptr
>
(
&
on
),
static_cast
<
socklen_t
>
(
sizeof
(
on
))));
...
...
@@ -830,10 +795,10 @@ expected<native_socket> new_ip_acceptor_impl(uint16_t port, const char* addr,
family_of
(
sa
)
=
Family
;
if
(
any
)
set_inaddr_any
(
fd
,
sa
);
CALL_CFUN
(
tmp
,
cc_one
,
"inet_pton"
,
CALL_CFUN
(
tmp
,
detail
::
cc_one
,
"inet_pton"
,
inet_pton
(
Family
,
addr
,
&
addr_of
(
sa
)));
port_of
(
sa
)
=
htons
(
port
);
CALL_CFUN
(
res
,
cc_zero
,
"bind"
,
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"bind"
,
bind
(
fd
,
reinterpret_cast
<
sockaddr
*>
(
&
sa
),
static_cast
<
socklen_t
>
(
sizeof
(
sa
))));
return
sguard
.
release
();
...
...
@@ -868,7 +833,7 @@ expected<native_socket> new_tcp_acceptor_impl(uint16_t port, const char* addr,
port
,
addr_str
);
}
socket_guard
sguard
{
fd
};
CALL_CFUN
(
tmp2
,
cc_zero
,
"listen"
,
listen
(
fd
,
SOMAXCONN
));
CALL_CFUN
(
tmp2
,
detail
::
cc_zero
,
"listen"
,
listen
(
fd
,
SOMAXCONN
));
// ok, no errors so far
CAF_LOG_DEBUG
(
CAF_ARG
(
fd
));
return
sguard
.
release
();
...
...
libcaf_io/src/socket_utils.cpp
View file @
f9f8efc1
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment