W5200(WIZ820io) network interface
Diff: MyNetDnsRequest.cpp
- Revision:
- 2:a8df39b4f3aa
- Parent:
- 1:803123933c5a
--- a/MyNetDnsRequest.cpp Tue Apr 17 12:13:15 2012 +0000 +++ b/MyNetDnsRequest.cpp Thu Apr 19 11:14:43 2012 +0000 @@ -1,10 +1,18 @@ -// MyNetDnsRequest.cpp 2012/4/16 +// MyNetDnsRequest.cpp 2012/4/19 #include "mbed.h" #include "MyNetDnsRequest.h" #include "UDPSocket.h" #include <string> #include "dnsname.h" -#include "w5200NetIf.h" +#include "W5200NetIf.h" +//#define __DEBUG +#include "dbg/dbg.h" + +#ifdef __DEBUG +#define DBG2(...) do{ DebugStream::debug("%p %d %s ", this,__LINE__,__PRETTY_FUNCTION__); DebugStream::debug(__VA_ARGS__); } while(0); +#else +#define DBG2(...) while(0); +#endif //__DEBUG //#define DEBUG @@ -36,10 +44,11 @@ void MyNetDnsRequest::callback(UDPSocketEvent e) { PRINT_FUNC(); + DBG2("m_id[]=%02x:%02x\n", m_id[0], m_id[1]); uint8_t buf[512]; Host host; int len = m_udp->recvfrom((char*)buf, sizeof(buf), &host); - if (memcmp(buf, m_id, 2) != 0) { //verify + if (memcmp(buf+0, m_id, 2) != 0) { //verify return; } int rcode = response(buf, len); @@ -125,7 +134,7 @@ IpAddr dns(8,8,8,8); NetIf* pIf = Net::getDefaultIf(); if (pIf) { - dns = ((w5200NetIf*)pIf)->m_dns; + dns = ((W5200NetIf*)pIf)->m_dns; } Host server(dns, 53); // DNS m_udp->bind(local); @@ -136,8 +145,8 @@ printHex(buf, size); #endif m_udp->sendto((char*)buf, size, &server); - m_timer.reset(); - m_timer.start(); + m_interval.reset(); + m_interval.start(); } void MyNetDnsRequest::poll() { @@ -148,6 +157,7 @@ #endif //DEBUG switch(m_state) { case MYNETDNS_START: + m_retry = 0; resolve(m_hostname); m_state = MYNETDNS_PROCESSING; break; @@ -160,12 +170,19 @@ onReply(NETDNS_ERROR); break; case MYNETDNS_OK: + DBG2("m_retry=%d, m_interval=%d\n", m_retry, m_interval.read_ms()); onReply(NETDNS_FOUND); break; } - if (m_timer.read_ms() > 3000) { - m_timer.stop(); - m_state = MYNETDNS_ERROR; + if (m_interval.read_ms() > 1000) { + m_interval.stop(); + DBG2("timeout m_retry=%d\n", m_retry); + if (++m_retry > 1) { + m_state = MYNETDNS_ERROR; + } else { + resolve(m_hostname); + m_state = MYNETDNS_PROCESSING; + } } if(m_closing && (m_state!=MYNETDNS_PROCESSING)) { NetDnsRequest::close();