### Eclipse Workspace Patch 1.0 #P org.eclipse.rse.connectorservice.telnet Index: src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.tm.rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java,v retrieving revision 1.25 diff -u -r1.25 TelnetConnectorService.java --- src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java 2 Aug 2009 12:01:39 -0000 1.25 +++ src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java 30 May 2012 14:53:18 -0000 @@ -72,9 +72,11 @@ public static final String PROPERTY_LOGIN_PROMPT = "Login.Prompt"; //$NON-NLS-1$ public static final String PROPERTY_PASSWORD_PROMPT = "Password.Prompt"; //$NON-NLS-1$ public static final String PROPERTY_COMMAND_PROMPT = "Command.Prompt"; //$NON-NLS-1$ + public static final String PROPERTY_LOGIN_READ_TIMEOUT = "Login.Timeout"; //$NON-NLS-1$ private static final int TELNET_DEFAULT_PORT = 23; // TODO Make configurable private static final int TELNET_CONNECT_TIMEOUT = 60; //seconds - TODO: Make configurable + private static final int TELNET_LOGIN_READ_TIMEOUT = 1000; //msecs by default private List fTelnetClients = new ArrayList(); private SessionLostHandler fSessionLostHandler; private IPropertySet telnetPropertySet = null; @@ -101,6 +103,7 @@ */ protected IPropertySet getTelnetPropertySet() { IPropertySet telnetSet = getPropertySet(PROPERTY_SET_NAME); + if (telnetSet == null) { telnetSet = createPropertySet(PROPERTY_SET_NAME, TelnetConnectorResources.PropertySet_Description); @@ -111,7 +114,9 @@ telnetSet.addProperty(PROPERTY_PASSWORD_PROMPT, "assword: ", PropertyType.getStringPropertyType()); //$NON-NLS-1$ telnetSet.addProperty(PROPERTY_COMMAND_PROMPT, - "$", PropertyType.getStringPropertyType()); //$NON-NLS-1$ + "", PropertyType.getStringPropertyType()); //$NON-NLS-1$ + telnetSet.addProperty(PROPERTY_LOGIN_READ_TIMEOUT, + "1000", PropertyType.getIntegerPropertyType()); //$NON-NLS-1$ } return telnetSet; } @@ -258,11 +263,30 @@ } } - public int readUntil(String pattern,InputStream in) { + int read_withtime(InputStream in, long timeout) { + long millisToEnd = System.currentTimeMillis() + timeout; + try { + while (System.currentTimeMillis()0) + return in.read(); + else + Thread.sleep(100); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return -1; + } + + public int readUntil(String pattern, InputStream in, long timeout) { + try { char lastChar = pattern.charAt(pattern.length() - 1); StringBuffer sb = new StringBuffer(); - int ch = in.read(); + int ch = read_withtime(in, timeout); while (ch >= 0) { char tch = (char) ch; if (Activator.isTracingOn()) @@ -279,7 +303,7 @@ return SUCCESS_CODE; } } - ch = in.read(); + ch = read_withtime(in, timeout); } } catch (Exception e) { SystemBasePlugin.logError(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), e); @@ -547,23 +571,42 @@ .getPropertyValue(PROPERTY_PASSWORD_PROMPT); String command_prompt = telnetPropertySet .getPropertyValue(PROPERTY_COMMAND_PROMPT); + long read_timeout = TELNET_LOGIN_READ_TIMEOUT; + String read_timeoutS = telnetPropertySet.getPropertyValue(PROPERTY_LOGIN_READ_TIMEOUT); + if (read_timeoutS == null) { + // legacy connection without the timeout property configured: use legacy default connect timeout + read_timeout = 60000; + } else if (read_timeoutS.trim().length()>0) { + try { + read_timeout = Long.decode(read_timeoutS).longValue(); + } catch(NumberFormatException e) {} + } if (Boolean.valueOf(login_required).booleanValue()) { status = SUCCESS_CODE; if (login_prompt != null && login_prompt.length() > 0) { - status = readUntil(login_prompt,this.in); + status = readUntil(login_prompt,this.in, read_timeout); write(username,this.out); } if (status == SUCCESS_CODE && password_prompt != null && password_prompt.length() > 0) { - status = readUntil(password_prompt,this.in); + status = readUntil(password_prompt,this.in, read_timeout); write(password,this.out); } if (status == SUCCESS_CODE && command_prompt != null && command_prompt.length() > 0) { - status = readUntil(command_prompt,this.in); + status = readUntil(command_prompt,this.in, read_timeout); } } else { + status = SUCCESS_CODE; + /* + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ if (command_prompt != null && command_prompt.length() > 0) { - status = readUntil(command_prompt,this.in); + status = readUntil(command_prompt,this.in, read_timeout); } } }