less noisy logcat. catch illegal state exception as result of race condition

This commit is contained in:
Daniel Gultsch 2024-01-19 15:20:47 +01:00
parent b2e1f9b3d8
commit 4168bc4666
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2

View file

@ -191,7 +191,6 @@ public class WebRTCDataChannelTransport implements Transport {
new OnMessageObserver() {
@Override
public void onMessage(final DataChannel.Buffer buffer) {
Log.d(Config.LOGTAG, "onMessage() (the other one)");
try {
WebRTCDataChannelTransport.this.writableByteChannel.write(buffer.data);
} catch (final IOException e) {
@ -584,8 +583,7 @@ public class WebRTCDataChannelTransport implements Transport {
Log.d(Config.LOGTAG, "DataChannelWriter reached EOF");
return;
}
dataChannel.send(
new DataChannel.Buffer(ByteBuffer.wrap(buffer, 0, count), true));
send(ByteBuffer.wrap(buffer, 0, count));
}
} catch (final InterruptedException | InterruptedIOException e) {
if (isSending.get()) {
@ -598,6 +596,16 @@ public class WebRTCDataChannelTransport implements Transport {
}
}
private void send(final ByteBuffer byteBuffer) throws IOException {
try {
dataChannel.send(new DataChannel.Buffer(byteBuffer, true));
} catch (final IllegalStateException e) {
// dataChannel can be 'disposed' if we waited too long between `isSending` check and
// actually trying to send
throw new IOException(e);
}
}
public void close() {
this.isSending.set(false);
terminate(this.dataChannel);