Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SimpleLCDClock readCard2Twitter_http AnalogClock_StepperMotor_NTP ServoCamV1
if/lwip/lwipNetTcpSocket.h@0:3717b703f76d, 2010-05-24 (annotated)
- Committer:
- donatien
- Date:
- Mon May 24 10:23:42 2010 +0000
- Revision:
- 0:3717b703f76d
- Child:
- 1:e52ec2a24c6a
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| donatien | 0:3717b703f76d | 1 | #ifndef LWIPNETTCPSOCKET_H | 
| donatien | 0:3717b703f76d | 2 | #define LWIPNETTCPSOCKET_H | 
| donatien | 0:3717b703f76d | 3 | |
| donatien | 0:3717b703f76d | 4 | #define NET_LWIP_STACK 1 | 
| donatien | 0:3717b703f76d | 5 | #include "lwip/ip_addr.h" | 
| donatien | 0:3717b703f76d | 6 | #include "if/net/net.h" | 
| donatien | 0:3717b703f76d | 7 | #include "LwipNetIf.h" | 
| donatien | 0:3717b703f76d | 8 | |
| donatien | 0:3717b703f76d | 9 | //Implements NetTcpSockets over lwIP raw API | 
| donatien | 0:3717b703f76d | 10 | |
| donatien | 0:3717b703f76d | 11 | struct tcp_pcb; //Represents a Tcp Connection, "Protocol Control Block", see rawapi.txt & tcp.h | 
| donatien | 0:3717b703f76d | 12 | struct pbuf; //Lwip Buffer Container | 
| donatien | 0:3717b703f76d | 13 | |
| donatien | 0:3717b703f76d | 14 | typedef signed char err_t; | 
| donatien | 0:3717b703f76d | 15 | |
| donatien | 0:3717b703f76d | 16 | class LwipNetTcpSocket: public NetTcpSocket | 
| donatien | 0:3717b703f76d | 17 | { | 
| donatien | 0:3717b703f76d | 18 | public: | 
| donatien | 0:3717b703f76d | 19 | LwipNetTcpSocket(tcp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership | 
| donatien | 0:3717b703f76d | 20 | virtual ~LwipNetTcpSocket(); | 
| donatien | 0:3717b703f76d | 21 | |
| donatien | 0:3717b703f76d | 22 | virtual NetTcpSocketErr bind(const Host& me); | 
| donatien | 0:3717b703f76d | 23 | virtual NetTcpSocketErr listen(); | 
| donatien | 0:3717b703f76d | 24 | virtual NetTcpSocketErr connect(const Host& host); | 
| donatien | 0:3717b703f76d | 25 | virtual NetTcpSocketErr accept(Host* pClient, NetTcpSocket** ppNewNetTcpSocket); | 
| donatien | 0:3717b703f76d | 26 | |
| donatien | 0:3717b703f76d | 27 | virtual int /*if < 0 : NetTcpSocketErr*/ send(const char* buf, int len); | 
| donatien | 0:3717b703f76d | 28 | virtual int /*if < 0 : NetTcpSocketErr*/ recv(char* buf, int len); | 
| donatien | 0:3717b703f76d | 29 | |
| donatien | 0:3717b703f76d | 30 | virtual NetTcpSocketErr close(); | 
| donatien | 0:3717b703f76d | 31 | |
| donatien | 0:3717b703f76d | 32 | virtual NetTcpSocketErr poll(); | 
| donatien | 0:3717b703f76d | 33 | |
| donatien | 0:3717b703f76d | 34 | protected: | 
| donatien | 0:3717b703f76d | 35 | volatile tcp_pcb* m_pPcb; | 
| donatien | 0:3717b703f76d | 36 | |
| donatien | 0:3717b703f76d | 37 | //Events callbacks from lwIp | 
| donatien | 0:3717b703f76d | 38 | err_t acceptCb(tcp_pcb* newpcb, err_t err); | 
| donatien | 0:3717b703f76d | 39 | err_t connectedCb(tcp_pcb* tpcb, err_t err); | 
| donatien | 0:3717b703f76d | 40 | |
| donatien | 0:3717b703f76d | 41 | void errCb(err_t err); | 
| donatien | 0:3717b703f76d | 42 | |
| donatien | 0:3717b703f76d | 43 | err_t sentCb(tcp_pcb* tpcb, u16_t len); | 
| donatien | 0:3717b703f76d | 44 | err_t recvCb(tcp_pcb* tpcb, pbuf *p, err_t err); | 
| donatien | 0:3717b703f76d | 45 | |
| donatien | 0:3717b703f76d | 46 | private: | 
| donatien | 0:3717b703f76d | 47 | void cleanUp(); //Flush input buffer | 
| donatien | 0:3717b703f76d | 48 | |
| donatien | 0:3717b703f76d | 49 | // queue<tcp_pcb*> m_lpInPcb; //Incoming connections that have not been accepted yet | 
| donatien | 0:3717b703f76d | 50 | queue<LwipNetTcpSocket*> m_lpInNetTcpSocket; //Incoming connections that have not been accepted yet | 
| donatien | 0:3717b703f76d | 51 | |
| donatien | 0:3717b703f76d | 52 | volatile pbuf* m_pReadPbuf; //Ptr to read buffer | 
| donatien | 0:3717b703f76d | 53 | |
| donatien | 0:3717b703f76d | 54 | //Static callbacks : Transforms into a C++ callback | 
| donatien | 0:3717b703f76d | 55 | static err_t sAcceptCb(void *arg, struct tcp_pcb *newpcb, err_t err); | 
| donatien | 0:3717b703f76d | 56 | static err_t sConnectedCb(void *arg, struct tcp_pcb *tpcb, err_t err); | 
| donatien | 0:3717b703f76d | 57 | |
| donatien | 0:3717b703f76d | 58 | static void sErrCb(void *arg, err_t err); | 
| donatien | 0:3717b703f76d | 59 | |
| donatien | 0:3717b703f76d | 60 | static err_t sSentCb(void *arg, struct tcp_pcb *tpcb, u16_t len); | 
| donatien | 0:3717b703f76d | 61 | static err_t sRecvCb(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err); | 
| donatien | 0:3717b703f76d | 62 | |
| donatien | 0:3717b703f76d | 63 | }; | 
| donatien | 0:3717b703f76d | 64 | |
| donatien | 0:3717b703f76d | 65 | #endif |