Changeset 7734 for trunk/gsdl/src/java
- Timestamp:
- 2004-07-13T10:57:05+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/java/org/nzdl/gsdl/Phind/Phind.java
r6269 r7734 90 90 91 91 import java.net.Socket; 92 import java.net.SocketTimeoutException; 92 93 import java.net.InetAddress; 93 94 import java.net.UnknownHostException; … … 187 188 // ignored. 188 189 189 190 /** We're adding a timeout to the loop used to read the result from the 191 * server - partially because of the 'fails to return anything' death 192 * spiral - but also because its a good idea anyway. Why DataInputStream 193 * doesn't have a TimeOutException, given its most often used to get data 194 * from a URL, I don't know. Lets default it to 60 seconds. 195 * DLConsulting 12-07-2004 196 */ 197 private int timeout = 60; 198 190 199 public String getAppletInfo() { 191 200 return "Phind by Gordon Paynter ([email protected]). Copyright 1997-2000."; … … 457 466 // Send the query to the phindcgi program 458 467 System.out.println("sending query: " + query); 468 /** Start timeout counter. 469 * DLConsulting 12-07-2004 470 */ 471 int time = 0; 459 472 try { 460 473 URL phindcgi = new URL(query); … … 467 480 if (availableBytes == 0) { 468 481 // if i had threads i'd do a wait here for 1 second 482 /** Ah-ha but we do have threads here - at least one thread 483 * anyway! Note that we want to prevent interrupted 484 * exceptions flinging us out of the read loop. 485 * We also check that the time count hasn't reached out 486 * timeout threshold yet. If so, make use of the nifty 487 * execption handling. 488 * DLConsulting 12-07-2004 489 * Start... 490 */ 491 if(time >= timeout) { 492 throw new SocketTimeoutException( 493 "No data recieved in " + time + 494 " seconds. Connection timed-out."); 495 } 496 try { 497 Thread.sleep(1000); 498 } 499 catch(InterruptedException exception) { 500 System.err.println("Unexpected InterruptedException. Non-fatal."); 501 exception.printStackTrace(); 502 } 503 time++; 504 /** ...End */ 469 505 } else { 470 506 buffer = new byte[availableBytes]; … … 685 721 // expansion_bg = parameterValue("expansion_bg", Color.white); 686 722 // document_bg = parameterValue("document_bg", Color.white); 723 724 /** How long should the read loop wait before timing out? 725 * DLConsulting 12-07-2004 726 */ 727 timeout = parameterValue("timeout", 60); 687 728 } 688 729 … … 917 958 918 959 } 960
Note:
See TracChangeset
for help on using the changeset viewer.