Skip to content
This repository has been archived by the owner on Jul 31, 2019. It is now read-only.

Commit

Permalink
Improve UDP socket logic, fixing various issues with concurrency when…
Browse files Browse the repository at this point in the history
… sending messages.
  • Loading branch information
acomminos committed Aug 23, 2017
1 parent 4a44ab6 commit 4a0fe1d
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 100 deletions.
13 changes: 4 additions & 9 deletions src/main/java/com/morlunk/jumble/net/JumbleConnection.java
Expand Up @@ -625,17 +625,12 @@ public void onTCPConnectionEstablished() {
mConnected = true;

// Attempt to start UDP thread once connected.
if(!shouldForceTCP()) {
try {
mUDP = new JumbleUDP(mCryptState);
mUDP.setUDPConnectionListener(this);
mUDP.connect(mHost, mPort);
} catch (ConnectException e) {
onUDPConnectionError(e);
}
if (!shouldForceTCP()) {
mUDP = new JumbleUDP(mCryptState, this, mMainHandler);
mUDP.connect(mHost, mPort);
}

if(mListener != null) mListener.onConnectionEstablished();
if (mListener != null) mListener.onConnectionEstablished();
}

@Override
Expand Down
Expand Up @@ -27,6 +27,7 @@
* Base class for TCP/UDP protocol implementations.
* Provides a common threading model (single threaded queue for write)
* Created by andrew on 25/03/14.
* @deprecated This shouldn't be needed. Redundant inheritance with limited shared code.
*/
public abstract class JumbleNetworkThread implements Runnable {

Expand Down
30 changes: 21 additions & 9 deletions src/main/java/com/morlunk/jumble/net/JumbleTCP.java
Expand Up @@ -126,15 +126,6 @@ public void run() {
});
}
}

if(mListener != null) {
executeOnMainThread(new Runnable() {
@Override
public void run() {
mListener.onTCPConnectionDisconnect();
}
});
}
} catch (SocketException e) {
error("Could not open a connection to the host", e);
} catch (SSLHandshakeException e) {
Expand Down Expand Up @@ -162,6 +153,13 @@ public void run() {
e.printStackTrace();
}
mRunning = false;

executeOnMainThread(new Runnable() {
@Override
public void run() {
mListener.onTCPConnectionDisconnect();
}
});
stopThreads();
}
}
Expand Down Expand Up @@ -215,6 +213,8 @@ public void run() {
* Attempts to disconnect gracefully on the Tx thread.
* Disconnects interrupt the socket listening on the Tx thread, suppressing any exceptions
* caused by this request. Any remaining protobuf messages will be dispatched first.
*
* Suppresses all future errors on this connection.
*/
public void disconnect() {
if (!mRunning) return;
Expand Down Expand Up @@ -256,6 +256,18 @@ public void run() {
});
}

/**
* Runnable that
*/
private static class OutboxConsumer implements Runnable {


@Override
public void run() {

}
}

public interface TCPConnectionListener {
public void onTCPConnectionEstablished();
public void onTLSHandshakeFailed(X509Certificate[] chain);
Expand Down

0 comments on commit 4a0fe1d

Please sign in to comment.