|
From: Markus B. <mba...@us...> - 2005-10-09 21:14:42
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31151/src/org/rubypeople/rdt/core Added Files: SocketUtil.java Log Message: moved from org.rubypeople.rdt.testunit to org.rubypeople.rdt.core because it is needed from org.rubypeople.rdt.debug.core, too --- NEW FILE: SocketUtil.java --- /******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.core; import java.io.IOException; import java.net.ServerSocket; /** * Utility class to find a port to debug on. */ public class SocketUtil { /** * Returns a free port number on localhost, or -1 if unable to find a free port. * * @return a free port number on localhost, or -1 if unable to find a free port * @since 3.0 */ public static int findFreePort() { ServerSocket socket= null; try { socket= new ServerSocket(0); return socket.getLocalPort(); } catch (IOException e) { } finally { if (socket != null) { try { socket.close(); } catch (IOException e) { } } } return -1; } } |