FramedConnection.java
40.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
package com.squareup.okhttp.internal.framed;
import com.squareup.okhttp.Protocol;
import com.squareup.okhttp.internal.Internal;
import com.squareup.okhttp.internal.NamedRunnable;
import com.squareup.okhttp.internal.Util;
import java.io.Closeable;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;
import okio.Okio;
public final class FramedConnection
implements Closeable
{
private static final int OKHTTP_CLIENT_WINDOW_SIZE = 16777216;
private static final ExecutorService executor;
long bytesLeftInWriteWindow;
final boolean client;
private final Set<Integer> currentPushRequests = new LinkedHashSet();
final FrameWriter frameWriter;
private final IncomingStreamHandler handler;
private final String hostName;
private long idleStartTimeNs = System.nanoTime();
private int lastGoodStreamId;
private int nextPingId;
private int nextStreamId;
final Settings okHttpSettings = new Settings();
final Settings peerSettings = new Settings();
private Map<Integer, Ping> pings;
final Protocol protocol;
private final ExecutorService pushExecutor;
private final PushObserver pushObserver;
final Reader readerRunnable;
private boolean receivedInitialPeerSettings = false;
private boolean shutdown;
final Socket socket;
private final Map<Integer, FramedStream> streams = new HashMap();
long unacknowledgedBytesRead = 0L;
final Variant variant;
static
{
if (!FramedConnection.class.desiredAssertionStatus()) {}
for (boolean bool = true;; bool = false)
{
$assertionsDisabled = bool;
executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue(), Util.threadFactory("OkHttp FramedConnection", true));
return;
}
}
private FramedConnection(Builder paramBuilder)
throws IOException
{
this.protocol = paramBuilder.protocol;
this.pushObserver = paramBuilder.pushObserver;
this.client = paramBuilder.client;
this.handler = paramBuilder.handler;
int i;
if (paramBuilder.client)
{
i = 1;
this.nextStreamId = i;
if ((paramBuilder.client) && (this.protocol == Protocol.HTTP_2)) {
this.nextStreamId += 2;
}
i = j;
if (paramBuilder.client) {
i = 1;
}
this.nextPingId = i;
if (paramBuilder.client) {
this.okHttpSettings.set(7, 0, 16777216);
}
this.hostName = paramBuilder.hostName;
if (this.protocol != Protocol.HTTP_2) {
break label359;
}
this.variant = new Http2();
this.pushExecutor = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue(), Util.threadFactory(String.format("OkHttp %s Push Observer", new Object[] { this.hostName }), true));
this.peerSettings.set(7, 0, 65535);
this.peerSettings.set(5, 0, 16384);
}
for (;;)
{
this.bytesLeftInWriteWindow = this.peerSettings.getInitialWindowSize(65536);
this.socket = paramBuilder.socket;
this.frameWriter = this.variant.newWriter(Okio.buffer(Okio.sink(paramBuilder.socket)), this.client);
this.readerRunnable = new Reader(null);
new Thread(this.readerRunnable).start();
return;
i = 2;
break;
label359:
if (this.protocol != Protocol.SPDY_3) {
break label388;
}
this.variant = new Spdy3();
this.pushExecutor = null;
}
label388:
throw new AssertionError(this.protocol);
}
/* Error */
private void close(ErrorCode paramErrorCode1, ErrorCode paramErrorCode2)
throws IOException
{
// Byte code:
// 0: getstatic 85 com/squareup/okhttp/internal/framed/FramedConnection:$assertionsDisabled Z
// 3: ifne +18 -> 21
// 6: aload_0
// 7: invokestatic 352 java/lang/Thread:holdsLock (Ljava/lang/Object;)Z
// 10: ifeq +11 -> 21
// 13: new 262 java/lang/AssertionError
// 16: dup
// 17: invokespecial 353 java/lang/AssertionError:<init> ()V
// 20: athrow
// 21: aload_0
// 22: aload_1
// 23: invokevirtual 356 com/squareup/okhttp/internal/framed/FramedConnection:shutdown (Lcom/squareup/okhttp/internal/framed/ErrorCode;)V
// 26: aconst_null
// 27: astore_1
// 28: aload_0
// 29: monitorenter
// 30: aload_0
// 31: getfield 124 com/squareup/okhttp/internal/framed/FramedConnection:streams Ljava/util/Map;
// 34: invokeinterface 361 1 0
// 39: ifne +247 -> 286
// 42: aload_0
// 43: getfield 124 com/squareup/okhttp/internal/framed/FramedConnection:streams Ljava/util/Map;
// 46: invokeinterface 365 1 0
// 51: aload_0
// 52: getfield 124 com/squareup/okhttp/internal/framed/FramedConnection:streams Ljava/util/Map;
// 55: invokeinterface 369 1 0
// 60: anewarray 371 com/squareup/okhttp/internal/framed/FramedStream
// 63: invokeinterface 377 2 0
// 68: checkcast 379 [Lcom/squareup/okhttp/internal/framed/FramedStream;
// 71: astore 6
// 73: aload_0
// 74: getfield 124 com/squareup/okhttp/internal/framed/FramedConnection:streams Ljava/util/Map;
// 77: invokeinterface 382 1 0
// 82: aload_0
// 83: iconst_0
// 84: invokespecial 386 com/squareup/okhttp/internal/framed/FramedConnection:setIdle (Z)V
// 87: aload_0
// 88: getfield 388 com/squareup/okhttp/internal/framed/FramedConnection:pings Ljava/util/Map;
// 91: ifnull +189 -> 280
// 94: aload_0
// 95: getfield 388 com/squareup/okhttp/internal/framed/FramedConnection:pings Ljava/util/Map;
// 98: invokeinterface 365 1 0
// 103: aload_0
// 104: getfield 388 com/squareup/okhttp/internal/framed/FramedConnection:pings Ljava/util/Map;
// 107: invokeinterface 369 1 0
// 112: anewarray 390 com/squareup/okhttp/internal/framed/Ping
// 115: invokeinterface 377 2 0
// 120: checkcast 392 [Lcom/squareup/okhttp/internal/framed/Ping;
// 123: astore 7
// 125: aload_0
// 126: aconst_null
// 127: putfield 388 com/squareup/okhttp/internal/framed/FramedConnection:pings Ljava/util/Map;
// 130: aload_0
// 131: monitorexit
// 132: aload_1
// 133: astore 5
// 135: aload 6
// 137: ifnull +69 -> 206
// 140: aload 6
// 142: arraylength
// 143: istore 4
// 145: iconst_0
// 146: istore_3
// 147: iload_3
// 148: iload 4
// 150: if_icmpge +53 -> 203
// 153: aload 6
// 155: iload_3
// 156: aaload
// 157: astore 5
// 159: aload 5
// 161: aload_2
// 162: invokevirtual 394 com/squareup/okhttp/internal/framed/FramedStream:close (Lcom/squareup/okhttp/internal/framed/ErrorCode;)V
// 165: aload_1
// 166: astore 5
// 168: iload_3
// 169: iconst_1
// 170: iadd
// 171: istore_3
// 172: aload 5
// 174: astore_1
// 175: goto -28 -> 147
// 178: astore_1
// 179: goto -151 -> 28
// 182: astore_1
// 183: aload_0
// 184: monitorexit
// 185: aload_1
// 186: athrow
// 187: astore 8
// 189: aload_1
// 190: astore 5
// 192: aload_1
// 193: ifnull -25 -> 168
// 196: aload 8
// 198: astore 5
// 200: goto -32 -> 168
// 203: aload_1
// 204: astore 5
// 206: aload 7
// 208: ifnull +30 -> 238
// 211: aload 7
// 213: arraylength
// 214: istore 4
// 216: iconst_0
// 217: istore_3
// 218: iload_3
// 219: iload 4
// 221: if_icmpge +17 -> 238
// 224: aload 7
// 226: iload_3
// 227: aaload
// 228: invokevirtual 397 com/squareup/okhttp/internal/framed/Ping:cancel ()V
// 231: iload_3
// 232: iconst_1
// 233: iadd
// 234: istore_3
// 235: goto -17 -> 218
// 238: aload_0
// 239: getfield 241 com/squareup/okhttp/internal/framed/FramedConnection:frameWriter Lcom/squareup/okhttp/internal/framed/FrameWriter;
// 242: invokeinterface 401 1 0
// 247: aload 5
// 249: astore_1
// 250: aload_0
// 251: getfield 223 com/squareup/okhttp/internal/framed/FramedConnection:socket Ljava/net/Socket;
// 254: invokevirtual 404 java/net/Socket:close ()V
// 257: aload_1
// 258: ifnull +17 -> 275
// 261: aload_1
// 262: athrow
// 263: astore_1
// 264: aload 5
// 266: ifnull -16 -> 250
// 269: aload 5
// 271: astore_1
// 272: goto -22 -> 250
// 275: return
// 276: astore_1
// 277: goto -20 -> 257
// 280: aconst_null
// 281: astore 7
// 283: goto -153 -> 130
// 286: aconst_null
// 287: astore 6
// 289: goto -202 -> 87
// Local variable table:
// start length slot name signature
// 0 292 0 this FramedConnection
// 0 292 1 paramErrorCode1 ErrorCode
// 0 292 2 paramErrorCode2 ErrorCode
// 146 89 3 i int
// 143 79 4 j int
// 133 137 5 localObject Object
// 71 217 6 arrayOfFramedStream FramedStream[]
// 123 159 7 arrayOfPing Ping[]
// 187 10 8 localIOException IOException
// Exception table:
// from to target type
// 21 26 178 java/io/IOException
// 30 87 182 finally
// 87 130 182 finally
// 130 132 182 finally
// 183 185 182 finally
// 159 165 187 java/io/IOException
// 238 247 263 java/io/IOException
// 250 257 276 java/io/IOException
}
private FramedStream newStream(int paramInt, List<Header> paramList, boolean paramBoolean1, boolean paramBoolean2)
throws IOException
{
boolean bool2 = true;
boolean bool1;
if (!paramBoolean1)
{
bool1 = true;
if (paramBoolean2) {
break label65;
}
}
label65:
for (paramBoolean2 = bool2;; paramBoolean2 = false)
{
synchronized (this.frameWriter)
{
try
{
if (!this.shutdown) {
break label71;
}
throw new IOException("shutdown");
}
finally {}
}
bool1 = false;
break;
}
label71:
int i = this.nextStreamId;
this.nextStreamId += 2;
FramedStream localFramedStream = new FramedStream(i, this, bool1, paramBoolean2, paramList);
if (localFramedStream.isOpen())
{
this.streams.put(Integer.valueOf(i), localFramedStream);
setIdle(false);
}
if (paramInt == 0) {
this.frameWriter.synStream(bool1, paramBoolean2, i, paramInt, paramList);
}
for (;;)
{
if (!paramBoolean1) {
this.frameWriter.flush();
}
return localFramedStream;
if (this.client) {
throw new IllegalArgumentException("client streams shouldn't have associated stream IDs");
}
this.frameWriter.pushPromise(paramInt, i, paramList);
}
}
private void pushDataLater(final int paramInt1, BufferedSource paramBufferedSource, final int paramInt2, final boolean paramBoolean)
throws IOException
{
final Buffer localBuffer = new Buffer();
paramBufferedSource.require(paramInt2);
paramBufferedSource.read(localBuffer, paramInt2);
if (localBuffer.size() != paramInt2) {
throw new IOException(localBuffer.size() + " != " + paramInt2);
}
this.pushExecutor.execute(new NamedRunnable("OkHttp %s Push Data[%s]", new Object[] { this.hostName, Integer.valueOf(paramInt1) })
{
public void execute()
{
try
{
boolean bool = FramedConnection.this.pushObserver.onData(paramInt1, localBuffer, paramInt2, paramBoolean);
if (bool) {
FramedConnection.this.frameWriter.rstStream(paramInt1, ErrorCode.CANCEL);
}
if ((bool) || (paramBoolean)) {
synchronized (FramedConnection.this)
{
FramedConnection.this.currentPushRequests.remove(Integer.valueOf(paramInt1));
return;
}
}
return;
}
catch (IOException localIOException) {}
}
});
}
private void pushHeadersLater(final int paramInt, final List<Header> paramList, final boolean paramBoolean)
{
this.pushExecutor.execute(new NamedRunnable("OkHttp %s Push Headers[%s]", new Object[] { this.hostName, Integer.valueOf(paramInt) })
{
public void execute()
{
boolean bool = FramedConnection.this.pushObserver.onHeaders(paramInt, paramList, paramBoolean);
if (bool) {}
try
{
FramedConnection.this.frameWriter.rstStream(paramInt, ErrorCode.CANCEL);
if ((bool) || (paramBoolean)) {
synchronized (FramedConnection.this)
{
FramedConnection.this.currentPushRequests.remove(Integer.valueOf(paramInt));
return;
}
}
return;
}
catch (IOException localIOException) {}
}
});
}
private void pushRequestLater(final int paramInt, final List<Header> paramList)
{
try
{
if (this.currentPushRequests.contains(Integer.valueOf(paramInt)))
{
writeSynResetLater(paramInt, ErrorCode.PROTOCOL_ERROR);
return;
}
this.currentPushRequests.add(Integer.valueOf(paramInt));
this.pushExecutor.execute(new NamedRunnable("OkHttp %s Push Request[%s]", new Object[] { this.hostName, Integer.valueOf(paramInt) })
{
public void execute()
{
if (FramedConnection.this.pushObserver.onRequest(paramInt, paramList)) {
try
{
FramedConnection.this.frameWriter.rstStream(paramInt, ErrorCode.CANCEL);
synchronized (FramedConnection.this)
{
FramedConnection.this.currentPushRequests.remove(Integer.valueOf(paramInt));
return;
}
return;
}
catch (IOException localIOException) {}
}
}
});
return;
}
finally {}
}
private void pushResetLater(final int paramInt, final ErrorCode paramErrorCode)
{
this.pushExecutor.execute(new NamedRunnable("OkHttp %s Push Reset[%s]", new Object[] { this.hostName, Integer.valueOf(paramInt) })
{
public void execute()
{
FramedConnection.this.pushObserver.onReset(paramInt, paramErrorCode);
synchronized (FramedConnection.this)
{
FramedConnection.this.currentPushRequests.remove(Integer.valueOf(paramInt));
return;
}
}
});
}
private boolean pushedStream(int paramInt)
{
return (this.protocol == Protocol.HTTP_2) && (paramInt != 0) && ((paramInt & 0x1) == 0);
}
/* Error */
private Ping removePing(int paramInt)
{
// Byte code:
// 0: aload_0
// 1: monitorenter
// 2: aload_0
// 3: getfield 388 com/squareup/okhttp/internal/framed/FramedConnection:pings Ljava/util/Map;
// 6: ifnull +24 -> 30
// 9: aload_0
// 10: getfield 388 com/squareup/okhttp/internal/framed/FramedConnection:pings Ljava/util/Map;
// 13: iload_1
// 14: invokestatic 422 java/lang/Integer:valueOf (I)Ljava/lang/Integer;
// 17: invokeinterface 526 2 0
// 22: checkcast 390 com/squareup/okhttp/internal/framed/Ping
// 25: astore_2
// 26: aload_0
// 27: monitorexit
// 28: aload_2
// 29: areturn
// 30: aconst_null
// 31: astore_2
// 32: goto -6 -> 26
// 35: astore_2
// 36: aload_0
// 37: monitorexit
// 38: aload_2
// 39: athrow
// Local variable table:
// start length slot name signature
// 0 40 0 this FramedConnection
// 0 40 1 paramInt int
// 25 7 2 localPing Ping
// 35 4 2 localObject Object
// Exception table:
// from to target type
// 2 26 35 finally
}
private void setIdle(boolean paramBoolean)
{
if (paramBoolean) {}
for (;;)
{
try
{
l = System.nanoTime();
this.idleStartTimeNs = l;
return;
}
finally {}
long l = Long.MAX_VALUE;
}
}
private void writePing(boolean paramBoolean, int paramInt1, int paramInt2, Ping paramPing)
throws IOException
{
FrameWriter localFrameWriter = this.frameWriter;
if (paramPing != null) {}
try
{
paramPing.send();
this.frameWriter.ping(paramBoolean, paramInt1, paramInt2);
return;
}
finally {}
}
private void writePingLater(final boolean paramBoolean, final int paramInt1, final int paramInt2, final Ping paramPing)
{
executor.execute(new NamedRunnable("OkHttp %s ping %08x%08x", new Object[] { this.hostName, Integer.valueOf(paramInt1), Integer.valueOf(paramInt2) })
{
public void execute()
{
try
{
FramedConnection.this.writePing(paramBoolean, paramInt1, paramInt2, paramPing);
return;
}
catch (IOException localIOException) {}
}
});
}
final void addBytesToWriteWindow(long paramLong)
{
this.bytesLeftInWriteWindow += paramLong;
if (paramLong > 0L) {
notifyAll();
}
}
public final void close()
throws IOException
{
close(ErrorCode.NO_ERROR, ErrorCode.CANCEL);
}
public final void flush()
throws IOException
{
this.frameWriter.flush();
}
public final long getIdleStartTimeNs()
{
try
{
long l = this.idleStartTimeNs;
return l;
}
finally
{
localObject = finally;
throw ((Throwable)localObject);
}
}
public final Protocol getProtocol()
{
return this.protocol;
}
final FramedStream getStream(int paramInt)
{
try
{
FramedStream localFramedStream = (FramedStream)this.streams.get(Integer.valueOf(paramInt));
return localFramedStream;
}
finally
{
localObject = finally;
throw ((Throwable)localObject);
}
}
/* Error */
public final boolean isIdle()
{
// Byte code:
// 0: aload_0
// 1: monitorenter
// 2: aload_0
// 3: getfield 132 com/squareup/okhttp/internal/framed/FramedConnection:idleStartTimeNs J
// 6: lstore_1
// 7: lload_1
// 8: ldc2_w 527
// 11: lcmp
// 12: ifeq +9 -> 21
// 15: iconst_1
// 16: istore_3
// 17: aload_0
// 18: monitorexit
// 19: iload_3
// 20: ireturn
// 21: iconst_0
// 22: istore_3
// 23: goto -6 -> 17
// 26: astore 4
// 28: aload_0
// 29: monitorexit
// 30: aload 4
// 32: athrow
// Local variable table:
// start length slot name signature
// 0 33 0 this FramedConnection
// 6 2 1 l long
// 16 7 3 bool boolean
// 26 5 4 localObject Object
// Exception table:
// from to target type
// 2 7 26 finally
}
public final FramedStream newStream(List<Header> paramList, boolean paramBoolean1, boolean paramBoolean2)
throws IOException
{
return newStream(0, paramList, paramBoolean1, paramBoolean2);
}
public final int openStreamCount()
{
try
{
int i = this.streams.size();
return i;
}
finally
{
localObject = finally;
throw ((Throwable)localObject);
}
}
public final Ping ping()
throws IOException
{
Ping localPing = new Ping();
try
{
if (this.shutdown) {
throw new IOException("shutdown");
}
}
finally {}
int i = this.nextPingId;
this.nextPingId += 2;
if (this.pings == null) {
this.pings = new HashMap();
}
this.pings.put(Integer.valueOf(i), localObject);
writePing(false, i, 1330343787, (Ping)localObject);
return (Ping)localObject;
}
public final FramedStream pushStream(int paramInt, List<Header> paramList, boolean paramBoolean)
throws IOException
{
if (this.client) {
throw new IllegalStateException("Client cannot push requests.");
}
if (this.protocol != Protocol.HTTP_2) {
throw new IllegalStateException("protocol != HTTP_2");
}
return newStream(paramInt, paramList, paramBoolean, false);
}
final FramedStream removeStream(int paramInt)
{
try
{
FramedStream localFramedStream = (FramedStream)this.streams.remove(Integer.valueOf(paramInt));
if ((localFramedStream != null) && (this.streams.isEmpty())) {
setIdle(true);
}
notifyAll();
return localFramedStream;
}
finally {}
}
public final void sendConnectionPreface()
throws IOException
{
this.frameWriter.connectionPreface();
this.frameWriter.settings(this.okHttpSettings);
int i = this.okHttpSettings.getInitialWindowSize(65536);
if (i != 65536) {
this.frameWriter.windowUpdate(0, i - 65536);
}
}
public final void shutdown(ErrorCode paramErrorCode)
throws IOException
{
int i;
synchronized (this.frameWriter) {}
}
public final void writeData(int paramInt, boolean paramBoolean, Buffer paramBuffer, long paramLong)
throws IOException
{
long l = paramLong;
if (paramLong == 0L)
{
this.frameWriter.data(paramBoolean, paramInt, paramBuffer, 0);
return;
}
for (;;)
{
try
{
int i = Math.min((int)Math.min(l, this.bytesLeftInWriteWindow), this.frameWriter.maxDataLength());
this.bytesLeftInWriteWindow -= i;
l -= i;
FrameWriter localFrameWriter = this.frameWriter;
if ((!paramBoolean) || (l != 0L)) {
break label170;
}
bool = true;
localFrameWriter.data(bool, paramInt, paramBuffer, i);
if (l <= 0L) {
break;
}
try
{
if (this.bytesLeftInWriteWindow > 0L) {
continue;
}
if (!this.streams.containsKey(Integer.valueOf(paramInt))) {
throw new IOException("stream closed");
}
}
catch (InterruptedException paramBuffer)
{
throw new InterruptedIOException();
}
wait();
}
finally {}
continue;
label170:
boolean bool = false;
}
}
final void writeSynReply(int paramInt, boolean paramBoolean, List<Header> paramList)
throws IOException
{
this.frameWriter.synReply(paramBoolean, paramInt, paramList);
}
final void writeSynReset(int paramInt, ErrorCode paramErrorCode)
throws IOException
{
this.frameWriter.rstStream(paramInt, paramErrorCode);
}
final void writeSynResetLater(final int paramInt, final ErrorCode paramErrorCode)
{
executor.submit(new NamedRunnable("OkHttp %s stream %d", new Object[] { this.hostName, Integer.valueOf(paramInt) })
{
public void execute()
{
try
{
FramedConnection.this.writeSynReset(paramInt, paramErrorCode);
return;
}
catch (IOException localIOException) {}
}
});
}
final void writeWindowUpdateLater(final int paramInt, final long paramLong)
{
executor.execute(new NamedRunnable("OkHttp Window Update %s stream %d", new Object[] { this.hostName, Integer.valueOf(paramInt) })
{
public void execute()
{
try
{
FramedConnection.this.frameWriter.windowUpdate(paramInt, paramLong);
return;
}
catch (IOException localIOException) {}
}
});
}
public static class Builder
{
private boolean client;
private IncomingStreamHandler handler = IncomingStreamHandler.REFUSE_INCOMING_STREAMS;
private String hostName;
private Protocol protocol = Protocol.SPDY_3;
private PushObserver pushObserver = PushObserver.CANCEL;
private Socket socket;
public Builder(String paramString, boolean paramBoolean, Socket paramSocket)
throws IOException
{
this.hostName = paramString;
this.client = paramBoolean;
this.socket = paramSocket;
}
public Builder(boolean paramBoolean, Socket paramSocket)
throws IOException
{
this(((InetSocketAddress)paramSocket.getRemoteSocketAddress()).getHostName(), paramBoolean, paramSocket);
}
public FramedConnection build()
throws IOException
{
return new FramedConnection(this, null);
}
public Builder handler(IncomingStreamHandler paramIncomingStreamHandler)
{
this.handler = paramIncomingStreamHandler;
return this;
}
public Builder protocol(Protocol paramProtocol)
{
this.protocol = paramProtocol;
return this;
}
public Builder pushObserver(PushObserver paramPushObserver)
{
this.pushObserver = paramPushObserver;
return this;
}
}
class Reader
extends NamedRunnable
implements FrameReader.Handler
{
FrameReader frameReader;
private Reader()
{
super(new Object[] { FramedConnection.this.hostName });
}
private void ackSettingsLater(final Settings paramSettings)
{
FramedConnection.executor.execute(new NamedRunnable("OkHttp %s ACK Settings", new Object[] { FramedConnection.this.hostName })
{
public void execute()
{
try
{
FramedConnection.this.frameWriter.ackSettings(paramSettings);
return;
}
catch (IOException localIOException) {}
}
});
}
public void ackSettings() {}
public void alternateService(int paramInt1, String paramString1, ByteString paramByteString, String paramString2, int paramInt2, long paramLong) {}
public void data(boolean paramBoolean, int paramInt1, BufferedSource paramBufferedSource, int paramInt2)
throws IOException
{
if (FramedConnection.this.pushedStream(paramInt1)) {
FramedConnection.this.pushDataLater(paramInt1, paramBufferedSource, paramInt2, paramBoolean);
}
FramedStream localFramedStream;
do
{
return;
localFramedStream = FramedConnection.this.getStream(paramInt1);
if (localFramedStream == null)
{
FramedConnection.this.writeSynResetLater(paramInt1, ErrorCode.INVALID_STREAM);
paramBufferedSource.skip(paramInt2);
return;
}
localFramedStream.receiveData(paramBufferedSource, paramInt2);
} while (!paramBoolean);
localFramedStream.receiveFin();
}
/* Error */
protected void execute()
{
// Byte code:
// 0: getstatic 102 com/squareup/okhttp/internal/framed/ErrorCode:INTERNAL_ERROR Lcom/squareup/okhttp/internal/framed/ErrorCode;
// 3: astore_3
// 4: getstatic 102 com/squareup/okhttp/internal/framed/ErrorCode:INTERNAL_ERROR Lcom/squareup/okhttp/internal/framed/ErrorCode;
// 7: astore 4
// 9: aload_3
// 10: astore_2
// 11: aload_3
// 12: astore_1
// 13: aload_0
// 14: aload_0
// 15: getfield 21 com/squareup/okhttp/internal/framed/FramedConnection$Reader:this$0 Lcom/squareup/okhttp/internal/framed/FramedConnection;
// 18: getfield 106 com/squareup/okhttp/internal/framed/FramedConnection:variant Lcom/squareup/okhttp/internal/framed/Variant;
// 21: aload_0
// 22: getfield 21 com/squareup/okhttp/internal/framed/FramedConnection$Reader:this$0 Lcom/squareup/okhttp/internal/framed/FramedConnection;
// 25: getfield 110 com/squareup/okhttp/internal/framed/FramedConnection:socket Ljava/net/Socket;
// 28: invokestatic 116 okio/Okio:source (Ljava/net/Socket;)Lokio/Source;
// 31: invokestatic 120 okio/Okio:buffer (Lokio/Source;)Lokio/BufferedSource;
// 34: aload_0
// 35: getfield 21 com/squareup/okhttp/internal/framed/FramedConnection$Reader:this$0 Lcom/squareup/okhttp/internal/framed/FramedConnection;
// 38: getfield 124 com/squareup/okhttp/internal/framed/FramedConnection:client Z
// 41: invokeinterface 130 3 0
// 46: putfield 132 com/squareup/okhttp/internal/framed/FramedConnection$Reader:frameReader Lcom/squareup/okhttp/internal/framed/FrameReader;
// 49: aload_3
// 50: astore_2
// 51: aload_3
// 52: astore_1
// 53: aload_0
// 54: getfield 21 com/squareup/okhttp/internal/framed/FramedConnection$Reader:this$0 Lcom/squareup/okhttp/internal/framed/FramedConnection;
// 57: getfield 124 com/squareup/okhttp/internal/framed/FramedConnection:client Z
// 60: ifne +16 -> 76
// 63: aload_3
// 64: astore_2
// 65: aload_3
// 66: astore_1
// 67: aload_0
// 68: getfield 132 com/squareup/okhttp/internal/framed/FramedConnection$Reader:frameReader Lcom/squareup/okhttp/internal/framed/FrameReader;
// 71: invokeinterface 137 1 0
// 76: aload_3
// 77: astore_2
// 78: aload_3
// 79: astore_1
// 80: aload_0
// 81: getfield 132 com/squareup/okhttp/internal/framed/FramedConnection$Reader:frameReader Lcom/squareup/okhttp/internal/framed/FrameReader;
// 84: aload_0
// 85: invokeinterface 141 2 0
// 90: ifne -14 -> 76
// 93: aload_3
// 94: astore_2
// 95: aload_3
// 96: astore_1
// 97: getstatic 144 com/squareup/okhttp/internal/framed/ErrorCode:NO_ERROR Lcom/squareup/okhttp/internal/framed/ErrorCode;
// 100: astore_3
// 101: aload_3
// 102: astore_2
// 103: aload_3
// 104: astore_1
// 105: getstatic 147 com/squareup/okhttp/internal/framed/ErrorCode:CANCEL Lcom/squareup/okhttp/internal/framed/ErrorCode;
// 108: astore 5
// 110: aload_0
// 111: getfield 21 com/squareup/okhttp/internal/framed/FramedConnection$Reader:this$0 Lcom/squareup/okhttp/internal/framed/FramedConnection;
// 114: aload_3
// 115: aload 5
// 117: invokestatic 151 com/squareup/okhttp/internal/framed/FramedConnection:access$1000 (Lcom/squareup/okhttp/internal/framed/FramedConnection;Lcom/squareup/okhttp/internal/framed/ErrorCode;Lcom/squareup/okhttp/internal/framed/ErrorCode;)V
// 120: aload_0
// 121: getfield 132 com/squareup/okhttp/internal/framed/FramedConnection$Reader:frameReader Lcom/squareup/okhttp/internal/framed/FrameReader;
// 124: invokestatic 157 com/squareup/okhttp/internal/Util:closeQuietly (Ljava/io/Closeable;)V
// 127: return
// 128: astore_1
// 129: aload_2
// 130: astore_1
// 131: getstatic 160 com/squareup/okhttp/internal/framed/ErrorCode:PROTOCOL_ERROR Lcom/squareup/okhttp/internal/framed/ErrorCode;
// 134: astore_3
// 135: getstatic 160 com/squareup/okhttp/internal/framed/ErrorCode:PROTOCOL_ERROR Lcom/squareup/okhttp/internal/framed/ErrorCode;
// 138: astore_1
// 139: aload_0
// 140: getfield 21 com/squareup/okhttp/internal/framed/FramedConnection$Reader:this$0 Lcom/squareup/okhttp/internal/framed/FramedConnection;
// 143: aload_3
// 144: aload_1
// 145: invokestatic 151 com/squareup/okhttp/internal/framed/FramedConnection:access$1000 (Lcom/squareup/okhttp/internal/framed/FramedConnection;Lcom/squareup/okhttp/internal/framed/ErrorCode;Lcom/squareup/okhttp/internal/framed/ErrorCode;)V
// 148: aload_0
// 149: getfield 132 com/squareup/okhttp/internal/framed/FramedConnection$Reader:frameReader Lcom/squareup/okhttp/internal/framed/FrameReader;
// 152: invokestatic 157 com/squareup/okhttp/internal/Util:closeQuietly (Ljava/io/Closeable;)V
// 155: return
// 156: astore_2
// 157: aload_1
// 158: astore_3
// 159: aload_2
// 160: astore_1
// 161: aload_0
// 162: getfield 21 com/squareup/okhttp/internal/framed/FramedConnection$Reader:this$0 Lcom/squareup/okhttp/internal/framed/FramedConnection;
// 165: aload_3
// 166: aload 4
// 168: invokestatic 151 com/squareup/okhttp/internal/framed/FramedConnection:access$1000 (Lcom/squareup/okhttp/internal/framed/FramedConnection;Lcom/squareup/okhttp/internal/framed/ErrorCode;Lcom/squareup/okhttp/internal/framed/ErrorCode;)V
// 171: aload_0
// 172: getfield 132 com/squareup/okhttp/internal/framed/FramedConnection$Reader:frameReader Lcom/squareup/okhttp/internal/framed/FrameReader;
// 175: invokestatic 157 com/squareup/okhttp/internal/Util:closeQuietly (Ljava/io/Closeable;)V
// 178: aload_1
// 179: athrow
// 180: astore_2
// 181: goto -10 -> 171
// 184: astore_1
// 185: goto -24 -> 161
// 188: astore_1
// 189: goto -41 -> 148
// 192: astore_1
// 193: goto -73 -> 120
// Local variable table:
// start length slot name signature
// 0 196 0 this Reader
// 12 93 1 localObject1 Object
// 128 1 1 localIOException1 IOException
// 130 49 1 localObject2 Object
// 184 1 1 localObject3 Object
// 188 1 1 localIOException2 IOException
// 192 1 1 localIOException3 IOException
// 10 120 2 localObject4 Object
// 156 4 2 localObject5 Object
// 180 1 2 localIOException4 IOException
// 3 163 3 localObject6 Object
// 7 160 4 localErrorCode1 ErrorCode
// 108 8 5 localErrorCode2 ErrorCode
// Exception table:
// from to target type
// 13 49 128 java/io/IOException
// 53 63 128 java/io/IOException
// 67 76 128 java/io/IOException
// 80 93 128 java/io/IOException
// 97 101 128 java/io/IOException
// 105 110 128 java/io/IOException
// 13 49 156 finally
// 53 63 156 finally
// 67 76 156 finally
// 80 93 156 finally
// 97 101 156 finally
// 105 110 156 finally
// 131 135 156 finally
// 161 171 180 java/io/IOException
// 135 139 184 finally
// 139 148 188 java/io/IOException
// 110 120 192 java/io/IOException
}
public void goAway(int paramInt, ErrorCode arg2, ByteString paramByteString)
{
paramByteString.size();
synchronized (FramedConnection.this)
{
paramByteString = (FramedStream[])FramedConnection.this.streams.values().toArray(new FramedStream[FramedConnection.this.streams.size()]);
FramedConnection.access$1402(FramedConnection.this, true);
int j = paramByteString.length;
int i = 0;
if (i < j)
{
??? = paramByteString[i];
if ((???.getId() > paramInt) && (???.isLocallyInitiated()))
{
???.receiveRstStream(ErrorCode.REFUSED_STREAM);
FramedConnection.this.removeStream(???.getId());
}
i += 1;
}
}
}
public void headers(boolean paramBoolean1, boolean paramBoolean2, int paramInt1, int paramInt2, final List<Header> paramList, HeadersMode paramHeadersMode)
{
if (FramedConnection.this.pushedStream(paramInt1)) {
FramedConnection.this.pushHeadersLater(paramInt1, paramList, paramBoolean2);
}
FramedStream localFramedStream;
do
{
return;
synchronized (FramedConnection.this)
{
if (FramedConnection.this.shutdown) {
return;
}
}
localFramedStream = FramedConnection.this.getStream(paramInt1);
if (localFramedStream == null)
{
if (paramHeadersMode.failIfStreamAbsent())
{
FramedConnection.this.writeSynResetLater(paramInt1, ErrorCode.INVALID_STREAM);
return;
}
if (paramInt1 <= FramedConnection.this.lastGoodStreamId) {
return;
}
if (paramInt1 % 2 == FramedConnection.this.nextStreamId % 2) {
return;
}
paramList = new FramedStream(paramInt1, FramedConnection.this, paramBoolean1, paramBoolean2, paramList);
FramedConnection.access$1502(FramedConnection.this, paramInt1);
FramedConnection.this.streams.put(Integer.valueOf(paramInt1), paramList);
FramedConnection.executor.execute(new NamedRunnable("OkHttp %s stream %d", new Object[] { FramedConnection.this.hostName, Integer.valueOf(paramInt1) })
{
public void execute()
{
try
{
FramedConnection.this.handler.receive(paramList);
return;
}
catch (IOException localIOException1)
{
Internal.logger.log(Level.INFO, "StreamHandler failure for " + FramedConnection.this.hostName, localIOException1);
try
{
paramList.close(ErrorCode.PROTOCOL_ERROR);
return;
}
catch (IOException localIOException2) {}
}
}
});
return;
}
if (paramHeadersMode.failIfStreamPresent())
{
localFramedStream.closeLater(ErrorCode.PROTOCOL_ERROR);
FramedConnection.this.removeStream(paramInt1);
return;
}
localFramedStream.receiveHeaders(paramList, paramHeadersMode);
} while (!paramBoolean2);
localFramedStream.receiveFin();
}
public void ping(boolean paramBoolean, int paramInt1, int paramInt2)
{
if (paramBoolean)
{
Ping localPing = FramedConnection.this.removePing(paramInt1);
if (localPing != null) {
localPing.receive();
}
return;
}
FramedConnection.this.writePingLater(true, paramInt1, paramInt2, null);
}
public void priority(int paramInt1, int paramInt2, int paramInt3, boolean paramBoolean) {}
public void pushPromise(int paramInt1, int paramInt2, List<Header> paramList)
{
FramedConnection.this.pushRequestLater(paramInt2, paramList);
}
public void rstStream(int paramInt, ErrorCode paramErrorCode)
{
if (FramedConnection.this.pushedStream(paramInt)) {
FramedConnection.this.pushResetLater(paramInt, paramErrorCode);
}
FramedStream localFramedStream;
do
{
return;
localFramedStream = FramedConnection.this.removeStream(paramInt);
} while (localFramedStream == null);
localFramedStream.receiveRstStream(paramErrorCode);
}
public void settings(boolean paramBoolean, Settings paramSettings)
{
for (;;)
{
int i;
synchronized (FramedConnection.this)
{
i = FramedConnection.this.peerSettings.getInitialWindowSize(65536);
if (paramBoolean) {
FramedConnection.this.peerSettings.clear();
}
FramedConnection.this.peerSettings.merge(paramSettings);
if (FramedConnection.this.getProtocol() == Protocol.HTTP_2) {
ackSettingsLater(paramSettings);
}
int j = FramedConnection.this.peerSettings.getInitialWindowSize(65536);
if ((j == -1) || (j == i)) {
break label248;
}
l = j - i;
if (!FramedConnection.this.receivedInitialPeerSettings)
{
FramedConnection.this.addBytesToWriteWindow(l);
FramedConnection.access$2102(FramedConnection.this, true);
}
if (FramedConnection.this.streams.isEmpty()) {
break label243;
}
paramSettings = (FramedStream[])FramedConnection.this.streams.values().toArray(new FramedStream[FramedConnection.this.streams.size()]);
if ((paramSettings == null) || (l == 0L)) {
break label242;
}
j = paramSettings.length;
i = 0;
if (i >= j) {
break label242;
}
}
synchronized (paramSettings[i])
{
???.addBytesToWriteWindow(l);
i += 1;
continue;
paramSettings = finally;
throw paramSettings;
}
label242:
return;
label243:
paramSettings = null;
continue;
label248:
paramSettings = null;
long l = 0L;
}
}
public void windowUpdate(int paramInt, long paramLong)
{
if (paramInt == 0) {
synchronized (FramedConnection.this)
{
FramedConnection localFramedConnection = FramedConnection.this;
localFramedConnection.bytesLeftInWriteWindow += paramLong;
FramedConnection.this.notifyAll();
return;
}
}
??? = FramedConnection.this.getStream(paramInt);
if (??? != null) {
try
{
((FramedStream)???).addBytesToWriteWindow(paramLong);
return;
}
finally {}
}
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/okhttp/internal/framed/FramedConnection.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/