Reduce usage of std::bind()
C++14 lambdas are easier to read, easier to debug,
and can usually be better optimized by the compiler.
Change-Id: I294f275904f91942a8de946fe63e77078a7608a6
diff --git a/tests/daemon/face/websocket-channel-fixture.hpp b/tests/daemon/face/websocket-channel-fixture.hpp
index 69b2e9b..e6e1e9f 100644
--- a/tests/daemon/face/websocket-channel-fixture.hpp
+++ b/tests/daemon/face/websocket-channel-fixture.hpp
@@ -38,7 +38,8 @@
{
protected:
shared_ptr<WebSocketChannel>
- makeChannel(const boost::asio::ip::address& addr, uint16_t port = 0, optional<size_t> mtu = nullopt) final
+ makeChannel(const boost::asio::ip::address& addr, uint16_t port = 0,
+ optional<size_t> mtu = nullopt) final
{
if (port == 0)
port = getNextPort();
@@ -55,7 +56,7 @@
listenerChannel = makeChannel(addr, 20030);
listenerChannel->setPingInterval(pingInterval);
listenerChannel->setPongTimeout(pongTimeout);
- listenerChannel->listen(bind(&WebSocketChannelFixture::listenerOnFaceCreated, this, _1));
+ listenerChannel->listen(std::bind(&WebSocketChannelFixture::listenerOnFaceCreated, this, _1));
}
void
@@ -65,9 +66,9 @@
client.clear_error_channels(websocketpp::log::elevel::all);
client.init_asio(&g_io);
- client.set_open_handler(bind(&WebSocketChannelFixture::clientHandleOpen, this, _1));
- client.set_message_handler(bind(&WebSocketChannelFixture::clientHandleMessage, this, _1, _2));
- client.set_ping_handler(bind(&WebSocketChannelFixture::clientHandlePing, this, _1, _2));
+ client.set_open_handler(std::bind(&WebSocketChannelFixture::clientHandleOpen, this, _1));
+ client.set_message_handler(std::bind(&WebSocketChannelFixture::clientHandleMessage, this, _1, _2));
+ client.set_ping_handler(std::bind(&WebSocketChannelFixture::clientHandlePing, this, _1, _2));
websocketpp::lib::error_code ec;
auto con = client.get_connection(FaceUri(listenerEp, "ws").toString(), ec);
@@ -100,20 +101,16 @@
listenerOnFaceCreated(const shared_ptr<Face>& newFace)
{
BOOST_REQUIRE(newFace != nullptr);
- newFace->afterReceiveInterest.connect(bind(&WebSocketChannelFixture::faceAfterReceiveInterest, this, _1));
+ newFace->afterReceiveInterest.connect([this] (const auto& interest, const auto&) {
+ faceReceivedInterests.push_back(interest);
+ limitedIo.afterOp();
+ });
connectFaceClosedSignal(*newFace, [this] { limitedIo.afterOp(); });
listenerFaces.push_back(newFace);
limitedIo.afterOp();
}
void
- faceAfterReceiveInterest(const Interest& interest)
- {
- faceReceivedInterests.push_back(interest);
- limitedIo.afterOp();
- }
-
- void
clientHandleOpen(websocketpp::connection_hdl hdl)
{
clientHandle = hdl;
@@ -131,8 +128,8 @@
clientHandlePing(websocketpp::connection_hdl, std::string)
{
auto now = time::steady_clock::now();
- if (m_prevPingRecvTime != time::steady_clock::TimePoint()) {
- measuredPingInterval = now - m_prevPingRecvTime;
+ if (m_prevPingRecvTime != time::steady_clock::time_point()) {
+ measuredPingIntervals.push_back(now - m_prevPingRecvTime);
}
m_prevPingRecvTime = now;
@@ -147,13 +144,13 @@
websocketpp::connection_hdl clientHandle;
std::vector<std::string> clientReceivedMessages;
- time::steady_clock::Duration measuredPingInterval;
+ std::vector<time::nanoseconds> measuredPingIntervals;
// set clientShouldPong to false to disable the pong response,
// which will eventually cause a timeout in listenerChannel
bool clientShouldPong = true;
private:
- time::steady_clock::TimePoint m_prevPingRecvTime;
+ time::steady_clock::time_point m_prevPingRecvTime;
};
} // namespace tests