Dependencies:   mbed

Committer:
slowness
Date:
Tue Sep 06 18:10:36 2011 +0000
Revision:
0:cd4c47744fa1

        

Who changed what in which revision?

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