Robert Cook
/
NetworkAnimator
TCPEchoHandler.h@0:32a0996dff0f, 2012-06-13 (annotated)
- Committer:
- robertcook
- Date:
- Wed Jun 13 18:39:46 2012 +0000
- Revision:
- 0:32a0996dff0f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robertcook | 0:32a0996dff0f | 1 | #ifndef TCP_ECHO_HANDLER_H |
robertcook | 0:32a0996dff0f | 2 | #define TCP_ECHO_HANDLER_H |
robertcook | 0:32a0996dff0f | 3 | |
robertcook | 0:32a0996dff0f | 4 | #include "mbed.h" |
robertcook | 0:32a0996dff0f | 5 | #include "TCPSocket.h" |
robertcook | 0:32a0996dff0f | 6 | #include "netservice.h" |
robertcook | 0:32a0996dff0f | 7 | |
robertcook | 0:32a0996dff0f | 8 | // Constant: ECHO_TIMOUT |
robertcook | 0:32a0996dff0f | 9 | // The timeout period for inactivity in milliseconds |
robertcook | 0:32a0996dff0f | 10 | #define ECHO_TIMEOUT 5000 |
robertcook | 0:32a0996dff0f | 11 | |
robertcook | 0:32a0996dff0f | 12 | /* |
robertcook | 0:32a0996dff0f | 13 | Class: TCPEchoHandler |
robertcook | 0:32a0996dff0f | 14 | A class instantiated to handle the incoming TCP client connection |
robertcook | 0:32a0996dff0f | 15 | Extends NetService to hook into the TCP/IP stack's polling |
robertcook | 0:32a0996dff0f | 16 | and destruction service |
robertcook | 0:32a0996dff0f | 17 | */ |
robertcook | 0:32a0996dff0f | 18 | class TCPEchoHandler : public NetService { |
robertcook | 0:32a0996dff0f | 19 | public: |
robertcook | 0:32a0996dff0f | 20 | // Constructor: TCPEchoHandler |
robertcook | 0:32a0996dff0f | 21 | // Setup and handle the incoming connection |
robertcook | 0:32a0996dff0f | 22 | TCPEchoHandler(TCPSocket*); |
robertcook | 0:32a0996dff0f | 23 | virtual ~TCPEchoHandler(); |
robertcook | 0:32a0996dff0f | 24 | private: |
robertcook | 0:32a0996dff0f | 25 | // Variable: clientSocket |
robertcook | 0:32a0996dff0f | 26 | // The incoming TCP socket from the client |
robertcook | 0:32a0996dff0f | 27 | TCPSocket* clientSocket; |
robertcook | 0:32a0996dff0f | 28 | // Variable: closed |
robertcook | 0:32a0996dff0f | 29 | // A marker to say whether this socket is already closed |
robertcook | 0:32a0996dff0f | 30 | int closed; |
robertcook | 0:32a0996dff0f | 31 | // Variable: timeoutWatchdog |
robertcook | 0:32a0996dff0f | 32 | // A timer to countdown from during inactivity and close |
robertcook | 0:32a0996dff0f | 33 | // dormant connections |
robertcook | 0:32a0996dff0f | 34 | Timeout timeoutWatchdog; |
robertcook | 0:32a0996dff0f | 35 | |
robertcook | 0:32a0996dff0f | 36 | // Function: onNetTcpSocketEvent |
robertcook | 0:32a0996dff0f | 37 | // The callback function called by the network stack whenever an |
robertcook | 0:32a0996dff0f | 38 | // event occurs on the TCP socket |
robertcook | 0:32a0996dff0f | 39 | // Parameter: e - The event that has occurred |
robertcook | 0:32a0996dff0f | 40 | void onTCPSocketEvent(TCPSocketEvent e); |
robertcook | 0:32a0996dff0f | 41 | // Function: close |
robertcook | 0:32a0996dff0f | 42 | // Closes the client socket and marks this class as done with |
robertcook | 0:32a0996dff0f | 43 | // for the TCP/IP stack to destroy |
robertcook | 0:32a0996dff0f | 44 | virtual void close(); |
robertcook | 0:32a0996dff0f | 45 | // Function: setTimeout |
robertcook | 0:32a0996dff0f | 46 | // Parameter: timeout - The length of time to wait for more activity in milliseconds |
robertcook | 0:32a0996dff0f | 47 | void setTimeout(unsigned int timeout); |
robertcook | 0:32a0996dff0f | 48 | // Function: onTimeout |
robertcook | 0:32a0996dff0f | 49 | // The handler called by the timeout watchdog to close the connection when timed out |
robertcook | 0:32a0996dff0f | 50 | void onTimeout(); |
robertcook | 0:32a0996dff0f | 51 | }; |
robertcook | 0:32a0996dff0f | 52 | |
robertcook | 0:32a0996dff0f | 53 | #endif |