1 #ifndef VTESTBED_SERVER_CLIENT_HH 2 #define VTESTBED_SERVER_CLIENT_HH 7 #include <unistdx/base/log_message> 8 #include <unistdx/io/poller> 9 #include <unistdx/net/socket> 11 #include <vtestbed/core/testbed.hh> 12 #include <vtestbed/server/macros.hh> 13 #include <vtestbed/server/remote_client.hh> 25 typedef clock_type::duration duration;
26 typedef clock_type::time_point time_point;
33 sys::event_poller _poller;
36 bool _verbose =
false;
43 Client(
const sys::socket_address& address):
44 _client(sys::socket(), address,
false)
47 template <
class Handler>
49 run(Handler handler) {
53 for (
const sys::epoll_event& ev : _poller) {
54 if (ev.fd() == _client.socket().fd()) {
56 _client.process(ev, _testbed);
57 handler.on_receive(_testbed);
60 this->info(
"disconnect from _", _client.address());
66 if (_client.handshake()) {
67 handler.on_handshake(_client);
75 this->info(
"connect to _", _client.address());
77 _client.socket().connect(_client.address());
78 #if defined(UNISTDX_HAVE_TCP_USER_TIMEOUT) 79 VTB_WARN(_client.socket().set_user_timeout(_timeout));
81 }
catch (
const sys::bad_call& err) {
82 if (err.errc() != std::errc::operation_in_progress) {
86 _poller.emplace(_client.socket().fd(), sys::event::in);
96 verbose()
const noexcept {
107 inline const testbed_type&
113 push(
const testbed_type&
testbed) {
114 lock_type lock(_mutex);
116 _poller.notify_one();
119 inline const client_type&
120 client() const noexcept {
131 template <
class ... Args>
133 info(
const Args& ... args) {
134 sys::log_message(
"client", args ...);
143 #endif // vim:filetype=cpp
const testbed_type & testbed() const noexcept
Virtual testbed object received from the server.
testbed_type & testbed() noexcept
Virtual testbed object received from the server.