Dependencies:   mbed

Dependents:   TCP

Committer:
slowness
Date:
Tue Sep 06 18:05:46 2011 +0000
Revision:
0:58c3d014a4e7

        

Who changed what in which revision?

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