Exemplo n.º 1
0
void CDebug::run() {
	if ( m_port==DBG_USB ) {
		//
		// USB port
		//
		CSerial cdc(USB);
		m_shell.assign(cdc);
		while(1) {
			if ( cdc.isConnected() ) {
				m_shell.run();
			}
		}

	} else {
		//
		// Telnet (TCP/IP port 23)
		//
		CSocket server;
		CSocket *client;

		server.create(SOCK_STREAM);
		server.bind(TELNET_PORT);
		server.listen();
		while (1) {
			if ((client = server.accept()) != NULL) {
				client->keepAlive(3, 3, 3);	// set keep alive in 3 seconds for idle, try in 3 seconds and 3 times
				m_shell.assign(client);
				m_shell.run();
				delete client;
			}
		}
	}
}