Add timeout when receiving Multicast packet in LpdMessageDispatcherTest

pull/60/head
Tatsuhiro Tsujikawa 2013-03-21 21:38:55 +09:00
parent 0309d67aab
commit 15b19f7baf
1 changed files with 14 additions and 1 deletions

View File

@ -50,6 +50,7 @@ void LpdMessageDispatcherTest::testSendMessage()
recvsock->bind(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT, AF_INET); recvsock->bind(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT, AF_INET);
#endif // !__MINGW32__ #endif // !__MINGW32__
recvsock->joinMulticastGroup(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT, ""); recvsock->joinMulticastGroup(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT, "");
recvsock->setNonBlockingMode();
LpdMessageDispatcher d("cd41c7fdddfd034a15a04d7ff881216e01c4ceaf", 6000, LpdMessageDispatcher d("cd41c7fdddfd034a15a04d7ff881216e01c4ceaf", 6000,
LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT); LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT);
@ -60,7 +61,19 @@ void LpdMessageDispatcherTest::testSendMessage()
unsigned char buf[200]; unsigned char buf[200];
std::pair<std::string, uint16_t> peer; std::pair<std::string, uint16_t> peer;
ssize_t nbytes = recvsock->readDataFrom(buf, sizeof(buf), peer); ssize_t nbytes;
int trycnt;
for(trycnt = 0; trycnt < 5; ++trycnt) {
nbytes = recvsock->readDataFrom(buf, sizeof(buf), peer);
if(nbytes == 0) {
sleep(1);
} else {
break;
}
}
if(trycnt == 5) {
CPPUNIT_FAIL("[TIMEOUT] No Multicast packet received.");
}
buf[nbytes] = '\0'; buf[nbytes] = '\0';
std::stringstream temp; std::stringstream temp;
temp << "BT-SEARCH * HTTP/1.1\r\n" temp << "BT-SEARCH * HTTP/1.1\r\n"