mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-13 20:15:22 +02:00
[fix] Bug 287158: [terminal][telnet] Connect worker is giving up to early
This commit is contained in:
parent
874606fed5
commit
f43b89df95
1 changed files with 66 additions and 33 deletions
|
@ -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
|
||||||
|
@ -13,6 +13,7 @@
|
||||||
* 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,6 +36,17 @@ class TelnetConnectWorker extends Thread {
|
||||||
fControl.setState(TerminalState.CONNECTING);
|
fControl.setState(TerminalState.CONNECTING);
|
||||||
}
|
}
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// Retry the connect with after a little pause in case the
|
||||||
|
// remote telnet server isn't ready. ConnectExceptions might
|
||||||
|
// happen if the telnet server process did not initialized itself.
|
||||||
|
// This is seen especially if the telnet server is a process
|
||||||
|
// providing it's input and output via a built in telnet server.
|
||||||
|
int remaining = 10;
|
||||||
|
|
||||||
|
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 */ }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int nTimeout = fConn.getTelnetSettings().getTimeout() * 1000;
|
int nTimeout = fConn.getTelnetSettings().getTimeout() * 1000;
|
||||||
String strHost = fConn.getTelnetSettings().getHost();
|
String strHost = fConn.getTelnetSettings().getHost();
|
||||||
|
@ -44,6 +56,10 @@ class TelnetConnectWorker extends Thread {
|
||||||
|
|
||||||
socket.connect(address, nTimeout);
|
socket.connect(address, nTimeout);
|
||||||
|
|
||||||
|
// If we get to this point, the connect succeeded and we will
|
||||||
|
// force the remaining counter to be 0.
|
||||||
|
remaining = 0;
|
||||||
|
|
||||||
// This next call causes reads on the socket to see TCP urgent data
|
// This next call causes reads on the socket to see TCP urgent data
|
||||||
// inline with the rest of the non-urgent data. Without this call, TCP
|
// inline with the rest of the non-urgent data. Without this call, TCP
|
||||||
// urgent data is silently dropped by Java. This is required for
|
// urgent data is silently dropped by Java. This is required for
|
||||||
|
@ -62,16 +78,33 @@ class TelnetConnectWorker extends Thread {
|
||||||
fControl.setState(TerminalState.CONNECTED);
|
fControl.setState(TerminalState.CONNECTED);
|
||||||
|
|
||||||
} catch (UnknownHostException ex) {
|
} 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$
|
String txt="Unknown host: " + ex.getMessage(); //$NON-NLS-1$
|
||||||
connectFailed(txt,"Unknown host: " + ex.getMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
connectFailed(txt,"Unknown host: " + ex.getMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
} catch (SocketTimeoutException socketTimeoutException) {
|
} 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$
|
connectFailed(socketTimeoutException.getMessage(), "Connection Error!\n" + socketTimeoutException.getMessage()); //$NON-NLS-1$
|
||||||
} catch (ConnectException connectException) {
|
} catch (ConnectException connectException) {
|
||||||
connectFailed(connectException.getMessage(),"Connection refused!"); //$NON-NLS-1$
|
// 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) {
|
} catch (Exception exception) {
|
||||||
|
// Any other exception on connect. No re-try in this case either
|
||||||
|
remaining = 0;
|
||||||
|
// Log the exception
|
||||||
Logger.logException(exception);
|
Logger.logException(exception);
|
||||||
|
// And signal failed
|
||||||
connectFailed(exception.getMessage(),""); //$NON-NLS-1$
|
connectFailed(exception.getMessage(),""); //$NON-NLS-1$
|
||||||
|
} finally {
|
||||||
|
remaining--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue