Skip to content

Commit

Permalink
Removing blocking function (#56)
Browse files Browse the repository at this point in the history
* Removing blocking function

This fixes #47
The ´InetAddress.getHostName()´ blocks and does not resolve if there is no DNS server (example using an IOT device in AP mode, e.g. ESP8266), so I'm changing it to ´InetAddress.getHostAddress()´ as it is non-blocking.

* Update for Android 7+
  • Loading branch information
cristovao-trevisan authored and mvayngrib committed Jan 5, 2020
1 parent 2bbef63 commit ed8468a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions android/src/main/java/com/tradle/react/UdpSockets.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.net.wifi.WifiManager;
import android.support.annotation.Nullable;
import android.util.SparseArray;
import android.os.AsyncTask;

import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.Arguments;
Expand Down Expand Up @@ -72,7 +73,7 @@ protected void doInBackgroundGuarded(Void... params) {
}
mClients.clear();
}
}.execute().get();
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR).get();
} catch (InterruptedException ioe) {
FLog.e(TAG, "onCatalystInstanceDestroy", ioe);
} catch (ExecutionException ee) {
Expand Down Expand Up @@ -118,7 +119,7 @@ protected void doInBackgroundGuarded(Void... params) {
UdpSocketClient.Builder builder = new UdpSocketClient.Builder(UdpSockets.this, UdpSockets.this);
mClients.put(cId, builder.build());
}
}.execute();
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

/**
Expand All @@ -132,7 +133,7 @@ public void bind(final Integer cId, final Integer port, final @Nullable String a
protected void doInBackgroundGuarded(Void... params) {
UdpSocketClient client = findClient(cId, callback);
if (client == null) {
return;
return;
}

try {
Expand All @@ -154,7 +155,7 @@ protected void doInBackgroundGuarded(Void... params) {
callback.invoke(UdpErrorUtil.getError(null, ioe.getMessage()));
}
}
}.execute();
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

/**
Expand Down Expand Up @@ -201,7 +202,7 @@ protected void doInBackgroundGuarded(Void... params) {
FLog.e(TAG, "addMembership", ioe);
}
}
}.execute();
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

/**
Expand All @@ -228,7 +229,7 @@ protected void doInBackgroundGuarded(Void... params) {
}
}
}
}.execute();
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

/**
Expand Down Expand Up @@ -256,7 +257,7 @@ protected void doInBackgroundGuarded(Void... params) {
callback.invoke(UdpErrorUtil.getError(null, ioe.getMessage()));
}
}
}.execute();
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

/**
Expand Down Expand Up @@ -286,7 +287,7 @@ protected void doInBackgroundGuarded(Void... params) {

mClients.remove(cId);
}
}.execute();
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

/**
Expand All @@ -309,7 +310,7 @@ protected void doInBackgroundGuarded(Void... params) {
callback.invoke(UdpErrorUtil.getError(null, e.getMessage()));
}
}
}.execute();
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

/**
Expand Down Expand Up @@ -343,7 +344,7 @@ protected void doInBackgroundGuarded(Void... params) {
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("udp-" + clientID + "-data", eventParams);
}
}.execute();
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

/**
Expand Down

0 comments on commit ed8468a

Please sign in to comment.