Revision: 1827 http://svn.sourceforge.net/vexi/?rev=1827&view=rev Author: mkpg2 Date: 2007-05-27 04:27:47 -0700 (Sun, 27 May 2007)
Log Message: ----------- Test fix. NanoHTTPD was not quiting and freeing its port, so the 2nd test to not be able to setup properly. Modified Paths: -------------- core/trunk/org.vexi.core/src_junit/testdeployment/NanoHTTPD.java Modified: core/trunk/org.vexi.core/src_junit/testdeployment/NanoHTTPD.java =================================================================== --- core/trunk/org.vexi.core/src_junit/testdeployment/NanoHTTPD.java 2007-05-13 16:08:46 UTC (rev 1826) +++ core/trunk/org.vexi.core/src_junit/testdeployment/NanoHTTPD.java 2007-05-27 11:27:47 UTC (rev 1827) @@ -55,12 +55,17 @@ static public int PORT = 7070; private static NanoHTTPD singleton; - static public void start() throws IOException{ + static public void start() throws Exception{ if(singleton==null) singleton = new NanoHTTPD(PORT); } static public void stop() throws IOException{ - if(singleton!=null) singleton.myThread.interrupt(); + if(singleton!=null){ + singleton.myThread.interrupt(); + //REMARK hmm, interupting doesn't work - force the thread + //to exit by closing its socket on it. + singleton.ss.close(); + } singleton = null; } @@ -196,16 +201,26 @@ // Socket & server code // ================================================== + ServerSocket ss; /** * Starts a HTTP server to given port.<p> * Throws an IOException if the socket is already in use + * @throws InterruptedException */ - public NanoHTTPD( int port ) throws IOException + public NanoHTTPD( int port ) throws IOException, InterruptedException { myFileDir = new File(NanoHTTPD.class.getResource(".").getPath());; myTcpPort = port; - final ServerSocket ss = new ServerSocket( myTcpPort ); + // Retry, its possible the socket is still being released. + for(int i=0; i<10; i++){ + try{ + ss = new ServerSocket( myTcpPort ); + break; + }catch(BindException e){ + Thread.sleep(100*i); + } + } myThread = new Thread( new Runnable() { public void run() @@ -215,8 +230,13 @@ while( !Thread.interrupted() ) new HTTPSession( ss.accept()); } + catch ( SocketException e){ + // expected + } catch ( IOException ioe ) - {} + { + ioe.printStackTrace(); + } System.out.println("NanoHTTPD, finished serving"); } }); @@ -255,7 +275,7 @@ { nh = new NanoHTTPD( port ); } - catch( IOException ioe ) + catch( Exception ioe ) { System.err.println( "Couldn't start server:\n" + ioe ); System.exit( -1 ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn