Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of lwip by
TCPCallbackConnection.h
00001 #ifndef TCPCALLBACKCONNECTION_H 00002 #define TCPCALLBACKCONNECTION_H 00003 00004 #include "TCPConnection.h" 00005 00006 namespace mbed { 00007 00008 #define NO_SENT_FNC ((err_t (*)(TCPCallbackConnection *, u16_t))NULL) 00009 #define NO_RECV_FNC ((err_t (*)(TCPCallbackConnection *, struct pbuf *, err_t))NULL) 00010 #define NO_POLL_FNC ((err_t (*)(TCPCallbackConnection *))NULL) 00011 #define NO_ACCEPT_FNC ((err_t (*)(TCPCallbackConnection *, struct tcp_pcb *, err_t))NULL) 00012 #define NO_CONNECT_FNC ((err_t (*)(TCPCallbackConnection *, err_t))NULL) 00013 #define NO_ERR_FNC ((void (*)(TCPCallbackConnection *, err_t))NULL) 00014 00015 00016 class TCPCallbackConnection : public TCPConnection { 00017 public: 00018 TCPCallbackConnection(struct ip_addr ip_addr, u16_t port, 00019 err_t (*psent)(TCPCallbackConnection *, u16_t), 00020 err_t (*precv)(TCPCallbackConnection *, struct pbuf *, err_t), 00021 err_t (*ppoll)(TCPCallbackConnection *), 00022 err_t (*pconnected)(TCPCallbackConnection *, err_t), 00023 void (*perr )(TCPCallbackConnection *, err_t)) 00024 : TCPConnection(ip_addr, port) { 00025 _sent = psent; 00026 _recv = precv; 00027 _poll = ppoll; 00028 _connected = pconnected; 00029 _err = perr; 00030 } 00031 00032 TCPCallbackConnection(TCPListener *parent, struct tcp_pcb *npcb, 00033 err_t (*psent)(TCPCallbackConnection *, u16_t), 00034 err_t (*precv)(TCPCallbackConnection *, struct pbuf *, err_t), 00035 err_t (*ppoll)(TCPCallbackConnection *), 00036 err_t (*pconnected)(TCPCallbackConnection *, err_t), 00037 void (*perr )(TCPCallbackConnection *, err_t)) 00038 : TCPConnection(parent, npcb) { 00039 _sent = psent; 00040 _recv = precv; 00041 _poll = ppoll; 00042 _connected = pconnected; 00043 _err = perr; 00044 } 00045 00046 private: 00047 /* 00048 * Function to be called when more send buffer space is available. 00049 * @param space the amount of bytes available 00050 * @return ERR_OK: try to send some data by calling tcp_output 00051 */ 00052 virtual err_t sent(u16_t space) { 00053 if(_sent) { 00054 return (_sent)(this, space); 00055 } else { 00056 return ERR_OK; 00057 } 00058 } 00059 00060 /* 00061 * Function to be called when (in-sequence) data has arrived. 00062 * @param p the packet buffer which arrived 00063 * @param err an error argument (TODO: that is current always ERR_OK?) 00064 * @return ERR_OK: try to send some data by calling tcp_output 00065 */ 00066 virtual err_t recv(struct pbuf *p, err_t err) { 00067 if(_recv) { 00068 return (_recv)(this, p, err); 00069 } else { 00070 return ERR_OK; 00071 } 00072 } 00073 00074 /* 00075 * Function which is called periodically. 00076 * The period can be adjusted in multiples of the TCP slow timer interval 00077 * by changing tcp_pcb.polltmr. 00078 * @return ERR_OK: try to send some data by calling tcp_output 00079 */ 00080 virtual err_t poll() { 00081 if(_poll) { 00082 return (_poll)(this); 00083 } else { 00084 return ERR_OK; 00085 } 00086 } 00087 00088 virtual err_t connected(err_t err) { 00089 err = TCPConnection::connected(err); 00090 if(_connected) { 00091 return (_connected)(this, err); 00092 } else { 00093 return ERR_OK; 00094 } 00095 } 00096 00097 /* 00098 * Function to be called whenever a fatal error occurs. 00099 * There is no pcb parameter since most of the times, the pcb is 00100 * already deallocated (or there is no pcb) when this function is called. 00101 * @param err an indication why the error callback is called: 00102 * ERR_ABRT: aborted through tcp_abort or by a TCP timer 00103 * ERR_RST: the connection was reset by the remote host 00104 */ 00105 virtual void err(err_t erra) { 00106 if(_err) { 00107 (_err)(this, erra); 00108 } 00109 } 00110 00111 virtual void dnsreply(const char *hostname, struct ip_addr *addr) {}; 00112 00113 err_t (*_sent)(TCPCallbackConnection *, u16_t); 00114 err_t (*_recv)(TCPCallbackConnection *, struct pbuf *p, err_t err); 00115 err_t (*_poll)(TCPCallbackConnection *); 00116 err_t (*_accept)(TCPCallbackConnection *, struct tcp_pcb *newpcb, err_t err); 00117 err_t (*_connected)(TCPCallbackConnection *, err_t err); 00118 void (*_err )(TCPCallbackConnection *, err_t); 00119 }; 00120 00121 }; 00122 00123 #endif /* TCPCALLBACKCONNECTION_H */
Generated on Tue Jul 12 2022 16:07:19 by
1.7.2
