From a14096f4aec0c0af285a6fcb0d368001666b8765 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 19 Oct 2018 14:19:12 +0200 Subject: Use sendmsg and recvmsg instead of send and recv to receive one message at a time --- tests/main.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/main.cpp b/tests/main.cpp index d650128..2d1d505 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -15,29 +15,38 @@ int main() sibs::BootstrapConnection connection1(sibs::Ipv4("127.0.0.1", PORT)); bool gotData1 = false; - connection1.listen(key, [&gotData1](const sibs::DirectConnectionPeer *peer, const void *data, const sibs::usize size) + bool gotAsdf1 = false; + connection1.listen(key, [&gotData1, &gotAsdf1](const sibs::DirectConnectionPeer *peer, const void *data, const sibs::usize size) { if(size == 5 && strncmp((const char*)data, "hello", 5) == 0) gotData1 = true; + if(size == 4 && strncmp((const char*)data, "asdf", 4) == 0) + gotAsdf1 = true; return true; }); sibs::BootstrapConnection connection2(sibs::Ipv4("127.0.0.1", PORT)); bool gotData2 = false; - connection2.listen(key, [&gotData2](const sibs::DirectConnectionPeer *peer, const void *data, const sibs::usize size) + bool gotAsdf2 = false; + connection2.listen(key, [&gotData2, &gotAsdf2](const sibs::DirectConnectionPeer *peer, const void *data, const sibs::usize size) { if(size == 5 && strncmp((const char*)data, "hello", 5) == 0) gotData2 = true; + if(size == 4 && strncmp((const char*)data, "asdf", 4) == 0) + gotAsdf2 = true; return true; }); // wait until connection1 and connection2 receive each other as peers from bootstrap node std::this_thread::sleep_for(std::chrono::seconds(3)); connection1.put(key, "hello", 5); + connection1.put(key, "asdf", 4); std::this_thread::sleep_for(std::chrono::seconds(3)); REQUIRE(gotData1); + REQUIRE(gotAsdf1); REQUIRE(gotData2); + REQUIRE(gotAsdf2); return 0; } -- cgit v1.2.3