mirror of
https://github.com/aria2/aria2.git
synced 2025-04-06 14:07:37 +03:00
Refactor SocketCore::getPeerInfo, getAddrInfo to return Endpoint object
This commit is contained in:
parent
e899eba76f
commit
ea4d99ea08
19 changed files with 91 additions and 109 deletions
|
@ -43,26 +43,30 @@ void SocketCoreTest::testWriteAndReadDatagram()
|
|||
SocketCore c(SOCK_DGRAM);
|
||||
c.bind(0);
|
||||
|
||||
std::pair<std::string, uint16_t> svaddr;
|
||||
s.getAddrInfo(svaddr);
|
||||
auto remoteEndpoint = s.getAddrInfo();
|
||||
|
||||
std::string message1 = "hello world.";
|
||||
c.writeData(message1.c_str(), message1.size(), "localhost", svaddr.second);
|
||||
c.writeData(message1.c_str(), message1.size(), "localhost",
|
||||
remoteEndpoint.port);
|
||||
std::string message2 = "chocolate coated pie";
|
||||
c.writeData(message2.c_str(), message2.size(), "localhost", svaddr.second);
|
||||
c.writeData(message2.c_str(), message2.size(), "localhost",
|
||||
remoteEndpoint.port);
|
||||
|
||||
char readbuffer[100];
|
||||
std::pair<std::string, uint16_t> peer;
|
||||
|
||||
{
|
||||
ssize_t rlength = s.readDataFrom(readbuffer, sizeof(readbuffer), peer);
|
||||
ssize_t rlength =
|
||||
s.readDataFrom(readbuffer, sizeof(readbuffer), remoteEndpoint);
|
||||
// commented out because ip address may vary
|
||||
// CPPUNIT_ASSERT_EQUAL(std::std::string("127.0.0.1"), peer.first);
|
||||
// CPPUNIT_ASSERT_EQUAL(std::std::string("127.0.0.1"),
|
||||
// remoteEndpoint.addr);
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)message1.size(), rlength);
|
||||
readbuffer[rlength] = '\0';
|
||||
CPPUNIT_ASSERT_EQUAL(message1, std::string(readbuffer));
|
||||
}
|
||||
{
|
||||
ssize_t rlength = s.readDataFrom(readbuffer, sizeof(readbuffer), peer);
|
||||
ssize_t rlength =
|
||||
s.readDataFrom(readbuffer, sizeof(readbuffer), remoteEndpoint);
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)message2.size(), rlength);
|
||||
readbuffer[rlength] = '\0';
|
||||
CPPUNIT_ASSERT_EQUAL(message2, std::string(readbuffer));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue