Atsushi Hattori
/
20210627_Logger
hattori&ide
TinyHTTP/EthernetNetIf/LPC1768/core/net.h@0:f77369cabd75, 18 months ago (annotated)
- Committer:
- hattori_atsushi
- Date:
- Sun Dec 18 08:16:01 2022 +0000
- Revision:
- 0:f77369cabd75
hattori
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hattori_atsushi | 0:f77369cabd75 | 1 | |
hattori_atsushi | 0:f77369cabd75 | 2 | /* |
hattori_atsushi | 0:f77369cabd75 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
hattori_atsushi | 0:f77369cabd75 | 4 | |
hattori_atsushi | 0:f77369cabd75 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
hattori_atsushi | 0:f77369cabd75 | 6 | of this software and associated documentation files (the "Software"), to deal |
hattori_atsushi | 0:f77369cabd75 | 7 | in the Software without restriction, including without limitation the rights |
hattori_atsushi | 0:f77369cabd75 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
hattori_atsushi | 0:f77369cabd75 | 9 | copies of the Software, and to permit persons to whom the Software is |
hattori_atsushi | 0:f77369cabd75 | 10 | furnished to do so, subject to the following conditions: |
hattori_atsushi | 0:f77369cabd75 | 11 | |
hattori_atsushi | 0:f77369cabd75 | 12 | The above copyright notice and this permission notice shall be included in |
hattori_atsushi | 0:f77369cabd75 | 13 | all copies or substantial portions of the Software. |
hattori_atsushi | 0:f77369cabd75 | 14 | |
hattori_atsushi | 0:f77369cabd75 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
hattori_atsushi | 0:f77369cabd75 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
hattori_atsushi | 0:f77369cabd75 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
hattori_atsushi | 0:f77369cabd75 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
hattori_atsushi | 0:f77369cabd75 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
hattori_atsushi | 0:f77369cabd75 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
hattori_atsushi | 0:f77369cabd75 | 21 | THE SOFTWARE. |
hattori_atsushi | 0:f77369cabd75 | 22 | */ |
hattori_atsushi | 0:f77369cabd75 | 23 | |
hattori_atsushi | 0:f77369cabd75 | 24 | #ifndef NET_H |
hattori_atsushi | 0:f77369cabd75 | 25 | #define NET_H |
hattori_atsushi | 0:f77369cabd75 | 26 | |
hattori_atsushi | 0:f77369cabd75 | 27 | class NetIf; |
hattori_atsushi | 0:f77369cabd75 | 28 | class NetTcpSocket; |
hattori_atsushi | 0:f77369cabd75 | 29 | class NetUdpSocket; |
hattori_atsushi | 0:f77369cabd75 | 30 | class NetDnsRequest; |
hattori_atsushi | 0:f77369cabd75 | 31 | |
hattori_atsushi | 0:f77369cabd75 | 32 | #include <list> |
hattori_atsushi | 0:f77369cabd75 | 33 | using std::list; |
hattori_atsushi | 0:f77369cabd75 | 34 | |
hattori_atsushi | 0:f77369cabd75 | 35 | /* |
hattori_atsushi | 0:f77369cabd75 | 36 | #include "host.h" |
hattori_atsushi | 0:f77369cabd75 | 37 | #include "ipaddr.h" |
hattori_atsushi | 0:f77369cabd75 | 38 | #include "netservice.h" |
hattori_atsushi | 0:f77369cabd75 | 39 | #include "if/net/netif.h" |
hattori_atsushi | 0:f77369cabd75 | 40 | #include "if/net/nettcpsocket.h" |
hattori_atsushi | 0:f77369cabd75 | 41 | #include "if/net/netudpsocket.h" |
hattori_atsushi | 0:f77369cabd75 | 42 | #include "if/net/netdnsrequest.h" |
hattori_atsushi | 0:f77369cabd75 | 43 | */ |
hattori_atsushi | 0:f77369cabd75 | 44 | |
hattori_atsushi | 0:f77369cabd75 | 45 | class Host; |
hattori_atsushi | 0:f77369cabd75 | 46 | class NetIf; |
hattori_atsushi | 0:f77369cabd75 | 47 | class NetTcpSocket; |
hattori_atsushi | 0:f77369cabd75 | 48 | class NetUdpSocket; |
hattori_atsushi | 0:f77369cabd75 | 49 | class NetDnsRequest; |
hattori_atsushi | 0:f77369cabd75 | 50 | |
hattori_atsushi | 0:f77369cabd75 | 51 | class Net |
hattori_atsushi | 0:f77369cabd75 | 52 | { |
hattori_atsushi | 0:f77369cabd75 | 53 | private: |
hattori_atsushi | 0:f77369cabd75 | 54 | Net(); |
hattori_atsushi | 0:f77369cabd75 | 55 | ~Net(); |
hattori_atsushi | 0:f77369cabd75 | 56 | public: |
hattori_atsushi | 0:f77369cabd75 | 57 | static void poll(); //Poll every if & socket |
hattori_atsushi | 0:f77369cabd75 | 58 | |
hattori_atsushi | 0:f77369cabd75 | 59 | static NetTcpSocket* tcpSocket(NetIf& netif); |
hattori_atsushi | 0:f77369cabd75 | 60 | static NetTcpSocket* tcpSocket(); //Socket on default if |
hattori_atsushi | 0:f77369cabd75 | 61 | static void releaseTcpSocket(NetTcpSocket* pNetTcpSocket); |
hattori_atsushi | 0:f77369cabd75 | 62 | |
hattori_atsushi | 0:f77369cabd75 | 63 | static NetUdpSocket* udpSocket(NetIf& netif); |
hattori_atsushi | 0:f77369cabd75 | 64 | static NetUdpSocket* udpSocket(); //Socket on default if |
hattori_atsushi | 0:f77369cabd75 | 65 | static void releaseUdpSocket(NetUdpSocket* pNetUdpSocket); |
hattori_atsushi | 0:f77369cabd75 | 66 | |
hattori_atsushi | 0:f77369cabd75 | 67 | static NetDnsRequest* dnsRequest(const char* hostname, NetIf& netif); |
hattori_atsushi | 0:f77369cabd75 | 68 | static NetDnsRequest* dnsRequest(const char* hostname); //Create a new NetDnsRequest object from default if |
hattori_atsushi | 0:f77369cabd75 | 69 | |
hattori_atsushi | 0:f77369cabd75 | 70 | static NetDnsRequest* dnsRequest(Host* pHost, NetIf& netif); |
hattori_atsushi | 0:f77369cabd75 | 71 | static NetDnsRequest* dnsRequest(Host* pHost); //Create a new NetDnsRequest object from default if |
hattori_atsushi | 0:f77369cabd75 | 72 | |
hattori_atsushi | 0:f77369cabd75 | 73 | static void setDefaultIf(NetIf& netif); //Deprecated |
hattori_atsushi | 0:f77369cabd75 | 74 | static void setDefaultIf(NetIf* pIf); |
hattori_atsushi | 0:f77369cabd75 | 75 | static NetIf* getDefaultIf(); |
hattori_atsushi | 0:f77369cabd75 | 76 | |
hattori_atsushi | 0:f77369cabd75 | 77 | protected: |
hattori_atsushi | 0:f77369cabd75 | 78 | friend class NetIf; |
hattori_atsushi | 0:f77369cabd75 | 79 | friend class NetTcpSocket; |
hattori_atsushi | 0:f77369cabd75 | 80 | friend class NetUdpSocket; |
hattori_atsushi | 0:f77369cabd75 | 81 | |
hattori_atsushi | 0:f77369cabd75 | 82 | static void registerIf(NetIf* pIf); |
hattori_atsushi | 0:f77369cabd75 | 83 | static void unregisterIf(NetIf* pIf); |
hattori_atsushi | 0:f77369cabd75 | 84 | |
hattori_atsushi | 0:f77369cabd75 | 85 | static void registerNetTcpSocket(NetTcpSocket* pNetTcpSocket); |
hattori_atsushi | 0:f77369cabd75 | 86 | static void unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket); |
hattori_atsushi | 0:f77369cabd75 | 87 | |
hattori_atsushi | 0:f77369cabd75 | 88 | static void registerNetUdpSocket(NetUdpSocket* pNetUdpSocket); |
hattori_atsushi | 0:f77369cabd75 | 89 | static void unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket); |
hattori_atsushi | 0:f77369cabd75 | 90 | |
hattori_atsushi | 0:f77369cabd75 | 91 | private: |
hattori_atsushi | 0:f77369cabd75 | 92 | static Net& net(); //Return inst of singleton |
hattori_atsushi | 0:f77369cabd75 | 93 | |
hattori_atsushi | 0:f77369cabd75 | 94 | NetIf* m_defaultIf; |
hattori_atsushi | 0:f77369cabd75 | 95 | |
hattori_atsushi | 0:f77369cabd75 | 96 | list<NetIf*> m_lpIf; |
hattori_atsushi | 0:f77369cabd75 | 97 | list<NetTcpSocket*> m_lpNetTcpSocket; |
hattori_atsushi | 0:f77369cabd75 | 98 | list<NetUdpSocket*> m_lpNetUdpSocket; |
hattori_atsushi | 0:f77369cabd75 | 99 | }; |
hattori_atsushi | 0:f77369cabd75 | 100 | |
hattori_atsushi | 0:f77369cabd75 | 101 | #endif |