aboutsummaryrefslogtreecommitdiff
path: root/src/IvyClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/IvyClient.java')
-rwxr-xr-xsrc/IvyClient.java32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/IvyClient.java b/src/IvyClient.java
index 0a06c55..4f46ca8 100755
--- a/src/IvyClient.java
+++ b/src/IvyClient.java
@@ -112,26 +112,21 @@ public class IvyClient implements Runnable {
IvyClient() { }
- IvyClient(Ivy bus, Socket socket,int remotePort) throws IOException {
+ IvyClient(Ivy bus, Socket socket,int remotePort,boolean incoming) throws IOException {
synchronized(csMutex) { clientKey=new Integer(clientSerial++); }
this.bus = bus;
this.remotePort = remotePort;
+ this.incoming = incoming;
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = socket.getOutputStream();
incoming=(remotePort==0);
traceDebug(((incoming)?"incoming":"outgoing")+" connection on "+socket);
this.socket = socket;
- if (!incoming) { // outgoing connexion
+ if (!incoming) {
synchronized(bus) {
bus.addHalf(this); // register a half connexion
- if (bus.shouldIleave(this)) {
- traceDebug(toStringExt()+" should leave ...");
- close(false);
- bus.removeHalf(this);
- return;
- }
sendSchizo();
- // the registering will take place at the reception of the regexps...
+ // the registering (handShake) will take place at the reception of the regexps...
}
}
remoteHostname = socket.getInetAddress().getHostName();
@@ -154,7 +149,7 @@ public class IvyClient implements Runnable {
sendString( EndRegexp,0,"");
}
- synchronized private void handShake() {
+ synchronized private void handShake() throws IvyException {
synchronized(bus) {
bus.removeHalf(this);
bus.addClient(this);
@@ -217,14 +212,16 @@ public class IvyClient implements Runnable {
traceDebug("closing connexion to "+appName);
if (notify) sendBye("hasta la vista");
stopListening();
- socket.close();
+ socket.close(); // TODO is it necessary ? trying to fix a deadlock
}
/**
* asks the remote client to leave the bus.
* @param message the message that will be carried
*/
- public void sendDie(String message) { sendString(Die,0,message); }
+ public void sendDie(String message) {
+ sendString(Die,0,message);
+ }
/**
* checks the "validity" of a regular expression.
@@ -420,6 +417,7 @@ public class IvyClient implements Runnable {
}
private boolean newParseMsg(String s) throws IvyException {
+ if (s==null) throw new IvyException("null string to parse in protocol");
byte[] b = s.getBytes();
int from=0,to=0,msgType;
Integer msgId;
@@ -530,16 +528,8 @@ public class IvyClient implements Runnable {
if (incoming) {
// incoming connexion, I wait for his token to send him mine ...
synchronized(bus) {
- bus.addHalf(this);
try {
- // there is another connexion. Should I leave ?
- // Assymetric processing to prevent concurrent disconnexions
- if (bus.shouldIleave(this)) {
- traceDebug(toStringExt()+" should leave ...");
- close(false);
- bus.removeHalf(this);
- return false;
- }
+ bus.addHalf(this);
sendSchizo();
handShake();
} catch (IOException ioe) {