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