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 TCPCALLBACKCONNECTION_H
RodColeman 0:0791c1fece8e 2 #define TCPCALLBACKCONNECTION_H
RodColeman 0:0791c1fece8e 3
RodColeman 0:0791c1fece8e 4 #include "TCPConnection.h"
RodColeman 0:0791c1fece8e 5
RodColeman 0:0791c1fece8e 6 namespace mbed {
RodColeman 0:0791c1fece8e 7
RodColeman 0:0791c1fece8e 8 #define NO_SENT_FNC ((err_t (*)(TCPCallbackConnection *, u16_t))NULL)
RodColeman 0:0791c1fece8e 9 #define NO_RECV_FNC ((err_t (*)(TCPCallbackConnection *, struct pbuf *, err_t))NULL)
RodColeman 0:0791c1fece8e 10 #define NO_POLL_FNC ((err_t (*)(TCPCallbackConnection *))NULL)
RodColeman 0:0791c1fece8e 11 #define NO_ACCEPT_FNC ((err_t (*)(TCPCallbackConnection *, struct tcp_pcb *, err_t))NULL)
RodColeman 0:0791c1fece8e 12 #define NO_CONNECT_FNC ((err_t (*)(TCPCallbackConnection *, err_t))NULL)
RodColeman 0:0791c1fece8e 13 #define NO_ERR_FNC ((void (*)(TCPCallbackConnection *, err_t))NULL)
RodColeman 0:0791c1fece8e 14
RodColeman 0:0791c1fece8e 15
RodColeman 0:0791c1fece8e 16 class TCPCallbackConnection : public TCPConnection {
RodColeman 0:0791c1fece8e 17 public:
RodColeman 0:0791c1fece8e 18 TCPCallbackConnection(struct ip_addr ip_addr, u16_t port,
RodColeman 0:0791c1fece8e 19 err_t (*psent)(TCPCallbackConnection *, u16_t),
RodColeman 0:0791c1fece8e 20 err_t (*precv)(TCPCallbackConnection *, struct pbuf *, err_t),
RodColeman 0:0791c1fece8e 21 err_t (*ppoll)(TCPCallbackConnection *),
RodColeman 0:0791c1fece8e 22 err_t (*pconnected)(TCPCallbackConnection *, err_t),
RodColeman 0:0791c1fece8e 23 void (*perr )(TCPCallbackConnection *, err_t))
RodColeman 0:0791c1fece8e 24 : TCPConnection(ip_addr, port) {
RodColeman 0:0791c1fece8e 25 _sent = psent;
RodColeman 0:0791c1fece8e 26 _recv = precv;
RodColeman 0:0791c1fece8e 27 _poll = ppoll;
RodColeman 0:0791c1fece8e 28 _connected = pconnected;
RodColeman 0:0791c1fece8e 29 _err = perr;
RodColeman 0:0791c1fece8e 30 }
RodColeman 0:0791c1fece8e 31
RodColeman 0:0791c1fece8e 32 TCPCallbackConnection(TCPListener *parent, struct tcp_pcb *npcb,
RodColeman 0:0791c1fece8e 33 err_t (*psent)(TCPCallbackConnection *, u16_t),
RodColeman 0:0791c1fece8e 34 err_t (*precv)(TCPCallbackConnection *, struct pbuf *, err_t),
RodColeman 0:0791c1fece8e 35 err_t (*ppoll)(TCPCallbackConnection *),
RodColeman 0:0791c1fece8e 36 err_t (*pconnected)(TCPCallbackConnection *, err_t),
RodColeman 0:0791c1fece8e 37 void (*perr )(TCPCallbackConnection *, err_t))
RodColeman 0:0791c1fece8e 38 : TCPConnection(parent, npcb) {
RodColeman 0:0791c1fece8e 39 _sent = psent;
RodColeman 0:0791c1fece8e 40 _recv = precv;
RodColeman 0:0791c1fece8e 41 _poll = ppoll;
RodColeman 0:0791c1fece8e 42 _connected = pconnected;
RodColeman 0:0791c1fece8e 43 _err = perr;
RodColeman 0:0791c1fece8e 44 }
RodColeman 0:0791c1fece8e 45
RodColeman 0:0791c1fece8e 46 private:
RodColeman 0:0791c1fece8e 47 /*
RodColeman 0:0791c1fece8e 48 * Function to be called when more send buffer space is available.
RodColeman 0:0791c1fece8e 49 * @param space the amount of bytes available
RodColeman 0:0791c1fece8e 50 * @return ERR_OK: try to send some data by calling tcp_output
RodColeman 0:0791c1fece8e 51 */
RodColeman 0:0791c1fece8e 52 virtual err_t sent(u16_t space) {
RodColeman 0:0791c1fece8e 53 if(_sent) {
RodColeman 0:0791c1fece8e 54 return (_sent)(this, space);
RodColeman 0:0791c1fece8e 55 } else {
RodColeman 0:0791c1fece8e 56 return ERR_OK;
RodColeman 0:0791c1fece8e 57 }
RodColeman 0:0791c1fece8e 58 }
RodColeman 0:0791c1fece8e 59
RodColeman 0:0791c1fece8e 60 /*
RodColeman 0:0791c1fece8e 61 * Function to be called when (in-sequence) data has arrived.
RodColeman 0:0791c1fece8e 62 * @param p the packet buffer which arrived
RodColeman 0:0791c1fece8e 63 * @param err an error argument (TODO: that is current always ERR_OK?)
RodColeman 0:0791c1fece8e 64 * @return ERR_OK: try to send some data by calling tcp_output
RodColeman 0:0791c1fece8e 65 */
RodColeman 0:0791c1fece8e 66 virtual err_t recv(struct pbuf *p, err_t err) {
RodColeman 0:0791c1fece8e 67 if(_recv) {
RodColeman 0:0791c1fece8e 68 return (_recv)(this, p, err);
RodColeman 0:0791c1fece8e 69 } else {
RodColeman 0:0791c1fece8e 70 return ERR_OK;
RodColeman 0:0791c1fece8e 71 }
RodColeman 0:0791c1fece8e 72 }
RodColeman 0:0791c1fece8e 73
RodColeman 0:0791c1fece8e 74 /*
RodColeman 0:0791c1fece8e 75 * Function which is called periodically.
RodColeman 0:0791c1fece8e 76 * The period can be adjusted in multiples of the TCP slow timer interval
RodColeman 0:0791c1fece8e 77 * by changing tcp_pcb.polltmr.
RodColeman 0:0791c1fece8e 78 * @return ERR_OK: try to send some data by calling tcp_output
RodColeman 0:0791c1fece8e 79 */
RodColeman 0:0791c1fece8e 80 virtual err_t poll() {
RodColeman 0:0791c1fece8e 81 if(_poll) {
RodColeman 0:0791c1fece8e 82 return (_poll)(this);
RodColeman 0:0791c1fece8e 83 } else {
RodColeman 0:0791c1fece8e 84 return ERR_OK;
RodColeman 0:0791c1fece8e 85 }
RodColeman 0:0791c1fece8e 86 }
RodColeman 0:0791c1fece8e 87
RodColeman 0:0791c1fece8e 88 virtual err_t connected(err_t err) {
RodColeman 0:0791c1fece8e 89 err = TCPConnection::connected(err);
RodColeman 0:0791c1fece8e 90 if(_connected) {
RodColeman 0:0791c1fece8e 91 return (_connected)(this, err);
RodColeman 0:0791c1fece8e 92 } else {
RodColeman 0:0791c1fece8e 93 return ERR_OK;
RodColeman 0:0791c1fece8e 94 }
RodColeman 0:0791c1fece8e 95 }
RodColeman 0:0791c1fece8e 96
RodColeman 0:0791c1fece8e 97 /*
RodColeman 0:0791c1fece8e 98 * Function to be called whenever a fatal error occurs.
RodColeman 0:0791c1fece8e 99 * There is no pcb parameter since most of the times, the pcb is
RodColeman 0:0791c1fece8e 100 * already deallocated (or there is no pcb) when this function is called.
RodColeman 0:0791c1fece8e 101 * @param err an indication why the error callback is called:
RodColeman 0:0791c1fece8e 102 * ERR_ABRT: aborted through tcp_abort or by a TCP timer
RodColeman 0:0791c1fece8e 103 * ERR_RST: the connection was reset by the remote host
RodColeman 0:0791c1fece8e 104 */
RodColeman 0:0791c1fece8e 105 virtual void err(err_t erra) {
RodColeman 0:0791c1fece8e 106 if(_err) {
RodColeman 0:0791c1fece8e 107 (_err)(this, erra);
RodColeman 0:0791c1fece8e 108 }
RodColeman 0:0791c1fece8e 109 }
RodColeman 0:0791c1fece8e 110
RodColeman 0:0791c1fece8e 111 virtual void dnsreply(const char *hostname, struct ip_addr *addr) {};
RodColeman 0:0791c1fece8e 112
RodColeman 0:0791c1fece8e 113 err_t (*_sent)(TCPCallbackConnection *, u16_t);
RodColeman 0:0791c1fece8e 114 err_t (*_recv)(TCPCallbackConnection *, struct pbuf *p, err_t err);
RodColeman 0:0791c1fece8e 115 err_t (*_poll)(TCPCallbackConnection *);
RodColeman 0:0791c1fece8e 116 err_t (*_accept)(TCPCallbackConnection *, struct tcp_pcb *newpcb, err_t err);
RodColeman 0:0791c1fece8e 117 err_t (*_connected)(TCPCallbackConnection *, err_t err);
RodColeman 0:0791c1fece8e 118 void (*_err )(TCPCallbackConnection *, err_t);
RodColeman 0:0791c1fece8e 119 };
RodColeman 0:0791c1fece8e 120
RodColeman 0:0791c1fece8e 121 };
RodColeman 0:0791c1fece8e 122
RodColeman 0:0791c1fece8e 123 #endif /* TCPCALLBACKCONNECTION_H */