Browse Source

initialize atomics so udp messages are delivered on linux #656

cl-refactor
subtly 10 years ago
parent
commit
27d79a2f17
  1. 8
      libp2p/UDP.h
  2. 2
      test/net.cpp

8
libp2p/UDP.h

@ -65,14 +65,14 @@ 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;
@ -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();
}

2
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);

Loading…
Cancel
Save