Echo Server based on the legacy EthernetNetIf libraries used for a performance comparison with the new networking libraries
Dependencies: EthernetNetIf mbed
Fork of EchoServer by
TCPEchoHandler.h
00001 #ifndef TCP_ECHO_HANDLER_H 00002 #define TCP_ECHO_HANDLER_H 00003 00004 #include "mbed.h" 00005 #include "TCPSocket.h" 00006 #include <netservice.h> 00007 // Constant: ECHO_TIMOUT 00008 // The timeout period for inactivity in milliseconds 00009 #define ECHO_TIMEOUT 5000 00010 00011 /* 00012 Class: TCPEchoHandler 00013 A class instantiated to handle the incoming TCP client connection 00014 Extends NetService to hook into the TCP/IP stack's polling 00015 and destruction service 00016 */ 00017 class TCPEchoHandler : public NetService { 00018 public: 00019 // Constructor: TCPEchoHandler 00020 // Setup and handle the incoming connection 00021 TCPEchoHandler(TCPSocket*); 00022 virtual ~TCPEchoHandler(); 00023 private: 00024 // Variable: clientSocket 00025 // The incoming TCP socket from the client 00026 TCPSocket* clientSocket; 00027 // Variable: closed 00028 // A marker to say whether this socket is already closed 00029 int closed; 00030 // Variable: timeoutWatchdog 00031 // A timer to countdown from during inactivity and close 00032 // dormant connections 00033 Timeout timeoutWatchdog; 00034 00035 // Function: onNetTcpSocketEvent 00036 // The callback function called by the network stack whenever an 00037 // event occurs on the TCP socket 00038 // Parameter: e - The event that has occurred 00039 void onTCPSocketEvent(TCPSocketEvent e); 00040 // Function: close 00041 // Closes the client socket and marks this class as done with 00042 // for the TCP/IP stack to destroy 00043 virtual void close(); 00044 // Function: setTimeout 00045 // Parameter: timeout - The length of time to wait for more activity in milliseconds 00046 void setTimeout(unsigned int timeout); 00047 // Function: onTimeout 00048 // The handler called by the timeout watchdog to close the connection when timed out 00049 void onTimeout(); 00050 }; 00051 00052 #endif
Generated on Tue Jul 26 2022 23:07:02 by 1.7.2