Port of LwIP performed by Ralf in 2010. Not recommended for use with recent mbed libraries, but good demos of raw LwIP possible

Dependents:   LwIP_raw_API_serverExample tiny-dtls

Committer:
RodColeman
Date:
Tue Sep 18 14:41:24 2012 +0000
Revision:
0:0791c1fece8e
[mbed] converted /Eth_TCP_Wei_Server/lwip

Who changed what in which revision?

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