Fork of NetServicesMin with some warnings removed
Fork of NetServicesMin by
if/lwip/lwipNetUdpSocket.h@4:c8b2f969c8dd, 2012-11-24 (annotated)
- Committer:
- uci1
- Date:
- Sat Nov 24 20:20:45 2012 +0000
- Revision:
- 4:c8b2f969c8dd
- Parent:
- 0:8b387bed54c2
Remove debugging printouts
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hlipka | 0:8b387bed54c2 | 1 | |
hlipka | 0:8b387bed54c2 | 2 | /* |
hlipka | 0:8b387bed54c2 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
hlipka | 0:8b387bed54c2 | 4 | |
hlipka | 0:8b387bed54c2 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
hlipka | 0:8b387bed54c2 | 6 | of this software and associated documentation files (the "Software"), to deal |
hlipka | 0:8b387bed54c2 | 7 | in the Software without restriction, including without limitation the rights |
hlipka | 0:8b387bed54c2 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
hlipka | 0:8b387bed54c2 | 9 | copies of the Software, and to permit persons to whom the Software is |
hlipka | 0:8b387bed54c2 | 10 | furnished to do so, subject to the following conditions: |
hlipka | 0:8b387bed54c2 | 11 | |
hlipka | 0:8b387bed54c2 | 12 | The above copyright notice and this permission notice shall be included in |
hlipka | 0:8b387bed54c2 | 13 | all copies or substantial portions of the Software. |
hlipka | 0:8b387bed54c2 | 14 | |
hlipka | 0:8b387bed54c2 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
hlipka | 0:8b387bed54c2 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
hlipka | 0:8b387bed54c2 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
hlipka | 0:8b387bed54c2 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
hlipka | 0:8b387bed54c2 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
hlipka | 0:8b387bed54c2 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
hlipka | 0:8b387bed54c2 | 21 | THE SOFTWARE. |
hlipka | 0:8b387bed54c2 | 22 | */ |
hlipka | 0:8b387bed54c2 | 23 | |
hlipka | 0:8b387bed54c2 | 24 | #ifndef LWIPNETUDPSOCKET_H |
hlipka | 0:8b387bed54c2 | 25 | #define LWIPNETUDPSOCKET_H |
hlipka | 0:8b387bed54c2 | 26 | |
hlipka | 0:8b387bed54c2 | 27 | #define NET_LWIP_STACK 1 |
hlipka | 0:8b387bed54c2 | 28 | //#include "lwip/ip_addr.h" |
hlipka | 0:8b387bed54c2 | 29 | #include "if/net/netudpsocket.h" |
hlipka | 0:8b387bed54c2 | 30 | #include "LwipNetIf.h" |
hlipka | 0:8b387bed54c2 | 31 | |
hlipka | 0:8b387bed54c2 | 32 | #include "stdint.h" |
hlipka | 0:8b387bed54c2 | 33 | |
hlipka | 0:8b387bed54c2 | 34 | #include <list> |
hlipka | 0:8b387bed54c2 | 35 | using std::list; |
hlipka | 0:8b387bed54c2 | 36 | |
hlipka | 0:8b387bed54c2 | 37 | //Implements NetUdpSockets over lwIP raw API |
hlipka | 0:8b387bed54c2 | 38 | |
hlipka | 0:8b387bed54c2 | 39 | struct udp_pcb; //Represents a Udp Connection, "Protocol Control Block", see rawapi.txt & udp.h |
hlipka | 0:8b387bed54c2 | 40 | struct pbuf; //Lwip Buffer Container |
hlipka | 0:8b387bed54c2 | 41 | typedef struct ip_addr ip_addr_t; |
hlipka | 0:8b387bed54c2 | 42 | |
hlipka | 0:8b387bed54c2 | 43 | //typedef signed char err_t; |
hlipka | 0:8b387bed54c2 | 44 | typedef uint16_t u16_t; |
hlipka | 0:8b387bed54c2 | 45 | |
hlipka | 0:8b387bed54c2 | 46 | class LwipNetUdpSocket: public NetUdpSocket |
hlipka | 0:8b387bed54c2 | 47 | { |
hlipka | 0:8b387bed54c2 | 48 | public: |
hlipka | 0:8b387bed54c2 | 49 | LwipNetUdpSocket(udp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership |
hlipka | 0:8b387bed54c2 | 50 | virtual ~LwipNetUdpSocket(); |
hlipka | 0:8b387bed54c2 | 51 | |
hlipka | 0:8b387bed54c2 | 52 | virtual NetUdpSocketErr bind(const Host& me); |
hlipka | 0:8b387bed54c2 | 53 | |
hlipka | 0:8b387bed54c2 | 54 | virtual int /*if < 0 : NetUdpSocketErr*/ sendto(const char* buf, int len, Host* pHost); |
hlipka | 0:8b387bed54c2 | 55 | virtual int /*if < 0 : NetUdpSocketErr*/ recvfrom(char* buf, int len, Host* pHost); |
hlipka | 0:8b387bed54c2 | 56 | |
hlipka | 0:8b387bed54c2 | 57 | virtual NetUdpSocketErr close(); |
hlipka | 0:8b387bed54c2 | 58 | |
hlipka | 0:8b387bed54c2 | 59 | virtual NetUdpSocketErr poll(); |
hlipka | 0:8b387bed54c2 | 60 | |
hlipka | 0:8b387bed54c2 | 61 | protected: |
hlipka | 0:8b387bed54c2 | 62 | volatile udp_pcb* m_pPcb; |
hlipka | 0:8b387bed54c2 | 63 | |
hlipka | 0:8b387bed54c2 | 64 | //Event callback from lwIp |
hlipka | 0:8b387bed54c2 | 65 | void recvCb(udp_pcb* pcb, struct pbuf* p, ip_addr_t* addr, u16_t port); |
hlipka | 0:8b387bed54c2 | 66 | |
hlipka | 0:8b387bed54c2 | 67 | private: |
hlipka | 0:8b387bed54c2 | 68 | void cleanUp(); //Flush input buffer |
hlipka | 0:8b387bed54c2 | 69 | struct InPacket |
hlipka | 0:8b387bed54c2 | 70 | { |
hlipka | 0:8b387bed54c2 | 71 | volatile pbuf* pBuf; |
hlipka | 0:8b387bed54c2 | 72 | ip_addr_t addr; |
hlipka | 0:8b387bed54c2 | 73 | u16_t port; |
hlipka | 0:8b387bed54c2 | 74 | }; |
hlipka | 0:8b387bed54c2 | 75 | |
hlipka | 0:8b387bed54c2 | 76 | list<InPacket> m_lInPkt; |
hlipka | 0:8b387bed54c2 | 77 | IpAddr m_multicastGroup; |
hlipka | 0:8b387bed54c2 | 78 | |
hlipka | 0:8b387bed54c2 | 79 | //Static callback : Transforms into a C++ callback |
hlipka | 0:8b387bed54c2 | 80 | static void sRecvCb(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port); |
hlipka | 0:8b387bed54c2 | 81 | |
hlipka | 0:8b387bed54c2 | 82 | }; |
hlipka | 0:8b387bed54c2 | 83 | |
hlipka | 0:8b387bed54c2 | 84 | #endif |