A version of LWIP, provided for backwards compatibility.
Dependents: AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more
trunk/Core/TCPConnection.h@0:5e1631496985, 2012-05-08 (annotated)
- Committer:
- root@mbed.org
- Date:
- Tue May 08 15:32:10 2012 +0100
- Revision:
- 0:5e1631496985
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
root@mbed.org | 0:5e1631496985 | 1 | #ifndef TCPCONNECTION_H |
root@mbed.org | 0:5e1631496985 | 2 | #define TCPCONNECTION_H |
root@mbed.org | 0:5e1631496985 | 3 | |
root@mbed.org | 0:5e1631496985 | 4 | #include "arch/cc.h" |
root@mbed.org | 0:5e1631496985 | 5 | #include "lwip/err.h" |
root@mbed.org | 0:5e1631496985 | 6 | //#include "lwip/tcp.h" |
root@mbed.org | 0:5e1631496985 | 7 | |
root@mbed.org | 0:5e1631496985 | 8 | #include "TCPItem.h" |
root@mbed.org | 0:5e1631496985 | 9 | |
root@mbed.org | 0:5e1631496985 | 10 | namespace mbed { |
root@mbed.org | 0:5e1631496985 | 11 | |
root@mbed.org | 0:5e1631496985 | 12 | class NetServer; |
root@mbed.org | 0:5e1631496985 | 13 | class TCPListener; |
root@mbed.org | 0:5e1631496985 | 14 | |
root@mbed.org | 0:5e1631496985 | 15 | class TCPConnection : public TCPItem { |
root@mbed.org | 0:5e1631496985 | 16 | public: |
root@mbed.org | 0:5e1631496985 | 17 | TCPConnection(struct ip_addr, u16_t); |
root@mbed.org | 0:5e1631496985 | 18 | TCPConnection(TCPListener *, struct tcp_pcb *); |
root@mbed.org | 0:5e1631496985 | 19 | |
root@mbed.org | 0:5e1631496985 | 20 | virtual ~TCPConnection(); |
root@mbed.org | 0:5e1631496985 | 21 | |
root@mbed.org | 0:5e1631496985 | 22 | void connect(); |
root@mbed.org | 0:5e1631496985 | 23 | |
root@mbed.org | 0:5e1631496985 | 24 | err_t write(void *, u16_t len, u8_t flags = TCP_WRITE_FLAG_COPY) const; |
root@mbed.org | 0:5e1631496985 | 25 | |
root@mbed.org | 0:5e1631496985 | 26 | void recved(u32_t len) const; |
root@mbed.org | 0:5e1631496985 | 27 | u16_t sndbuf() const { return tcp_sndbuf(_pcb); } |
root@mbed.org | 0:5e1631496985 | 28 | |
root@mbed.org | 0:5e1631496985 | 29 | void set_poll_timer(const u32_t &time) { |
root@mbed.org | 0:5e1631496985 | 30 | if(_pcb) { |
root@mbed.org | 0:5e1631496985 | 31 | _pcb->polltmr = time; |
root@mbed.org | 0:5e1631496985 | 32 | } |
root@mbed.org | 0:5e1631496985 | 33 | } |
root@mbed.org | 0:5e1631496985 | 34 | |
root@mbed.org | 0:5e1631496985 | 35 | u32_t get_poll_interval() const { |
root@mbed.org | 0:5e1631496985 | 36 | return (_pcb)? _pcb->pollinterval: 0; |
root@mbed.org | 0:5e1631496985 | 37 | } |
root@mbed.org | 0:5e1631496985 | 38 | |
root@mbed.org | 0:5e1631496985 | 39 | void set_poll_interval(const u32_t &value) { |
root@mbed.org | 0:5e1631496985 | 40 | if(_pcb) { |
root@mbed.org | 0:5e1631496985 | 41 | _pcb->pollinterval = value; |
root@mbed.org | 0:5e1631496985 | 42 | } |
root@mbed.org | 0:5e1631496985 | 43 | } |
root@mbed.org | 0:5e1631496985 | 44 | |
root@mbed.org | 0:5e1631496985 | 45 | u32_t get_poll_timer() const { |
root@mbed.org | 0:5e1631496985 | 46 | return (_pcb)? _pcb->polltmr: 0; |
root@mbed.org | 0:5e1631496985 | 47 | } |
root@mbed.org | 0:5e1631496985 | 48 | |
root@mbed.org | 0:5e1631496985 | 49 | protected: |
root@mbed.org | 0:5e1631496985 | 50 | TCPConnection(); |
root@mbed.org | 0:5e1631496985 | 51 | |
root@mbed.org | 0:5e1631496985 | 52 | /** |
root@mbed.org | 0:5e1631496985 | 53 | * Function to be called when more send buffer space is available. |
root@mbed.org | 0:5e1631496985 | 54 | * @param space the amount of bytes available |
root@mbed.org | 0:5e1631496985 | 55 | * @return ERR_OK: try to send some data by calling tcp_output |
root@mbed.org | 0:5e1631496985 | 56 | */ |
root@mbed.org | 0:5e1631496985 | 57 | virtual err_t sent(u16_t space) = 0; |
root@mbed.org | 0:5e1631496985 | 58 | |
root@mbed.org | 0:5e1631496985 | 59 | /** |
root@mbed.org | 0:5e1631496985 | 60 | * Function to be called when (in-sequence) data has arrived. |
root@mbed.org | 0:5e1631496985 | 61 | * @param p the packet buffer which arrived |
root@mbed.org | 0:5e1631496985 | 62 | * @param err an error argument (TODO: that is current always ERR_OK?) |
root@mbed.org | 0:5e1631496985 | 63 | * @return ERR_OK: try to send some data by calling tcp_output |
root@mbed.org | 0:5e1631496985 | 64 | */ |
root@mbed.org | 0:5e1631496985 | 65 | virtual err_t recv(struct pbuf *p, err_t err) = 0; |
root@mbed.org | 0:5e1631496985 | 66 | |
root@mbed.org | 0:5e1631496985 | 67 | /** |
root@mbed.org | 0:5e1631496985 | 68 | * Function to be called when a connection has been set up. |
root@mbed.org | 0:5e1631496985 | 69 | * @param pcb the tcp_pcb that now is connected |
root@mbed.org | 0:5e1631496985 | 70 | * @param err an error argument (TODO: that is current always ERR_OK?) |
root@mbed.org | 0:5e1631496985 | 71 | * @return value is currently ignored |
root@mbed.org | 0:5e1631496985 | 72 | */ |
root@mbed.org | 0:5e1631496985 | 73 | virtual err_t connected(err_t err); |
root@mbed.org | 0:5e1631496985 | 74 | |
root@mbed.org | 0:5e1631496985 | 75 | /** |
root@mbed.org | 0:5e1631496985 | 76 | * Function which is called periodically. |
root@mbed.org | 0:5e1631496985 | 77 | * The period can be adjusted in multiples of the TCP slow timer interval |
root@mbed.org | 0:5e1631496985 | 78 | * by changing tcp_pcb.polltmr. |
root@mbed.org | 0:5e1631496985 | 79 | * @return ERR_OK: try to send some data by calling tcp_output |
root@mbed.org | 0:5e1631496985 | 80 | */ |
root@mbed.org | 0:5e1631496985 | 81 | virtual err_t poll() = 0; |
root@mbed.org | 0:5e1631496985 | 82 | |
root@mbed.org | 0:5e1631496985 | 83 | /** |
root@mbed.org | 0:5e1631496985 | 84 | * Function to be called whenever a fatal error occurs. |
root@mbed.org | 0:5e1631496985 | 85 | * There is no pcb parameter since most of the times, the pcb is |
root@mbed.org | 0:5e1631496985 | 86 | * already deallocated (or there is no pcb) when this function is called. |
root@mbed.org | 0:5e1631496985 | 87 | * @param err an indication why the error callback is called: |
root@mbed.org | 0:5e1631496985 | 88 | * ERR_ABRT: aborted through tcp_abort or by a TCP timer |
root@mbed.org | 0:5e1631496985 | 89 | * ERR_RST: the connection was reset by the remote host |
root@mbed.org | 0:5e1631496985 | 90 | */ |
root@mbed.org | 0:5e1631496985 | 91 | virtual void err(err_t err) = 0; |
root@mbed.org | 0:5e1631496985 | 92 | |
root@mbed.org | 0:5e1631496985 | 93 | virtual void dnsreply(const char *hostname, struct ip_addr *addr) = 0; |
root@mbed.org | 0:5e1631496985 | 94 | |
root@mbed.org | 0:5e1631496985 | 95 | err_t dnsrequest(const char *hostname, struct ip_addr *addr) const; |
root@mbed.org | 0:5e1631496985 | 96 | |
root@mbed.org | 0:5e1631496985 | 97 | private: |
root@mbed.org | 0:5e1631496985 | 98 | static void dnsreply_callback(const char *name, struct ip_addr *ipaddr, void *arg); |
root@mbed.org | 0:5e1631496985 | 99 | static err_t connected_callback(void *arg, struct tcp_pcb *pcb, err_t err); |
root@mbed.org | 0:5e1631496985 | 100 | static err_t sent_callback(void *arg, struct tcp_pcb *pcb, u16_t space); |
root@mbed.org | 0:5e1631496985 | 101 | static err_t recv_callback(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err); |
root@mbed.org | 0:5e1631496985 | 102 | static err_t poll_callback(void *arg, struct tcp_pcb *pcb); |
root@mbed.org | 0:5e1631496985 | 103 | static void error_callback(void *arg, err_t erra); |
root@mbed.org | 0:5e1631496985 | 104 | |
root@mbed.org | 0:5e1631496985 | 105 | protected: |
root@mbed.org | 0:5e1631496985 | 106 | TCPListener *_parent; |
root@mbed.org | 0:5e1631496985 | 107 | struct ip_addr _ipaddr; |
root@mbed.org | 0:5e1631496985 | 108 | u16_t _port; |
root@mbed.org | 0:5e1631496985 | 109 | |
root@mbed.org | 0:5e1631496985 | 110 | friend class NetServer; |
root@mbed.org | 0:5e1631496985 | 111 | }; |
root@mbed.org | 0:5e1631496985 | 112 | |
root@mbed.org | 0:5e1631496985 | 113 | }; |
root@mbed.org | 0:5e1631496985 | 114 | |
root@mbed.org | 0:5e1631496985 | 115 | #endif /* TCPCONNECTION_H */ |