1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-13 12:05:21 +02:00

[fix] Bug 287158: [terminal][telnet] Connect worker is giving up to early

This commit is contained in:
Uwe Stieber 2009-08-20 10:03:58 +00:00
parent 874606fed5
commit f43b89df95

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2007 Wind River Systems, Inc. and others. * Copyright (c) 2003, 2009 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,8 +11,9 @@
* Helmut Haigermoser and Ted Williams. * Helmut Haigermoser and Ted Williams.
* *
* Contributors: * Contributors:
* Michael Scharf (Wind River) - extracted from TerminalControl * Michael Scharf (Wind River) - extracted from TerminalControl
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Martin Oberhuber (Wind River) - fixed copyright headers and beautified
* Uwe Stieber (Wind River) - [287158][terminal][telnet] Connect worker is giving up to early
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.telnet; package org.eclipse.tm.internal.terminal.telnet;
@ -35,43 +36,75 @@ class TelnetConnectWorker extends Thread {
fControl.setState(TerminalState.CONNECTING); fControl.setState(TerminalState.CONNECTING);
} }
public void run() { public void run() {
try { // Retry the connect with after a little pause in case the
int nTimeout = fConn.getTelnetSettings().getTimeout() * 1000; // remote telnet server isn't ready. ConnectExceptions might
String strHost = fConn.getTelnetSettings().getHost(); // happen if the telnet server process did not initialized itself.
int nPort = fConn.getTelnetSettings().getNetworkPort(); // This is seen especially if the telnet server is a process
InetSocketAddress address = new InetSocketAddress(strHost, nPort); // providing it's input and output via a built in telnet server.
Socket socket=new Socket(); int remaining = 10;
socket.connect(address, nTimeout); while (remaining >= 0) {
// Pause before we re-try if the remaining tries are less than the initial value
if (remaining < 10) try { Thread.sleep(500); } catch (InterruptedException e) { /* ignored on purpose */ }
// This next call causes reads on the socket to see TCP urgent data try {
// inline with the rest of the non-urgent data. Without this call, TCP int nTimeout = fConn.getTelnetSettings().getTimeout() * 1000;
// urgent data is silently dropped by Java. This is required for String strHost = fConn.getTelnetSettings().getHost();
// TELNET support, because when the TELNET server sends "IAC DM", the int nPort = fConn.getTelnetSettings().getNetworkPort();
// IAC byte is TCP urgent data. If urgent data is silently dropped, we InetSocketAddress address = new InetSocketAddress(strHost, nPort);
// only see the DM, which looks like an ISO Latin-1 '�' character. Socket socket=new Socket();
socket.setOOBInline(true); socket.connect(address, nTimeout);
fConn.setSocket(socket);
TelnetConnection connection=new TelnetConnection(fConn, socket); // If we get to this point, the connect succeeded and we will
socket.setKeepAlive(true); // force the remaining counter to be 0.
fConn.setTelnetConnection(connection); remaining = 0;
connection.start();
fControl.setState(TerminalState.CONNECTED);
} catch (UnknownHostException ex) { // This next call causes reads on the socket to see TCP urgent data
String txt="Unknown host: " + ex.getMessage(); //$NON-NLS-1$ // inline with the rest of the non-urgent data. Without this call, TCP
connectFailed(txt,"Unknown host: " + ex.getMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ // urgent data is silently dropped by Java. This is required for
} catch (SocketTimeoutException socketTimeoutException) { // TELNET support, because when the TELNET server sends "IAC DM", the
connectFailed(socketTimeoutException.getMessage(), "Connection Error!\n" + socketTimeoutException.getMessage()); //$NON-NLS-1$ // IAC byte is TCP urgent data. If urgent data is silently dropped, we
} catch (ConnectException connectException) { // only see the DM, which looks like an ISO Latin-1 '�' character.
connectFailed(connectException.getMessage(),"Connection refused!"); //$NON-NLS-1$
} catch (Exception exception) {
Logger.logException(exception);
connectFailed(exception.getMessage(),""); //$NON-NLS-1$ socket.setOOBInline(true);
fConn.setSocket(socket);
TelnetConnection connection=new TelnetConnection(fConn, socket);
socket.setKeepAlive(true);
fConn.setTelnetConnection(connection);
connection.start();
fControl.setState(TerminalState.CONNECTED);
} catch (UnknownHostException ex) {
// No re-try in case of UnknownHostException, there is no indication that
// the DNS will fix itself
remaining = 0;
//Construct error message and signal failed
String txt="Unknown host: " + ex.getMessage(); //$NON-NLS-1$
connectFailed(txt,"Unknown host: " + ex.getMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
} catch (SocketTimeoutException socketTimeoutException) {
// Time out occurred. No re-try in this case either. Time out can
// be increased by the user. Multiplying the timeout with the remaining
// counter is not desired.
remaining = 0;
// Construct error message and signal failed
connectFailed(socketTimeoutException.getMessage(), "Connection Error!\n" + socketTimeoutException.getMessage()); //$NON-NLS-1$
} catch (ConnectException connectException) {
// In case of a ConnectException, do a re-try. The server could have been
// simply not ready yet and the worker would give up to early.
if (remaining == 0) connectFailed(connectException.getMessage(),"Connection refused!"); //$NON-NLS-1$
} catch (Exception exception) {
// Any other exception on connect. No re-try in this case either
remaining = 0;
// Log the exception
Logger.logException(exception);
// And signal failed
connectFailed(exception.getMessage(),""); //$NON-NLS-1$
} finally {
remaining--;
}
} }
} }