A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Committer:
root@mbed.org
Date:
Tue May 08 15:32:10 2012 +0100
Revision:
0:5e1631496985
initial commit

Who changed what in which revision?

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