mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-30 11:02:31 -06:00
628 lines
36 KiB
Java
628 lines
36 KiB
Java
|
package okhttp3.internal.ws;
|
||
|
|
||
|
import androidx.core.app.NotificationCompat;
|
||
|
import com.google.common.net.HttpHeaders;
|
||
|
import io.sentry.ProfilingTraceData;
|
||
|
import io.sentry.SentryBaseEvent;
|
||
|
import io.sentry.clientreport.DiscardedEvent;
|
||
|
import io.sentry.okhttp.SentryOkHttpEventListener;
|
||
|
import io.sentry.protocol.Response;
|
||
|
import io.sentry.protocol.TransactionInfo;
|
||
|
import java.io.Closeable;
|
||
|
import java.io.IOException;
|
||
|
import java.net.ProtocolException;
|
||
|
import java.net.SocketTimeoutException;
|
||
|
import java.util.ArrayDeque;
|
||
|
import java.util.List;
|
||
|
import java.util.Random;
|
||
|
import java.util.concurrent.TimeUnit;
|
||
|
import kotlin.Metadata;
|
||
|
import kotlin.Unit;
|
||
|
import kotlin.collections.CollectionsKt;
|
||
|
import kotlin.jvm.internal.Intrinsics;
|
||
|
import kotlin.text.StringsKt;
|
||
|
import okhttp3.Call;
|
||
|
import okhttp3.Callback;
|
||
|
import okhttp3.EventListener;
|
||
|
import okhttp3.OkHttpClient;
|
||
|
import okhttp3.Protocol;
|
||
|
import okhttp3.Request;
|
||
|
import okhttp3.WebSocket;
|
||
|
import okhttp3.WebSocketListener;
|
||
|
import okhttp3.internal.Util;
|
||
|
import okhttp3.internal.concurrent.Task;
|
||
|
import okhttp3.internal.concurrent.TaskQueue;
|
||
|
import okhttp3.internal.concurrent.TaskRunner;
|
||
|
import okhttp3.internal.connection.Exchange;
|
||
|
import okhttp3.internal.connection.RealCall;
|
||
|
import okhttp3.internal.ws.RealWebSocket;
|
||
|
import okhttp3.internal.ws.WebSocketReader;
|
||
|
import okio.BufferedSink;
|
||
|
import okio.BufferedSource;
|
||
|
import okio.ByteString;
|
||
|
|
||
|
/* compiled from: RealWebSocket.kt */
|
||
|
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000¶\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u001c\u0018\u0000 `2\u00020\u00012\u00020\u0002:\u0005_`abcB?\u0012\u0006\u0010\u0003\u001a\u00020\u0004\u0012\u0006\u0010\u0005\u001a\u00020\u0006\u0012\u0006\u0010\u0007\u001a\u00020\b\u0012\u0006\u0010\t\u001a\u00020\n\u0012\u0006\u0010\u000b\u001a\u00020\f\u0012\b\u0010\r\u001a\u0004\u0018\u00010\u000e\u0012\u0006\u0010\u000f\u001a\u00020\f¢\u0006\u0002\u0010\u0010J\u0016\u00102\u001a\u0002032\u0006\u00104\u001a\u00020\f2\u0006\u00105\u001a\u000206J\b\u00107\u001a\u000203H\u0016J\u001f\u00108\u001a\u0002032\u0006\u00109\u001a\u00020:2\b\u0010;\u001a\u0004\u0018\u00010<H\u0000¢\u0006\u0002\b=J\u001a\u0010>\u001a\u00020\u00122\u0006\u0010?\u001a\u00020%2\b\u0010@\u001a\u0004\u0018\u00010\u0018H\u0016J \u0010>\u001a\u00020\u00122\u0006\u0010?\u001a\u00020%2\b\u0010@\u001a\u0004\u0018\u00010\u00182\u0006\u0010A\u001a\u00020\fJ\u000e\u0010B\u001a\u0002032\u0006\u0010C\u001a\u00020DJ\u001c\u0010E\u001a\u0002032\n\u0010F\u001a\u00060Gj\u0002`H2\b\u00109\u001a\u0004\u0018\u00010:J\u0016\u0010I\u001a\u0002032\u0006\u0010\u001e\u001a\u00020\u00182\u0006\u0010*\u001a\u00020+J\u0006\u0010J\u001a\u000203J\u0018\u0010K\u001a\u0002032\u0006\u0010?\u001a\u00020%2\u0006\u0010@\u001a\u00020\u0018H\u0016J\u0010\u0010L\u001a\u0002032\u0006\u0010M\u001a\u00020\u0018H\u0016J\u0010\u0010L\u001a\u0002032\u0006\u0010N\u001a\u00020 H\u0016J\u0010\u0010O\u001a\u0002032\u0006\u0010P\u001a\u00020 H\u0016J\u0010\u0010Q\u001a\u0002032\u0006\u0010P\u001a\u00020 H\u0016J\u000e\u0010R\u001a\u00020\u00122\u0006\u0010P\u001a\u00020 J\u0006\u0010S\u001a\u00020\u0012J\b\u0010!\u001a\u00020\fH\u0016J\u0006\u0010'\u001a\u00020%J\u0006\u0010(\u001a\u00020%J\b\u0010T\u001a\u00020\u0006H\u0016J\b\u0010U\u001a\u000203H\u0002J\u0010\u0010V\u001a\u00020\u00122\u0006\u0010M\u001a\u00020\u0018H\u0016J\u0010\u0010V\u001a\u00020\u00122\u0006\u0010N\u001a\u00020 H\u0016J\u0018\u0010V\u001a\u00020\u00122\u0006\u0010W\u001a\u00020 2\u0006\u0010X\u001a\u00020%H\u0002J\u0006\u0010)\u001a\u00020%J\u0006\u0010Y\u001a\u000203J\r\u0010Z\u001a\u00020\u0012H\u0000¢\u0006\u0002\b[J\r\u0010\\\u001a\u000203H\u0000¢\u0006\u0002\b]J\f\u0010^\u001a\u00020\u0012*\u00020\u000eH\u0002R\u000e\u0010\u0011\u001a\u00020\u0012X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0013\u001a\u0004\u0018\u00010\u0014X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0015\u001a\u00020\u0012X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\r\u001a\u0004\u0018\u00010\u000eX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0016\u001a\u00020\u0012X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0017\u001a\u00020\u0018X\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u0007\u001a\u00020\bX\u0080\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0019\u0010\u001aR\u0014\u0010\u001b\u001a\b\u0012\u0004\u0012\u00020\u001d0\u001cX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u000f\u001a\u00020\fX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u001e\u001a\u0004\u0018\u00010\u0018X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0006X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u000b\u001a\u00020\fX\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u001f\u001a\b\u0012\u0004\u0012\u00020 0\u001cX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010!
|
||
|
/* loaded from: classes3.dex */
|
||
|
public final class RealWebSocket implements WebSocket, WebSocketReader.FrameCallback {
|
||
|
private static final long CANCEL_AFTER_CLOSE_MILLIS = 60000;
|
||
|
public static final long DEFAULT_MINIMUM_DEFLATE_SIZE = 1024;
|
||
|
private static final long MAX_QUEUE_SIZE = 16777216;
|
||
|
private boolean awaitingPong;
|
||
|
private Call call;
|
||
|
private boolean enqueuedClose;
|
||
|
private WebSocketExtensions extensions;
|
||
|
private boolean failed;
|
||
|
private final String key;
|
||
|
private final WebSocketListener listener;
|
||
|
private final ArrayDeque<Object> messageAndCloseQueue;
|
||
|
private long minimumDeflateSize;
|
||
|
private String name;
|
||
|
private final Request originalRequest;
|
||
|
private final long pingIntervalMillis;
|
||
|
private final ArrayDeque<ByteString> pongQueue;
|
||
|
private long queueSize;
|
||
|
private final Random random;
|
||
|
private WebSocketReader reader;
|
||
|
private int receivedCloseCode;
|
||
|
private String receivedCloseReason;
|
||
|
private int receivedPingCount;
|
||
|
private int receivedPongCount;
|
||
|
private int sentPingCount;
|
||
|
private Streams streams;
|
||
|
private TaskQueue taskQueue;
|
||
|
private WebSocketWriter writer;
|
||
|
private Task writerTask;
|
||
|
private static final List<Protocol> ONLY_HTTP1 = CollectionsKt.listOf(Protocol.HTTP_1_1);
|
||
|
|
||
|
/* renamed from: getListener$okhttp, reason: from getter */
|
||
|
public final WebSocketListener getListener() {
|
||
|
return this.listener;
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.WebSocket
|
||
|
/* renamed from: request, reason: from getter */
|
||
|
public Request getOriginalRequest() {
|
||
|
return this.originalRequest;
|
||
|
}
|
||
|
|
||
|
public RealWebSocket(TaskRunner taskRunner, Request originalRequest, WebSocketListener listener, Random random, long j, WebSocketExtensions webSocketExtensions, long j2) {
|
||
|
Intrinsics.checkNotNullParameter(taskRunner, "taskRunner");
|
||
|
Intrinsics.checkNotNullParameter(originalRequest, "originalRequest");
|
||
|
Intrinsics.checkNotNullParameter(listener, "listener");
|
||
|
Intrinsics.checkNotNullParameter(random, "random");
|
||
|
this.originalRequest = originalRequest;
|
||
|
this.listener = listener;
|
||
|
this.random = random;
|
||
|
this.pingIntervalMillis = j;
|
||
|
this.extensions = webSocketExtensions;
|
||
|
this.minimumDeflateSize = j2;
|
||
|
this.taskQueue = taskRunner.newQueue();
|
||
|
this.pongQueue = new ArrayDeque<>();
|
||
|
this.messageAndCloseQueue = new ArrayDeque<>();
|
||
|
this.receivedCloseCode = -1;
|
||
|
if (!Intrinsics.areEqual("GET", originalRequest.method())) {
|
||
|
throw new IllegalArgumentException(("Request must be GET: " + originalRequest.method()).toString());
|
||
|
}
|
||
|
ByteString.Companion companion = ByteString.INSTANCE;
|
||
|
byte[] bArr = new byte[16];
|
||
|
random.nextBytes(bArr);
|
||
|
Unit unit = Unit.INSTANCE;
|
||
|
this.key = ByteString.Companion.of$default(companion, bArr, 0, 0, 3, null).base64();
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.WebSocket
|
||
|
public synchronized long queueSize() {
|
||
|
return this.queueSize;
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.WebSocket
|
||
|
public void cancel() {
|
||
|
Call call = this.call;
|
||
|
Intrinsics.checkNotNull(call);
|
||
|
call.cancel();
|
||
|
}
|
||
|
|
||
|
public final void connect(OkHttpClient client) {
|
||
|
Intrinsics.checkNotNullParameter(client, "client");
|
||
|
if (this.originalRequest.header(HttpHeaders.SEC_WEBSOCKET_EXTENSIONS) != null) {
|
||
|
failWebSocket(new ProtocolException("Request header not permitted: 'Sec-WebSocket-Extensions'"), null);
|
||
|
return;
|
||
|
}
|
||
|
OkHttpClient build = client.newBuilder().eventListener(EventListener.NONE).protocols(ONLY_HTTP1).build();
|
||
|
final Request build2 = this.originalRequest.newBuilder().header(HttpHeaders.UPGRADE, "websocket").header(HttpHeaders.CONNECTION, HttpHeaders.UPGRADE).header(HttpHeaders.SEC_WEBSOCKET_KEY, this.key).header(HttpHeaders.SEC_WEBSOCKET_VERSION, "13").header(HttpHeaders.SEC_WEBSOCKET_EXTENSIONS, "permessage-deflate").build();
|
||
|
RealCall realCall = new RealCall(build, build2, true);
|
||
|
this.call = realCall;
|
||
|
Intrinsics.checkNotNull(realCall);
|
||
|
realCall.enqueue(new Callback() { // from class: okhttp3.internal.ws.RealWebSocket$connect$1
|
||
|
@Override // okhttp3.Callback
|
||
|
public void onResponse(Call call, okhttp3.Response response) {
|
||
|
boolean isValid;
|
||
|
ArrayDeque arrayDeque;
|
||
|
Intrinsics.checkNotNullParameter(call, "call");
|
||
|
Intrinsics.checkNotNullParameter(response, "response");
|
||
|
Exchange exchange = response.getExchange();
|
||
|
try {
|
||
|
RealWebSocket.this.checkUpgradeSuccess$okhttp(response, exchange);
|
||
|
Intrinsics.checkNotNull(exchange);
|
||
|
RealWebSocket.Streams newWebSocketStreams = exchange.newWebSocketStreams();
|
||
|
WebSocketExtensions parse = WebSocketExtensions.INSTANCE.parse(response.headers());
|
||
|
RealWebSocket.this.extensions = parse;
|
||
|
isValid = RealWebSocket.this.isValid(parse);
|
||
|
if (!isValid) {
|
||
|
synchronized (RealWebSocket.this) {
|
||
|
arrayDeque = RealWebSocket.this.messageAndCloseQueue;
|
||
|
arrayDeque.clear();
|
||
|
RealWebSocket.this.close(1010, "unexpected Sec-WebSocket-Extensions in response header");
|
||
|
}
|
||
|
}
|
||
|
try {
|
||
|
RealWebSocket.this.initReaderAndWriter(Util.okHttpName + " WebSocket " + build2.url().redact(), newWebSocketStreams);
|
||
|
RealWebSocket.this.getListener().onOpen(RealWebSocket.this, response);
|
||
|
RealWebSocket.this.loopReader();
|
||
|
} catch (Exception e) {
|
||
|
RealWebSocket.this.failWebSocket(e, null);
|
||
|
}
|
||
|
} catch (IOException e2) {
|
||
|
if (exchange != null) {
|
||
|
exchange.webSocketUpgradeFailed();
|
||
|
}
|
||
|
RealWebSocket.this.failWebSocket(e2, response);
|
||
|
Util.closeQuietly(response);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.Callback
|
||
|
public void onFailure(Call call, IOException e) {
|
||
|
Intrinsics.checkNotNullParameter(call, "call");
|
||
|
Intrinsics.checkNotNullParameter(e, "e");
|
||
|
RealWebSocket.this.failWebSocket(e, null);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
public final boolean isValid(WebSocketExtensions webSocketExtensions) {
|
||
|
if (webSocketExtensions.unknownValues || webSocketExtensions.clientMaxWindowBits != null) {
|
||
|
return false;
|
||
|
}
|
||
|
if (webSocketExtensions.serverMaxWindowBits == null) {
|
||
|
return true;
|
||
|
}
|
||
|
int intValue = webSocketExtensions.serverMaxWindowBits.intValue();
|
||
|
return 8 <= intValue && 15 >= intValue;
|
||
|
}
|
||
|
|
||
|
public final void checkUpgradeSuccess$okhttp(okhttp3.Response response, Exchange exchange) throws IOException {
|
||
|
Intrinsics.checkNotNullParameter(response, "response");
|
||
|
if (response.code() != 101) {
|
||
|
throw new ProtocolException("Expected HTTP 101 response but was '" + response.code() + ' ' + response.message() + '\'');
|
||
|
}
|
||
|
String header$default = okhttp3.Response.header$default(response, HttpHeaders.CONNECTION, null, 2, null);
|
||
|
if (!StringsKt.equals(HttpHeaders.UPGRADE, header$default, true)) {
|
||
|
throw new ProtocolException("Expected 'Connection' header value 'Upgrade' but was '" + header$default + '\'');
|
||
|
}
|
||
|
String header$default2 = okhttp3.Response.header$default(response, HttpHeaders.UPGRADE, null, 2, null);
|
||
|
if (!StringsKt.equals("websocket", header$default2, true)) {
|
||
|
throw new ProtocolException("Expected 'Upgrade' header value 'websocket' but was '" + header$default2 + '\'');
|
||
|
}
|
||
|
String header$default3 = okhttp3.Response.header$default(response, HttpHeaders.SEC_WEBSOCKET_ACCEPT, null, 2, null);
|
||
|
String base64 = ByteString.INSTANCE.encodeUtf8(this.key + WebSocketProtocol.ACCEPT_MAGIC).sha1().base64();
|
||
|
if (!Intrinsics.areEqual(base64, header$default3)) {
|
||
|
throw new ProtocolException("Expected 'Sec-WebSocket-Accept' header value '" + base64 + "' but was '" + header$default3 + '\'');
|
||
|
}
|
||
|
if (exchange == null) {
|
||
|
throw new ProtocolException("Web Socket exchange missing: bad interceptor?");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final void initReaderAndWriter(final String name, final Streams streams) throws IOException {
|
||
|
Intrinsics.checkNotNullParameter(name, "name");
|
||
|
Intrinsics.checkNotNullParameter(streams, "streams");
|
||
|
final WebSocketExtensions webSocketExtensions = this.extensions;
|
||
|
Intrinsics.checkNotNull(webSocketExtensions);
|
||
|
synchronized (this) {
|
||
|
this.name = name;
|
||
|
this.streams = streams;
|
||
|
this.writer = new WebSocketWriter(streams.getClient(), streams.getSink(), this.random, webSocketExtensions.perMessageDeflate, webSocketExtensions.noContextTakeover(streams.getClient()), this.minimumDeflateSize);
|
||
|
this.writerTask = new WriterTask();
|
||
|
if (this.pingIntervalMillis != 0) {
|
||
|
final long nanos = TimeUnit.MILLISECONDS.toNanos(this.pingIntervalMillis);
|
||
|
final String str = name + " ping";
|
||
|
this.taskQueue.schedule(new Task(str) { // from class: okhttp3.internal.ws.RealWebSocket$initReaderAndWriter$$inlined$synchronized$lambda$1
|
||
|
@Override // okhttp3.internal.concurrent.Task
|
||
|
public long runOnce() {
|
||
|
this.writePingFrame$okhttp();
|
||
|
return nanos;
|
||
|
}
|
||
|
}, nanos);
|
||
|
}
|
||
|
if (!this.messageAndCloseQueue.isEmpty()) {
|
||
|
runWriter();
|
||
|
}
|
||
|
Unit unit = Unit.INSTANCE;
|
||
|
}
|
||
|
this.reader = new WebSocketReader(streams.getClient(), streams.getSource(), this, webSocketExtensions.perMessageDeflate, webSocketExtensions.noContextTakeover(!streams.getClient()));
|
||
|
}
|
||
|
|
||
|
public final void loopReader() throws IOException {
|
||
|
while (this.receivedCloseCode == -1) {
|
||
|
WebSocketReader webSocketReader = this.reader;
|
||
|
Intrinsics.checkNotNull(webSocketReader);
|
||
|
webSocketReader.processNextFrame();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final boolean processNextFrame() throws IOException {
|
||
|
try {
|
||
|
WebSocketReader webSocketReader = this.reader;
|
||
|
Intrinsics.checkNotNull(webSocketReader);
|
||
|
webSocketReader.processNextFrame();
|
||
|
return this.receivedCloseCode == -1;
|
||
|
} catch (Exception e) {
|
||
|
this.failWebSocket(e, null);
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final void awaitTermination(long timeout, TimeUnit timeUnit) throws InterruptedException {
|
||
|
Intrinsics.checkNotNullParameter(timeUnit, "timeUnit");
|
||
|
this.taskQueue.idleLatch().await(timeout, timeUnit);
|
||
|
}
|
||
|
|
||
|
public final void tearDown() throws InterruptedException {
|
||
|
this.taskQueue.shutdown();
|
||
|
this.taskQueue.idleLatch().await(10L, TimeUnit.SECONDS);
|
||
|
}
|
||
|
|
||
|
public final synchronized int sentPingCount() {
|
||
|
return this.sentPingCount;
|
||
|
}
|
||
|
|
||
|
public final synchronized int receivedPingCount() {
|
||
|
return this.receivedPingCount;
|
||
|
}
|
||
|
|
||
|
public final synchronized int receivedPongCount() {
|
||
|
return this.receivedPongCount;
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.internal.ws.WebSocketReader.FrameCallback
|
||
|
public void onReadMessage(String text) throws IOException {
|
||
|
Intrinsics.checkNotNullParameter(text, "text");
|
||
|
this.listener.onMessage(this, text);
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.internal.ws.WebSocketReader.FrameCallback
|
||
|
public void onReadMessage(ByteString bytes) throws IOException {
|
||
|
Intrinsics.checkNotNullParameter(bytes, "bytes");
|
||
|
this.listener.onMessage(this, bytes);
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.internal.ws.WebSocketReader.FrameCallback
|
||
|
public synchronized void onReadPing(ByteString payload) {
|
||
|
Intrinsics.checkNotNullParameter(payload, "payload");
|
||
|
if (!this.failed && (!this.enqueuedClose || !this.messageAndCloseQueue.isEmpty())) {
|
||
|
this.pongQueue.add(payload);
|
||
|
runWriter();
|
||
|
this.receivedPingCount++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.internal.ws.WebSocketReader.FrameCallback
|
||
|
public synchronized void onReadPong(ByteString payload) {
|
||
|
Intrinsics.checkNotNullParameter(payload, "payload");
|
||
|
this.receivedPongCount++;
|
||
|
this.awaitingPong = false;
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.internal.ws.WebSocketReader.FrameCallback
|
||
|
public void onReadClose(int code, String reason) {
|
||
|
WebSocketReader webSocketReader;
|
||
|
WebSocketWriter webSocketWriter;
|
||
|
Intrinsics.checkNotNullParameter(reason, "reason");
|
||
|
boolean z = true;
|
||
|
if (!(code != -1)) {
|
||
|
throw new IllegalArgumentException("Failed requirement.".toString());
|
||
|
}
|
||
|
Streams streams = null;
|
||
|
synchronized (this) {
|
||
|
if (this.receivedCloseCode != -1) {
|
||
|
z = false;
|
||
|
}
|
||
|
if (!z) {
|
||
|
throw new IllegalStateException("already closed".toString());
|
||
|
}
|
||
|
this.receivedCloseCode = code;
|
||
|
this.receivedCloseReason = reason;
|
||
|
if (this.enqueuedClose && this.messageAndCloseQueue.isEmpty()) {
|
||
|
Streams streams2 = this.streams;
|
||
|
this.streams = null;
|
||
|
webSocketReader = this.reader;
|
||
|
this.reader = null;
|
||
|
webSocketWriter = this.writer;
|
||
|
this.writer = null;
|
||
|
this.taskQueue.shutdown();
|
||
|
streams = streams2;
|
||
|
} else {
|
||
|
webSocketReader = null;
|
||
|
webSocketWriter = null;
|
||
|
}
|
||
|
Unit unit = Unit.INSTANCE;
|
||
|
}
|
||
|
try {
|
||
|
this.listener.onClosing(this, code, reason);
|
||
|
if (streams != null) {
|
||
|
this.listener.onClosed(this, code, reason);
|
||
|
}
|
||
|
} finally {
|
||
|
if (streams != null) {
|
||
|
Util.closeQuietly(streams);
|
||
|
}
|
||
|
if (webSocketReader != null) {
|
||
|
Util.closeQuietly(webSocketReader);
|
||
|
}
|
||
|
if (webSocketWriter != null) {
|
||
|
Util.closeQuietly(webSocketWriter);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.WebSocket
|
||
|
public boolean send(String text) {
|
||
|
Intrinsics.checkNotNullParameter(text, "text");
|
||
|
return send(ByteString.INSTANCE.encodeUtf8(text), 1);
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.WebSocket
|
||
|
public boolean send(ByteString bytes) {
|
||
|
Intrinsics.checkNotNullParameter(bytes, "bytes");
|
||
|
return send(bytes, 2);
|
||
|
}
|
||
|
|
||
|
private final synchronized boolean send(ByteString data, int formatOpcode) {
|
||
|
if (!this.failed && !this.enqueuedClose) {
|
||
|
if (this.queueSize + data.size() > MAX_QUEUE_SIZE) {
|
||
|
close(1001, null);
|
||
|
return false;
|
||
|
}
|
||
|
this.queueSize += data.size();
|
||
|
this.messageAndCloseQueue.add(new Message(formatOpcode, data));
|
||
|
runWriter();
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public final synchronized boolean pong(ByteString payload) {
|
||
|
Intrinsics.checkNotNullParameter(payload, "payload");
|
||
|
if (!this.failed && (!this.enqueuedClose || !this.messageAndCloseQueue.isEmpty())) {
|
||
|
this.pongQueue.add(payload);
|
||
|
runWriter();
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.WebSocket
|
||
|
public boolean close(int code, String reason) {
|
||
|
return close(code, reason, 60000L);
|
||
|
}
|
||
|
|
||
|
public final synchronized boolean close(int code, String reason, long cancelAfterCloseMillis) {
|
||
|
WebSocketProtocol.INSTANCE.validateCloseCode(code);
|
||
|
ByteString byteString = null;
|
||
|
if (reason != null) {
|
||
|
byteString = ByteString.INSTANCE.encodeUtf8(reason);
|
||
|
if (!(((long) byteString.size()) <= 123)) {
|
||
|
throw new IllegalArgumentException(("reason.size() > 123: " + reason).toString());
|
||
|
}
|
||
|
}
|
||
|
if (!this.failed && !this.enqueuedClose) {
|
||
|
this.enqueuedClose = true;
|
||
|
this.messageAndCloseQueue.add(new Close(code, byteString, cancelAfterCloseMillis));
|
||
|
runWriter();
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
/* JADX WARN: Removed duplicated region for block: B:25:0x0119 A[Catch: all -> 0x01e0, TRY_ENTER, TryCatch #0 {all -> 0x01e0, blocks: (B:25:0x0119, B:38:0x0124, B:40:0x012c, B:42:0x0130, B:43:0x0140, B:46:0x0151, B:50:0x0154, B:51:0x0155, B:52:0x0156, B:53:0x015d, B:54:0x015e, B:57:0x0164, B:59:0x0168, B:45:0x0141), top: B:23:0x0117, inners: #1 }] */
|
||
|
/* JADX WARN: Removed duplicated region for block: B:29:0x019b */
|
||
|
/* JADX WARN: Removed duplicated region for block: B:32:0x01a8 */
|
||
|
/* JADX WARN: Removed duplicated region for block: B:35:0x01b5 */
|
||
|
/* JADX WARN: Removed duplicated region for block: B:37:? A[RETURN, SYNTHETIC] */
|
||
|
/* JADX WARN: Removed duplicated region for block: B:38:0x0124 A[Catch: all -> 0x01e0, TryCatch #0 {all -> 0x01e0, blocks: (B:25:0x0119, B:38:0x0124, B:40:0x012c, B:42:0x0130, B:43:0x0140, B:46:0x0151, B:50:0x0154, B:51:0x0155, B:52:0x0156, B:53:0x015d, B:54:0x015e, B:57:0x0164, B:59:0x0168, B:45:0x0141), top: B:23:0x0117, inners: #1 }] */
|
||
|
/* JADX WARN: Type inference failed for: r1v13, types: [okhttp3.internal.ws.WebSocketWriter, java.lang.Object] */
|
||
|
/* JADX WARN: Type inference failed for: r1v16, types: [kotlin.jvm.internal.Ref$ObjectRef] */
|
||
|
/* JADX WARN: Type inference failed for: r1v2 */
|
||
|
/* JADX WARN: Type inference failed for: r2v1 */
|
||
|
/* JADX WARN: Type inference failed for: r2v10 */
|
||
|
/* JADX WARN: Type inference failed for: r2v17, types: [T, okhttp3.internal.ws.RealWebSocket$Streams] */
|
||
|
/* JADX WARN: Type inference failed for: r2v20, types: [T, okhttp3.internal.ws.WebSocketReader] */
|
||
|
/* JADX WARN: Type inference failed for: r2v23, types: [T, okhttp3.internal.ws.WebSocketWriter] */
|
||
|
/* JADX WARN: Type inference failed for: r2v6, types: [boolean] */
|
||
|
/* JADX WARN: Type inference failed for: r3v11, types: [okio.ByteString] */
|
||
|
/* JADX WARN: Type inference failed for: r3v12 */
|
||
|
/* JADX WARN: Type inference failed for: r3v16 */
|
||
|
/* JADX WARN: Type inference failed for: r3v23, types: [T, java.lang.Object] */
|
||
|
/* JADX WARN: Type inference failed for: r3v27, types: [T, java.lang.String] */
|
||
|
/*
|
||
|
Code decompiled incorrectly, please refer to instructions dump.
|
||
|
To view partially-correct add '--show-bad-code' argument
|
||
|
*/
|
||
|
public final boolean writeOneFrame$okhttp() throws java.io.IOException {
|
||
|
/*
|
||
|
Method dump skipped, instructions count: 524
|
||
|
To view this dump add '--comments-level debug' option
|
||
|
*/
|
||
|
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.ws.RealWebSocket.writeOneFrame$okhttp():boolean");
|
||
|
}
|
||
|
|
||
|
public final void writePingFrame$okhttp() {
|
||
|
synchronized (this) {
|
||
|
if (this.failed) {
|
||
|
return;
|
||
|
}
|
||
|
WebSocketWriter webSocketWriter = this.writer;
|
||
|
if (webSocketWriter != null) {
|
||
|
int i = this.awaitingPong ? this.sentPingCount : -1;
|
||
|
this.sentPingCount++;
|
||
|
this.awaitingPong = true;
|
||
|
Unit unit = Unit.INSTANCE;
|
||
|
if (i != -1) {
|
||
|
failWebSocket(new SocketTimeoutException("sent ping but didn't receive pong within " + this.pingIntervalMillis + "ms (after " + (i - 1) + " successful ping/pongs)"), null);
|
||
|
return;
|
||
|
}
|
||
|
try {
|
||
|
webSocketWriter.writePing(ByteString.EMPTY);
|
||
|
} catch (IOException e) {
|
||
|
failWebSocket(e, null);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final void failWebSocket(Exception e, okhttp3.Response response) {
|
||
|
Intrinsics.checkNotNullParameter(e, "e");
|
||
|
synchronized (this) {
|
||
|
if (this.failed) {
|
||
|
return;
|
||
|
}
|
||
|
this.failed = true;
|
||
|
Streams streams = this.streams;
|
||
|
this.streams = null;
|
||
|
WebSocketReader webSocketReader = this.reader;
|
||
|
this.reader = null;
|
||
|
WebSocketWriter webSocketWriter = this.writer;
|
||
|
this.writer = null;
|
||
|
this.taskQueue.shutdown();
|
||
|
Unit unit = Unit.INSTANCE;
|
||
|
try {
|
||
|
this.listener.onFailure(this, e, response);
|
||
|
} finally {
|
||
|
if (streams != null) {
|
||
|
Util.closeQuietly(streams);
|
||
|
}
|
||
|
if (webSocketReader != null) {
|
||
|
Util.closeQuietly(webSocketReader);
|
||
|
}
|
||
|
if (webSocketWriter != null) {
|
||
|
Util.closeQuietly(webSocketWriter);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* compiled from: RealWebSocket.kt */
|
||
|
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\b\u0000\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006R\u0011\u0010\u0004\u001a\u00020\u0005¢\u0006\b\n\u0000\u001a\u0004\b\u0007\u0010\bR\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\t\u0010\n¨\u0006\u000b"}, d2 = {"Lokhttp3/internal/ws/RealWebSocket$Message;", "", "formatOpcode", "", "data", "Lokio/ByteString;", "(ILokio/ByteString;)V", "getData", "()Lokio/ByteString;", "getFormatOpcode", "()I", "okhttp"}, k = 1, mv = {1, 4, 0})
|
||
|
/* loaded from: classes3.dex */
|
||
|
public static final class Message {
|
||
|
private final ByteString data;
|
||
|
private final int formatOpcode;
|
||
|
|
||
|
public final ByteString getData() {
|
||
|
return this.data;
|
||
|
}
|
||
|
|
||
|
public final int getFormatOpcode() {
|
||
|
return this.formatOpcode;
|
||
|
}
|
||
|
|
||
|
public Message(int i, ByteString data) {
|
||
|
Intrinsics.checkNotNullParameter(data, "data");
|
||
|
this.formatOpcode = i;
|
||
|
this.data = data;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* compiled from: RealWebSocket.kt */
|
||
|
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\b\b\u0000\u0018\u00002\u00020\u0001B\u001f\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\b\u0010\u0004\u001a\u0004\u0018\u00010\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bR\u0011\u0010\u0006\u001a\u00020\u0007¢\u0006\b\n\u0000\u001a\u0004\b\t\u0010\nR\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\fR\u0013\u0010\u0004\u001a\u0004\u0018\u00010\u0005¢\u0006\b\n\u0000\u001a\u0004\b\r\u0010\u000e¨\u0006\u000f"}, d2 = {"Lokhttp3/internal/ws/RealWebSocket$Close;", "", "code", "", DiscardedEvent.JsonKeys.REASON, "Lokio/ByteString;", "cancelAfterCloseMillis", "", "(ILokio/ByteString;J)V", "getCancelAfterCloseMillis", "()J", "getCode", "()I", "getReason", "()Lokio/ByteString;", "okhttp"}, k = 1, mv = {1, 4, 0})
|
||
|
/* loaded from: classes3.dex */
|
||
|
public static final class Close {
|
||
|
private final long cancelAfterCloseMillis;
|
||
|
private final int code;
|
||
|
private final ByteString reason;
|
||
|
|
||
|
public final long getCancelAfterCloseMillis() {
|
||
|
return this.cancelAfterCloseMillis;
|
||
|
}
|
||
|
|
||
|
public final int getCode() {
|
||
|
return this.code;
|
||
|
}
|
||
|
|
||
|
public final ByteString getReason() {
|
||
|
return this.reason;
|
||
|
}
|
||
|
|
||
|
public Close(int i, ByteString byteString, long j) {
|
||
|
this.code = i;
|
||
|
this.reason = byteString;
|
||
|
this.cancelAfterCloseMillis = j;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* compiled from: RealWebSocket.kt */
|
||
|
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\b\b&\u0018\u00002\u00020\u0001B\u001d\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bR\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\t\u0010\nR\u0011\u0010\u0006\u001a\u00020\u0007¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\fR\u0011\u0010\u0004\u001a\u00020\u0005¢\u0006\b\n\u0000\u001a\u0004\b\r\u0010\u000e¨\u0006\u000f"}, d2 = {"Lokhttp3/internal/ws/RealWebSocket$Streams;", "Ljava/io/Closeable;", "client", "", TransactionInfo.JsonKeys.SOURCE, "Lokio/BufferedSource;", "sink", "Lokio/BufferedSink;", "(ZLokio/BufferedSource;Lokio/BufferedSink;)V", "getClient", "()Z", "getSink", "()Lokio/BufferedSink;", "getSource", "()Lokio/BufferedSource;", "okhttp"}, k = 1, mv = {1, 4, 0})
|
||
|
/* loaded from: classes3.dex */
|
||
|
public static abstract class Streams implements Closeable {
|
||
|
private final boolean client;
|
||
|
private final BufferedSink sink;
|
||
|
private final BufferedSource source;
|
||
|
|
||
|
public final boolean getClient() {
|
||
|
return this.client;
|
||
|
}
|
||
|
|
||
|
public final BufferedSink getSink() {
|
||
|
return this.sink;
|
||
|
}
|
||
|
|
||
|
public final BufferedSource getSource() {
|
||
|
return this.source;
|
||
|
}
|
||
|
|
||
|
public Streams(boolean z, BufferedSource source, BufferedSink sink) {
|
||
|
Intrinsics.checkNotNullParameter(source, "source");
|
||
|
Intrinsics.checkNotNullParameter(sink, "sink");
|
||
|
this.client = z;
|
||
|
this.source = source;
|
||
|
this.sink = sink;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* compiled from: RealWebSocket.kt */
|
||
|
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\t\n\u0000\b\u0082\u0004\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\b\u0010\u0003\u001a\u00020\u0004H\u0016¨\u0006\u0005"}, d2 = {"Lokhttp3/internal/ws/RealWebSocket$WriterTask;", "Lokhttp3/internal/concurrent/Task;", "(Lokhttp3/internal/ws/RealWebSocket;)V", "runOnce", "", "okhttp"}, k = 1, mv = {1, 4, 0})
|
||
|
/* loaded from: classes3.dex */
|
||
|
private final class WriterTask extends Task {
|
||
|
public WriterTask() {
|
||
|
super(RealWebSocket.this.name + " writer", false, 2, null);
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.internal.concurrent.Task
|
||
|
public long runOnce() {
|
||
|
try {
|
||
|
return RealWebSocket.this.writeOneFrame$okhttp() ? 0L : -1L;
|
||
|
} catch (IOException e) {
|
||
|
RealWebSocket.this.failWebSocket(e, null);
|
||
|
return -1L;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private final void runWriter() {
|
||
|
if (Util.assertionsEnabled && !Thread.holdsLock(this)) {
|
||
|
StringBuilder sb = new StringBuilder("Thread ");
|
||
|
Thread currentThread = Thread.currentThread();
|
||
|
Intrinsics.checkNotNullExpressionValue(currentThread, "Thread.currentThread()");
|
||
|
throw new AssertionError(sb.append(currentThread.getName()).append(" MUST hold lock on ").append(this).toString());
|
||
|
}
|
||
|
Task task = this.writerTask;
|
||
|
if (task != null) {
|
||
|
TaskQueue.schedule$default(this.taskQueue, task, 0L, 2, null);
|
||
|
}
|
||
|
}
|
||
|
}
|