mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-13 03:55: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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -11,8 +11,9 @@
|
|||
* Helmut Haigermoser and Ted Williams.
|
||||
*
|
||||
* Contributors:
|
||||
* Michael Scharf (Wind River) - extracted from TerminalControl
|
||||
* Michael Scharf (Wind River) - extracted from TerminalControl
|
||||
* 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;
|
||||
|
||||
|
@ -35,43 +36,75 @@ class TelnetConnectWorker extends Thread {
|
|||
fControl.setState(TerminalState.CONNECTING);
|
||||
}
|
||||
public void run() {
|
||||
try {
|
||||
int nTimeout = fConn.getTelnetSettings().getTimeout() * 1000;
|
||||
String strHost = fConn.getTelnetSettings().getHost();
|
||||
int nPort = fConn.getTelnetSettings().getNetworkPort();
|
||||
InetSocketAddress address = new InetSocketAddress(strHost, nPort);
|
||||
Socket socket=new Socket();
|
||||
// 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;
|
||||
|
||||
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
|
||||
// inline with the rest of the non-urgent data. Without this call, TCP
|
||||
// urgent data is silently dropped by Java. This is required for
|
||||
// TELNET support, because when the TELNET server sends "IAC DM", the
|
||||
// IAC byte is TCP urgent data. If urgent data is silently dropped, we
|
||||
// only see the DM, which looks like an ISO Latin-1 '�' character.
|
||||
try {
|
||||
int nTimeout = fConn.getTelnetSettings().getTimeout() * 1000;
|
||||
String strHost = fConn.getTelnetSettings().getHost();
|
||||
int nPort = fConn.getTelnetSettings().getNetworkPort();
|
||||
InetSocketAddress address = new InetSocketAddress(strHost, nPort);
|
||||
Socket socket=new Socket();
|
||||
|
||||
socket.setOOBInline(true);
|
||||
|
||||
fConn.setSocket(socket);
|
||||
socket.connect(address, nTimeout);
|
||||
|
||||
TelnetConnection connection=new TelnetConnection(fConn, socket);
|
||||
socket.setKeepAlive(true);
|
||||
fConn.setTelnetConnection(connection);
|
||||
connection.start();
|
||||
fControl.setState(TerminalState.CONNECTED);
|
||||
// If we get to this point, the connect succeeded and we will
|
||||
// force the remaining counter to be 0.
|
||||
remaining = 0;
|
||||
|
||||
} catch (UnknownHostException ex) {
|
||||
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) {
|
||||
connectFailed(socketTimeoutException.getMessage(), "Connection Error!\n" + socketTimeoutException.getMessage()); //$NON-NLS-1$
|
||||
} catch (ConnectException connectException) {
|
||||
connectFailed(connectException.getMessage(),"Connection refused!"); //$NON-NLS-1$
|
||||
} catch (Exception exception) {
|
||||
Logger.logException(exception);
|
||||
// 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
|
||||
// urgent data is silently dropped by Java. This is required for
|
||||
// TELNET support, because when the TELNET server sends "IAC DM", the
|
||||
// IAC byte is TCP urgent data. If urgent data is silently dropped, we
|
||||
// only see the DM, which looks like an ISO Latin-1 '�' character.
|
||||
|
||||
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--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue