aboutsummaryrefslogtreecommitdiff
path: root/src/IvyClient.java
diff options
context:
space:
mode:
authorjestin2002-03-07 14:13:30 +0000
committerjestin2002-03-07 14:13:30 +0000
commit61ac1763d6ae6455ac6962bcef931103c9298d61 (patch)
treeab427cbc53fe95deedb9c69824c2761ab18d899c /src/IvyClient.java
parent36739f8756462e6c6d6fbe0dd148b0d347775cd8 (diff)
downloadivy-java-61ac1763d6ae6455ac6962bcef931103c9298d61.zip
ivy-java-61ac1763d6ae6455ac6962bcef931103c9298d61.tar.gz
ivy-java-61ac1763d6ae6455ac6962bcef931103c9298d61.tar.bz2
ivy-java-61ac1763d6ae6455ac6962bcef931103c9298d61.tar.xz
*** empty log message ***
Diffstat (limited to 'src/IvyClient.java')
-rwxr-xr-xsrc/IvyClient.java38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/IvyClient.java b/src/IvyClient.java
index cfbc320..08864f4 100755
--- a/src/IvyClient.java
+++ b/src/IvyClient.java
@@ -53,6 +53,7 @@ public class IvyClient extends Thread {
this.bus = bus;
this.socket = socket;
this.peerCalling=peerCalling;
+ socket.setSoTimeout(100);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = socket.getOutputStream();
Hashtable regexps=bus.regexp_out;
@@ -115,9 +116,9 @@ public class IvyClient extends Thread {
* the thread managing the socket is stopped
*/
void close(String msg) throws IOException {
- traceDebug( msg );
- in.close();
+ traceDebug(msg);
gardefou=false;
+ socket.close(); // should I ?
}
/**
@@ -133,23 +134,21 @@ public class IvyClient extends Thread {
/**
* the code of the thread handling the incoming messages.
- * this thread stops (at least it should) when the socket is closed
- * or when gardefou=false
*/
public void run() {
String msg = null;
try {
traceDebug("Connected from "+ socket.getInetAddress().getHostName()+ ":"+socket.getPort());
- /*
- * TODO bug ?!
- * sometime we're stuck in readline while gardefou is false
- * we need non blocking IO, found in the next 1.4 jdk ...
- */
- while ( gardefou && ((msg=in.readLine()) != null )) {
+ while ( gardefou ) {
try {
- newParseMsg(msg);
+ if ((msg=in.readLine()) != null ) {
+ newParseMsg(msg);
+ }
} catch (IvyException ie) {
ie.printStackTrace();
+ } catch (InterruptedIOException ioe) {
+ // okay, nothing on the line
+ // do nothing but loop. It might be a bit resource-eating ...
}
}
traceDebug("normally Disconnected from "+ socket.getInetAddress().getHostName()+":"+socket.getPort());
@@ -160,8 +159,8 @@ public class IvyClient extends Thread {
traceDebug("abnormally Disconnected from "+
socket.getInetAddress().getHostName()+":"+socket.getPort());
}
- bus.disconnect( this );
- bus.removeClient( this );
+ bus.disconnect(this);
+ bus.removeClient(this);
}
private void sendBuffer( String buffer ) throws IvyException {
@@ -266,8 +265,8 @@ public class IvyClient extends Thread {
break;
case EndRegexp:
bus.connect(this);
- /* TODO
- * BUG ? the peer is perhaps not ready to handle this message
+ /* TODO ?
+ * the peer is perhaps not ready to handle this message
* an assymetric processing should be written
*/
if (bus.ready_message!=null) sendMsg(bus.ready_message);
@@ -278,12 +277,15 @@ public class IvyClient extends Thread {
while ( (to<b.length) && (b[to]!=3) ) to++;
if (to<b.length) {
v.add(s.substring(from,to));
- from=to;
to++;
+ from=to;
}
}
String[] tab = new String[v.size()];
- for (int i=0;i<v.size();i++) tab[i]=(String)v.elementAt(i);
+ for (int i=0;i<v.size();i++) {
+ tab[i]=(String)v.elementAt(i);
+ // System.out.println(" *"+tab[i]+"* "+(tab[i]).length());
+ }
bus.callCallback(this,msgId,tab);
break;
case Error:
@@ -319,7 +321,7 @@ public class IvyClient extends Thread {
private void sendDie(String message) {send(Die,0,message);}
private InetAddress getRemoteAddress() { return socket.getInetAddress(); }
private void traceDebug(String s){
- if (debug) System.out.println("-->IvyClient<-- "+s);
+ if (debug) System.out.println("-->IvyClient "+appName+"<-- "+s);
}
} // class IvyClient
/* EOF */