Embed:
(wiki syntax)
Show/hide line numbers
LwipNetIf.cpp
00001 00002 /* 00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 THE SOFTWARE. 00022 */ 00023 00024 #include "LwipNetIf.h" 00025 #include "lwip/init.h" 00026 #include "lwip/tcp_impl.h" 00027 #include "lwip/dns.h" 00028 00029 #include "lwipNetTcpSocket.h" 00030 #include "lwipNetUdpSocket.h" 00031 #include "lwipNetDnsRequest.h" 00032 00033 #include "netCfg.h" 00034 #if NET_LWIP_STACK 00035 00036 //See doc/rawapi.txt for details 00037 00038 LwipNetIf::LwipNetIf() : NetIf(), m_tcpTimer(), m_dnsTimer(), m_init(false) 00039 { 00040 00041 } 00042 00043 00044 LwipNetIf::~LwipNetIf() 00045 { 00046 00047 } 00048 00049 void LwipNetIf::init() 00050 { 00051 if(m_init) 00052 return; 00053 m_init=true; 00054 lwip_init(); //init lwip, see init.c for details 00055 00056 //Setup Clocks 00057 m_tcpTimer.start(); 00058 m_dnsTimer.start(); 00059 //m_tcpTicker.attach_us( tcp_tmr, TCP_TMR_INTERVAL * 1000 ); //TCP_TMR_INTERVAL = 250 ms in tcp_impl.h 00060 //m_dnsTicker.attach_us( dns_tmr, DNS_TMR_INTERVAL * 1000 ); //DNS_TMR_INTERVAL = 1000 ms in dns.h 00061 } 00062 00063 NetTcpSocket* LwipNetIf::tcpSocket() //Create a new tcp socket 00064 { 00065 return new LwipNetTcpSocket(); 00066 } 00067 00068 NetUdpSocket* LwipNetIf::udpSocket() //Create a new udp socket 00069 { 00070 return new LwipNetUdpSocket(); 00071 } 00072 00073 NetDnsRequest* LwipNetIf::dnsRequest(const char* hostname) //Create a new NetDnsRequest object 00074 { 00075 return new LwipNetDnsRequest(hostname); 00076 } 00077 00078 NetDnsRequest* LwipNetIf::dnsRequest(Host* pHost) //Create a new NetDnsRequest object 00079 { 00080 return new LwipNetDnsRequest(pHost); 00081 } 00082 00083 void LwipNetIf::poll() 00084 { 00085 if(m_init && m_tcpTimer.read_ms() >= TCP_TMR_INTERVAL) 00086 { 00087 m_tcpTimer.reset(); 00088 tcp_tmr(); //Poll LwIP 00089 } 00090 if(m_init && m_dnsTimer.read_ms() >= DNS_TMR_INTERVAL) 00091 { 00092 m_dnsTimer.reset(); 00093 dns_tmr(); 00094 } 00095 //Do some stuff... 00096 } 00097 00098 #endif
Generated on Tue Jul 12 2022 16:37:49 by 1.7.2