Committer:
mbed714
Date:
Tue Nov 09 19:32:44 2010 +0000
Revision:
3:0c324737064d
Parent:
0:98aadd37a5c5

        

Who changed what in which revision?

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