diff --git a/libp2p/UDP.h b/libp2p/UDP.h index 74499da11..fd48aa59d 100644 --- a/libp2p/UDP.h +++ b/libp2p/UDP.h @@ -65,16 +65,16 @@ public: static_assert(datagramSize < 65507, "UDP datagrams cannot be larger than 65507 bytes"); /// Construct open socket to endpoint. - UDPSocket(ba::io_service& _io, Handler& _host, unsigned _port): m_host(_host), m_socket(_io, bi::udp::endpoint(bi::udp::v4(), _port)) {}; + UDPSocket(ba::io_service& _io, UDPSocketEvents& _host, unsigned _port): m_host(_host), m_socket(_io, bi::udp::endpoint(bi::udp::v4(), _port)) { m_started.store(false); m_closed.store(true); }; virtual ~UDPSocket() { disconnect(); } /// Socket will begin listening for and delivering packets void connect() { - bool no = false; - if (!m_started.compare_exchange_strong(no, true)) + bool expect = false; + if (!m_started.compare_exchange_strong(expect, true)) return; - + m_closed = false; doRead(); } @@ -86,7 +86,7 @@ public: Guard l(x_sendQ); sendQ.push_back(_datagram); - if (sendQ.size() == 1 && !m_closed) + if (sendQ.size() == 1 && !m_closed.load()) doWrite(); } diff --git a/test/net.cpp b/test/net.cpp index 1e8d20c54..34b20ccc7 100644 --- a/test/net.cpp +++ b/test/net.cpp @@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE(test_txrx_one) d.to = boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 30300); d.data = bytes({65,65,65,65}); - TestA a; a.start(); a.m_socket->connect(); + TestA a; a.m_socket->connect(); a.start(); a.m_socket->send(d); sleep(1); BOOST_REQUIRE_EQUAL(true, a.success);