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