A version of LWIP, provided for backwards compatibility.
Dependents: AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more
Diff: tag/0.5/tcpconnection.h
- Revision:
- 0:5e1631496985
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tag/0.5/tcpconnection.h Tue May 08 15:32:10 2012 +0100 @@ -0,0 +1,99 @@ +#ifndef TCPCONNECTION_H +#define TCPCONNECTION_H + +#include "tcpitem.h" + +#include "arch/cc.h" +#include "lwip/err.h" +//#include "lwip/tcp.h" + +namespace mbed { + +class NetServer; +class TCPListener; + +class TCPConnection : public TCPItem { + public: + TCPConnection(struct ip_addr, u16_t); + TCPConnection(TCPListener *, struct tcp_pcb *); + + virtual ~TCPConnection(); + + void connect(); + + err_t write(void *, u32_t len); + void recved(u32_t len); + u16_t sndbuf() { return tcp_sndbuf(_pcb); } + + void set_poll_timer(const u32_t &time) { + if(_pcb) { + _pcb->polltmr = time; + } + } + + u32_t get_poll_interval() const { + return (_pcb)? _pcb->pollinterval: 0; + } + + void set_poll_interval(const u32_t &value) { + if(_pcb) { + _pcb->pollinterval = value; + } + } + + u32_t get_poll_timer() const { + return (_pcb)? _pcb->polltmr: 0; + } + + + /** + * Function to be called when more send buffer space is available. + * @param space the amount of bytes available + * @return ERR_OK: try to send some data by calling tcp_output + */ + virtual err_t sent(u16_t space) = 0; + + /** + * Function to be called when (in-sequence) data has arrived. + * @param p the packet buffer which arrived + * @param err an error argument (TODO: that is current always ERR_OK?) + * @return ERR_OK: try to send some data by calling tcp_output + */ + virtual err_t recv(struct pbuf *p, err_t err) = 0; + + /** + * Function to be called when a connection has been set up. + * @param pcb the tcp_pcb that now is connected + * @param err an error argument (TODO: that is current always ERR_OK?) + * @return value is currently ignored + */ + virtual err_t connected(err_t err); + + /** + * Function which is called periodically. + * The period can be adjusted in multiples of the TCP slow timer interval + * by changing tcp_pcb.polltmr. + * @return ERR_OK: try to send some data by calling tcp_output + */ + virtual err_t poll() = 0; + + /** + * Function to be called whenever a fatal error occurs. + * There is no pcb parameter since most of the times, the pcb is + * already deallocated (or there is no pcb) when this function is called. + * @param err an indication why the error callback is called: + * ERR_ABRT: aborted through tcp_abort or by a TCP timer + * ERR_RST: the connection was reset by the remote host + */ + virtual void err(err_t) = 0; + + protected: + TCPListener *_parent; + struct ip_addr _ipaddr; + u16_t _port; + friend class NetServer; +}; + +}; + +#endif /* TCPCONNECTION_H */ \ No newline at end of file