Browse Source

stash

cl-refactor
subtly 10 years ago
parent
commit
d1aa994f8e
  1. 2
      libp2p/UDP.h
  2. 15
      test/net.cpp

2
libp2p/UDP.h

@ -68,11 +68,13 @@ public:
UDPSocket(ba::io_service& _io, Handler& _host, unsigned _port): m_host(_host), m_socket(_io, bi::udp::endpoint(bi::udp::v4(), _port)) {};
virtual ~UDPSocket() { disconnect(); }
/// Socket will begin listening for and delivering packets
void connect()
{
bool no = false;
if (!m_started.compare_exchange_strong(no, true))
return;
m_closed = false;
doRead();
}

15
test/net.cpp

@ -28,6 +28,21 @@ using namespace dev::p2p;
namespace ba = boost::asio;
namespace bi = ba::ip;
class Kademlia: UDPSocketEvents
{
public:
Kademlia(): Worker("test",0), m_io(), m_socket(new UDPSocket<Kademlia, 1024>(m_io, *this, 30300)) {}
~Kademlia() { m_io.stop(); stopWorking(); }
void onDisconnected(UDPSocketFace*) {};
void onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytesConstRef _packet) { if (_packet.toString() == "AAAA") success = true; }
ba::io_service m_io;
shared_ptr<UDPSocket<Kademlia, 1024>> m_socket;
bool success = false;
};
class TestA: UDPSocketEvents, public Worker
{
public:

Loading…
Cancel
Save