RealWebSocket.smali 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  1. .class public final Lokhttp3/internal/ws/RealWebSocket;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # interfaces
  5. .implements Lokhttp3/WebSocket;
  6. .implements Lokhttp3/internal/ws/WebSocketReader$FrameCallback;
  7. # annotations
  8. .annotation system Ldalvik/annotation/MemberClasses;
  9. value = {
  10. Lokhttp3/internal/ws/RealWebSocket$CancelRunnable;,
  11. Lokhttp3/internal/ws/RealWebSocket$Streams;,
  12. Lokhttp3/internal/ws/RealWebSocket$Close;,
  13. Lokhttp3/internal/ws/RealWebSocket$Message;,
  14. Lokhttp3/internal/ws/RealWebSocket$PingRunnable;
  15. }
  16. .end annotation
  17. # static fields
  18. .field static final synthetic $assertionsDisabled:Z = false
  19. .field private static final CANCEL_AFTER_CLOSE_MILLIS:J = 0xea60L
  20. .field private static final MAX_QUEUE_SIZE:J = 0x1000000L
  21. .field private static final ONLY_HTTP1:Ljava/util/List;
  22. .annotation system Ldalvik/annotation/Signature;
  23. value = {
  24. "Ljava/util/List<",
  25. "Lokhttp3/Protocol;",
  26. ">;"
  27. }
  28. .end annotation
  29. .end field
  30. # instance fields
  31. .field private call:Lokhttp3/Call;
  32. .field private cancelFuture:Ljava/util/concurrent/ScheduledFuture;
  33. .annotation system Ldalvik/annotation/Signature;
  34. value = {
  35. "Ljava/util/concurrent/ScheduledFuture<",
  36. "*>;"
  37. }
  38. .end annotation
  39. .end field
  40. .field private enqueuedClose:Z
  41. .field private executor:Ljava/util/concurrent/ScheduledExecutorService;
  42. .field private failed:Z
  43. .field private final key:Ljava/lang/String;
  44. .field final listener:Lokhttp3/WebSocketListener;
  45. .field private final messageAndCloseQueue:Ljava/util/ArrayDeque;
  46. .annotation system Ldalvik/annotation/Signature;
  47. value = {
  48. "Ljava/util/ArrayDeque<",
  49. "Ljava/lang/Object;",
  50. ">;"
  51. }
  52. .end annotation
  53. .end field
  54. .field private final originalRequest:Lokhttp3/Request;
  55. .field pingCount:I
  56. .field pongCount:I
  57. .field private final pongQueue:Ljava/util/ArrayDeque;
  58. .annotation system Ldalvik/annotation/Signature;
  59. value = {
  60. "Ljava/util/ArrayDeque<",
  61. "Lokio/ByteString;",
  62. ">;"
  63. }
  64. .end annotation
  65. .end field
  66. .field private queueSize:J
  67. .field private final random:Ljava/util/Random;
  68. .field private reader:Lokhttp3/internal/ws/WebSocketReader;
  69. .field private receivedCloseCode:I
  70. .field private receivedCloseReason:Ljava/lang/String;
  71. .field private streams:Lokhttp3/internal/ws/RealWebSocket$Streams;
  72. .field private writer:Lokhttp3/internal/ws/WebSocketWriter;
  73. .field private final writerRunnable:Ljava/lang/Runnable;
  74. # direct methods
  75. .method static constructor <clinit>()V
  76. .locals 1
  77. sget-object v0, Lokhttp3/Protocol;->HTTP_1_1:Lokhttp3/Protocol;
  78. invoke-static {v0}, Ljava/util/Collections;->singletonList(Ljava/lang/Object;)Ljava/util/List;
  79. move-result-object v0
  80. sput-object v0, Lokhttp3/internal/ws/RealWebSocket;->ONLY_HTTP1:Ljava/util/List;
  81. return-void
  82. .end method
  83. .method public constructor <init>(Lokhttp3/Request;Lokhttp3/WebSocketListener;Ljava/util/Random;)V
  84. .locals 2
  85. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  86. new-instance v0, Ljava/util/ArrayDeque;
  87. invoke-direct {v0}, Ljava/util/ArrayDeque;-><init>()V
  88. iput-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->pongQueue:Ljava/util/ArrayDeque;
  89. new-instance v0, Ljava/util/ArrayDeque;
  90. invoke-direct {v0}, Ljava/util/ArrayDeque;-><init>()V
  91. iput-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->messageAndCloseQueue:Ljava/util/ArrayDeque;
  92. const/4 v0, -0x1
  93. iput v0, p0, Lokhttp3/internal/ws/RealWebSocket;->receivedCloseCode:I
  94. invoke-virtual {p1}, Lokhttp3/Request;->method()Ljava/lang/String;
  95. move-result-object v0
  96. const-string v1, "GET"
  97. invoke-virtual {v1, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
  98. move-result v0
  99. if-eqz v0, :cond_0
  100. iput-object p1, p0, Lokhttp3/internal/ws/RealWebSocket;->originalRequest:Lokhttp3/Request;
  101. iput-object p2, p0, Lokhttp3/internal/ws/RealWebSocket;->listener:Lokhttp3/WebSocketListener;
  102. iput-object p3, p0, Lokhttp3/internal/ws/RealWebSocket;->random:Ljava/util/Random;
  103. const/16 p1, 0x10
  104. new-array p1, p1, [B
  105. invoke-virtual {p3, p1}, Ljava/util/Random;->nextBytes([B)V
  106. invoke-static {p1}, Lokio/ByteString;->of([B)Lokio/ByteString;
  107. move-result-object p1
  108. invoke-virtual {p1}, Lokio/ByteString;->base64()Ljava/lang/String;
  109. move-result-object p1
  110. iput-object p1, p0, Lokhttp3/internal/ws/RealWebSocket;->key:Ljava/lang/String;
  111. new-instance p1, Lokhttp3/internal/ws/RealWebSocket$1;
  112. invoke-direct {p1, p0}, Lokhttp3/internal/ws/RealWebSocket$1;-><init>(Lokhttp3/internal/ws/RealWebSocket;)V
  113. iput-object p1, p0, Lokhttp3/internal/ws/RealWebSocket;->writerRunnable:Ljava/lang/Runnable;
  114. return-void
  115. :cond_0
  116. new-instance p2, Ljava/lang/IllegalArgumentException;
  117. new-instance p3, Ljava/lang/StringBuilder;
  118. invoke-direct {p3}, Ljava/lang/StringBuilder;-><init>()V
  119. const-string v0, "Request must be GET: "
  120. invoke-virtual {p3, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  121. invoke-virtual {p1}, Lokhttp3/Request;->method()Ljava/lang/String;
  122. move-result-object p1
  123. invoke-virtual {p3, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  124. invoke-virtual {p3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  125. move-result-object p1
  126. invoke-direct {p2, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  127. throw p2
  128. .end method
  129. .method private runWriter()V
  130. .locals 2
  131. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  132. if-eqz v0, :cond_0
  133. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->writerRunnable:Ljava/lang/Runnable;
  134. invoke-interface {v0, v1}, Ljava/util/concurrent/ScheduledExecutorService;->execute(Ljava/lang/Runnable;)V
  135. :cond_0
  136. return-void
  137. .end method
  138. .method private declared-synchronized send(Lokio/ByteString;I)Z
  139. .locals 6
  140. monitor-enter p0
  141. :try_start_0
  142. iget-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->failed:Z
  143. const/4 v1, 0x0
  144. if-nez v0, :cond_2
  145. iget-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->enqueuedClose:Z
  146. if-eqz v0, :cond_0
  147. goto :goto_0
  148. :cond_0
  149. iget-wide v2, p0, Lokhttp3/internal/ws/RealWebSocket;->queueSize:J
  150. invoke-virtual {p1}, Lokio/ByteString;->size()I
  151. move-result v0
  152. int-to-long v4, v0
  153. add-long/2addr v2, v4
  154. const-wide/32 v4, 0x1000000
  155. cmp-long v0, v2, v4
  156. if-lez v0, :cond_1
  157. const/16 p1, 0x3e9
  158. const/4 p2, 0x0
  159. invoke-virtual {p0, p1, p2}, Lokhttp3/internal/ws/RealWebSocket;->close(ILjava/lang/String;)Z
  160. :try_end_0
  161. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  162. monitor-exit p0
  163. return v1
  164. :cond_1
  165. :try_start_1
  166. iget-wide v0, p0, Lokhttp3/internal/ws/RealWebSocket;->queueSize:J
  167. invoke-virtual {p1}, Lokio/ByteString;->size()I
  168. move-result v2
  169. int-to-long v2, v2
  170. add-long/2addr v0, v2
  171. iput-wide v0, p0, Lokhttp3/internal/ws/RealWebSocket;->queueSize:J
  172. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->messageAndCloseQueue:Ljava/util/ArrayDeque;
  173. new-instance v1, Lokhttp3/internal/ws/RealWebSocket$Message;
  174. invoke-direct {v1, p2, p1}, Lokhttp3/internal/ws/RealWebSocket$Message;-><init>(ILokio/ByteString;)V
  175. invoke-virtual {v0, v1}, Ljava/util/ArrayDeque;->add(Ljava/lang/Object;)Z
  176. invoke-direct {p0}, Lokhttp3/internal/ws/RealWebSocket;->runWriter()V
  177. :try_end_1
  178. .catchall {:try_start_1 .. :try_end_1} :catchall_0
  179. const/4 p1, 0x1
  180. monitor-exit p0
  181. return p1
  182. :cond_2
  183. :goto_0
  184. monitor-exit p0
  185. return v1
  186. :catchall_0
  187. move-exception p1
  188. monitor-exit p0
  189. throw p1
  190. .end method
  191. # virtual methods
  192. .method awaitTermination(ILjava/util/concurrent/TimeUnit;)V
  193. .locals 3
  194. .annotation system Ldalvik/annotation/Throws;
  195. value = {
  196. Ljava/lang/InterruptedException;
  197. }
  198. .end annotation
  199. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  200. int-to-long v1, p1
  201. invoke-interface {v0, v1, v2, p2}, Ljava/util/concurrent/ScheduledExecutorService;->awaitTermination(JLjava/util/concurrent/TimeUnit;)Z
  202. return-void
  203. .end method
  204. .method public cancel()V
  205. .locals 1
  206. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->call:Lokhttp3/Call;
  207. invoke-interface {v0}, Lokhttp3/Call;->cancel()V
  208. return-void
  209. .end method
  210. .method checkResponse(Lokhttp3/Response;)V
  211. .locals 5
  212. .annotation system Ldalvik/annotation/Throws;
  213. value = {
  214. Ljava/net/ProtocolException;
  215. }
  216. .end annotation
  217. invoke-virtual {p1}, Lokhttp3/Response;->code()I
  218. move-result v0
  219. const-string v1, "\'"
  220. const/16 v2, 0x65
  221. if-ne v0, v2, :cond_3
  222. const-string v0, "Connection"
  223. invoke-virtual {p1, v0}, Lokhttp3/Response;->header(Ljava/lang/String;)Ljava/lang/String;
  224. move-result-object v0
  225. const-string v2, "Upgrade"
  226. invoke-virtual {v2, v0}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z
  227. move-result v3
  228. if-eqz v3, :cond_2
  229. invoke-virtual {p1, v2}, Lokhttp3/Response;->header(Ljava/lang/String;)Ljava/lang/String;
  230. move-result-object v0
  231. const-string v2, "websocket"
  232. invoke-virtual {v2, v0}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z
  233. move-result v2
  234. if-eqz v2, :cond_1
  235. const-string v0, "Sec-WebSocket-Accept"
  236. invoke-virtual {p1, v0}, Lokhttp3/Response;->header(Ljava/lang/String;)Ljava/lang/String;
  237. move-result-object p1
  238. new-instance v0, Ljava/lang/StringBuilder;
  239. invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
  240. iget-object v2, p0, Lokhttp3/internal/ws/RealWebSocket;->key:Ljava/lang/String;
  241. invoke-virtual {v0, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  242. const-string v2, "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
  243. invoke-virtual {v0, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  244. invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  245. move-result-object v0
  246. invoke-static {v0}, Lokio/ByteString;->encodeUtf8(Ljava/lang/String;)Lokio/ByteString;
  247. move-result-object v0
  248. invoke-virtual {v0}, Lokio/ByteString;->sha1()Lokio/ByteString;
  249. move-result-object v0
  250. invoke-virtual {v0}, Lokio/ByteString;->base64()Ljava/lang/String;
  251. move-result-object v0
  252. invoke-virtual {v0, p1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
  253. move-result v2
  254. if-eqz v2, :cond_0
  255. return-void
  256. :cond_0
  257. new-instance v2, Ljava/net/ProtocolException;
  258. new-instance v3, Ljava/lang/StringBuilder;
  259. invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V
  260. const-string v4, "Expected \'Sec-WebSocket-Accept\' header value \'"
  261. invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  262. invoke-virtual {v3, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  263. const-string v0, "\' but was \'"
  264. invoke-virtual {v3, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  265. invoke-virtual {v3, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  266. invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  267. invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  268. move-result-object p1
  269. invoke-direct {v2, p1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  270. throw v2
  271. :cond_1
  272. new-instance p1, Ljava/net/ProtocolException;
  273. new-instance v2, Ljava/lang/StringBuilder;
  274. invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V
  275. const-string v3, "Expected \'Upgrade\' header value \'websocket\' but was \'"
  276. invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  277. invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  278. invoke-virtual {v2, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  279. invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  280. move-result-object v0
  281. invoke-direct {p1, v0}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  282. throw p1
  283. :cond_2
  284. new-instance p1, Ljava/net/ProtocolException;
  285. new-instance v2, Ljava/lang/StringBuilder;
  286. invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V
  287. const-string v3, "Expected \'Connection\' header value \'Upgrade\' but was \'"
  288. invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  289. invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  290. invoke-virtual {v2, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  291. invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  292. move-result-object v0
  293. invoke-direct {p1, v0}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  294. throw p1
  295. :cond_3
  296. new-instance v0, Ljava/net/ProtocolException;
  297. new-instance v2, Ljava/lang/StringBuilder;
  298. invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V
  299. const-string v3, "Expected HTTP 101 response but was \'"
  300. invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  301. invoke-virtual {p1}, Lokhttp3/Response;->code()I
  302. move-result v3
  303. invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
  304. const-string v3, " "
  305. invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  306. invoke-virtual {p1}, Lokhttp3/Response;->message()Ljava/lang/String;
  307. move-result-object p1
  308. invoke-virtual {v2, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  309. invoke-virtual {v2, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  310. invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  311. move-result-object p1
  312. invoke-direct {v0, p1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  313. throw v0
  314. .end method
  315. .method public close(ILjava/lang/String;)Z
  316. .locals 2
  317. const-wide/32 v0, 0xea60
  318. invoke-virtual {p0, p1, p2, v0, v1}, Lokhttp3/internal/ws/RealWebSocket;->close(ILjava/lang/String;J)Z
  319. move-result p1
  320. return p1
  321. .end method
  322. .method declared-synchronized close(ILjava/lang/String;J)Z
  323. .locals 6
  324. monitor-enter p0
  325. :try_start_0
  326. invoke-static {p1}, Lokhttp3/internal/ws/WebSocketProtocol;->validateCloseCode(I)V
  327. const/4 v0, 0x0
  328. if-eqz p2, :cond_1
  329. invoke-static {p2}, Lokio/ByteString;->encodeUtf8(Ljava/lang/String;)Lokio/ByteString;
  330. move-result-object v0
  331. invoke-virtual {v0}, Lokio/ByteString;->size()I
  332. move-result v1
  333. int-to-long v1, v1
  334. const-wide/16 v3, 0x7b
  335. cmp-long v5, v1, v3
  336. if-gtz v5, :cond_0
  337. goto :goto_0
  338. :cond_0
  339. new-instance p1, Ljava/lang/IllegalArgumentException;
  340. new-instance p3, Ljava/lang/StringBuilder;
  341. invoke-direct {p3}, Ljava/lang/StringBuilder;-><init>()V
  342. const-string p4, "reason.size() > 123: "
  343. invoke-virtual {p3, p4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  344. invoke-virtual {p3, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  345. invoke-virtual {p3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  346. move-result-object p2
  347. invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  348. throw p1
  349. :cond_1
  350. :goto_0
  351. iget-boolean p2, p0, Lokhttp3/internal/ws/RealWebSocket;->failed:Z
  352. if-nez p2, :cond_3
  353. iget-boolean p2, p0, Lokhttp3/internal/ws/RealWebSocket;->enqueuedClose:Z
  354. if-eqz p2, :cond_2
  355. goto :goto_1
  356. :cond_2
  357. const/4 p2, 0x1
  358. iput-boolean p2, p0, Lokhttp3/internal/ws/RealWebSocket;->enqueuedClose:Z
  359. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->messageAndCloseQueue:Ljava/util/ArrayDeque;
  360. new-instance v2, Lokhttp3/internal/ws/RealWebSocket$Close;
  361. invoke-direct {v2, p1, v0, p3, p4}, Lokhttp3/internal/ws/RealWebSocket$Close;-><init>(ILokio/ByteString;J)V
  362. invoke-virtual {v1, v2}, Ljava/util/ArrayDeque;->add(Ljava/lang/Object;)Z
  363. invoke-direct {p0}, Lokhttp3/internal/ws/RealWebSocket;->runWriter()V
  364. :try_end_0
  365. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  366. monitor-exit p0
  367. return p2
  368. :cond_3
  369. :goto_1
  370. const/4 p1, 0x0
  371. monitor-exit p0
  372. return p1
  373. :catchall_0
  374. move-exception p1
  375. monitor-exit p0
  376. throw p1
  377. .end method
  378. .method public connect(Lokhttp3/OkHttpClient;)V
  379. .locals 4
  380. invoke-virtual {p1}, Lokhttp3/OkHttpClient;->newBuilder()Lokhttp3/OkHttpClient$Builder;
  381. move-result-object p1
  382. sget-object v0, Lokhttp3/EventListener;->NONE:Lokhttp3/EventListener;
  383. invoke-virtual {p1, v0}, Lokhttp3/OkHttpClient$Builder;->eventListener(Lokhttp3/EventListener;)Lokhttp3/OkHttpClient$Builder;
  384. move-result-object p1
  385. sget-object v0, Lokhttp3/internal/ws/RealWebSocket;->ONLY_HTTP1:Ljava/util/List;
  386. invoke-virtual {p1, v0}, Lokhttp3/OkHttpClient$Builder;->protocols(Ljava/util/List;)Lokhttp3/OkHttpClient$Builder;
  387. move-result-object p1
  388. invoke-virtual {p1}, Lokhttp3/OkHttpClient$Builder;->build()Lokhttp3/OkHttpClient;
  389. move-result-object p1
  390. invoke-virtual {p1}, Lokhttp3/OkHttpClient;->pingIntervalMillis()I
  391. move-result v0
  392. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->originalRequest:Lokhttp3/Request;
  393. invoke-virtual {v1}, Lokhttp3/Request;->newBuilder()Lokhttp3/Request$Builder;
  394. move-result-object v1
  395. const-string v2, "Upgrade"
  396. const-string v3, "websocket"
  397. invoke-virtual {v1, v2, v3}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  398. move-result-object v1
  399. const-string v3, "Connection"
  400. invoke-virtual {v1, v3, v2}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  401. move-result-object v1
  402. iget-object v2, p0, Lokhttp3/internal/ws/RealWebSocket;->key:Ljava/lang/String;
  403. const-string v3, "Sec-WebSocket-Key"
  404. invoke-virtual {v1, v3, v2}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  405. move-result-object v1
  406. const-string v2, "Sec-WebSocket-Version"
  407. const-string v3, "13"
  408. invoke-virtual {v1, v2, v3}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  409. move-result-object v1
  410. invoke-virtual {v1}, Lokhttp3/Request$Builder;->build()Lokhttp3/Request;
  411. move-result-object v1
  412. sget-object v2, Lokhttp3/internal/Internal;->instance:Lokhttp3/internal/Internal;
  413. invoke-virtual {v2, p1, v1}, Lokhttp3/internal/Internal;->newWebSocketCall(Lokhttp3/OkHttpClient;Lokhttp3/Request;)Lokhttp3/Call;
  414. move-result-object p1
  415. iput-object p1, p0, Lokhttp3/internal/ws/RealWebSocket;->call:Lokhttp3/Call;
  416. iget-object p1, p0, Lokhttp3/internal/ws/RealWebSocket;->call:Lokhttp3/Call;
  417. new-instance v2, Lokhttp3/internal/ws/RealWebSocket$2;
  418. invoke-direct {v2, p0, v1, v0}, Lokhttp3/internal/ws/RealWebSocket$2;-><init>(Lokhttp3/internal/ws/RealWebSocket;Lokhttp3/Request;I)V
  419. invoke-interface {p1, v2}, Lokhttp3/Call;->enqueue(Lokhttp3/Callback;)V
  420. return-void
  421. .end method
  422. .method public failWebSocket(Ljava/lang/Exception;Lokhttp3/Response;)V
  423. .locals 3
  424. monitor-enter p0
  425. :try_start_0
  426. iget-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->failed:Z
  427. if-eqz v0, :cond_0
  428. monitor-exit p0
  429. return-void
  430. :cond_0
  431. const/4 v0, 0x1
  432. iput-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->failed:Z
  433. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->streams:Lokhttp3/internal/ws/RealWebSocket$Streams;
  434. const/4 v1, 0x0
  435. iput-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->streams:Lokhttp3/internal/ws/RealWebSocket$Streams;
  436. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->cancelFuture:Ljava/util/concurrent/ScheduledFuture;
  437. if-eqz v1, :cond_1
  438. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->cancelFuture:Ljava/util/concurrent/ScheduledFuture;
  439. const/4 v2, 0x0
  440. invoke-interface {v1, v2}, Ljava/util/concurrent/ScheduledFuture;->cancel(Z)Z
  441. :cond_1
  442. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  443. if-eqz v1, :cond_2
  444. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  445. invoke-interface {v1}, Ljava/util/concurrent/ScheduledExecutorService;->shutdown()V
  446. :cond_2
  447. monitor-exit p0
  448. :try_end_0
  449. .catchall {:try_start_0 .. :try_end_0} :catchall_1
  450. :try_start_1
  451. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->listener:Lokhttp3/WebSocketListener;
  452. invoke-virtual {v1, p0, p1, p2}, Lokhttp3/WebSocketListener;->onFailure(Lokhttp3/WebSocket;Ljava/lang/Throwable;Lokhttp3/Response;)V
  453. :try_end_1
  454. .catchall {:try_start_1 .. :try_end_1} :catchall_0
  455. invoke-static {v0}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  456. return-void
  457. :catchall_0
  458. move-exception p1
  459. invoke-static {v0}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  460. throw p1
  461. :catchall_1
  462. move-exception p1
  463. :try_start_2
  464. monitor-exit p0
  465. :try_end_2
  466. .catchall {:try_start_2 .. :try_end_2} :catchall_1
  467. throw p1
  468. .end method
  469. .method public initReaderAndWriter(Ljava/lang/String;JLokhttp3/internal/ws/RealWebSocket$Streams;)V
  470. .locals 7
  471. .annotation system Ldalvik/annotation/Throws;
  472. value = {
  473. Ljava/io/IOException;
  474. }
  475. .end annotation
  476. monitor-enter p0
  477. :try_start_0
  478. iput-object p4, p0, Lokhttp3/internal/ws/RealWebSocket;->streams:Lokhttp3/internal/ws/RealWebSocket$Streams;
  479. new-instance v0, Lokhttp3/internal/ws/WebSocketWriter;
  480. iget-boolean v1, p4, Lokhttp3/internal/ws/RealWebSocket$Streams;->client:Z
  481. iget-object v2, p4, Lokhttp3/internal/ws/RealWebSocket$Streams;->sink:Lokio/BufferedSink;
  482. iget-object v3, p0, Lokhttp3/internal/ws/RealWebSocket;->random:Ljava/util/Random;
  483. invoke-direct {v0, v1, v2, v3}, Lokhttp3/internal/ws/WebSocketWriter;-><init>(ZLokio/BufferedSink;Ljava/util/Random;)V
  484. iput-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->writer:Lokhttp3/internal/ws/WebSocketWriter;
  485. new-instance v0, Ljava/util/concurrent/ScheduledThreadPoolExecutor;
  486. const/4 v1, 0x1
  487. const/4 v2, 0x0
  488. invoke-static {p1, v2}, Lokhttp3/internal/Util;->threadFactory(Ljava/lang/String;Z)Ljava/util/concurrent/ThreadFactory;
  489. move-result-object p1
  490. invoke-direct {v0, v1, p1}, Ljava/util/concurrent/ScheduledThreadPoolExecutor;-><init>(ILjava/util/concurrent/ThreadFactory;)V
  491. iput-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  492. const-wide/16 v0, 0x0
  493. cmp-long p1, p2, v0
  494. if-eqz p1, :cond_0
  495. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  496. new-instance v1, Lokhttp3/internal/ws/RealWebSocket$PingRunnable;
  497. invoke-direct {v1, p0}, Lokhttp3/internal/ws/RealWebSocket$PingRunnable;-><init>(Lokhttp3/internal/ws/RealWebSocket;)V
  498. sget-object v6, Ljava/util/concurrent/TimeUnit;->MILLISECONDS:Ljava/util/concurrent/TimeUnit;
  499. move-wide v2, p2
  500. move-wide v4, p2
  501. invoke-interface/range {v0 .. v6}, Ljava/util/concurrent/ScheduledExecutorService;->scheduleAtFixedRate(Ljava/lang/Runnable;JJLjava/util/concurrent/TimeUnit;)Ljava/util/concurrent/ScheduledFuture;
  502. :cond_0
  503. iget-object p1, p0, Lokhttp3/internal/ws/RealWebSocket;->messageAndCloseQueue:Ljava/util/ArrayDeque;
  504. invoke-virtual {p1}, Ljava/util/ArrayDeque;->isEmpty()Z
  505. move-result p1
  506. if-nez p1, :cond_1
  507. invoke-direct {p0}, Lokhttp3/internal/ws/RealWebSocket;->runWriter()V
  508. :cond_1
  509. monitor-exit p0
  510. :try_end_0
  511. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  512. new-instance p1, Lokhttp3/internal/ws/WebSocketReader;
  513. iget-boolean p2, p4, Lokhttp3/internal/ws/RealWebSocket$Streams;->client:Z
  514. iget-object p3, p4, Lokhttp3/internal/ws/RealWebSocket$Streams;->source:Lokio/BufferedSource;
  515. invoke-direct {p1, p2, p3, p0}, Lokhttp3/internal/ws/WebSocketReader;-><init>(ZLokio/BufferedSource;Lokhttp3/internal/ws/WebSocketReader$FrameCallback;)V
  516. iput-object p1, p0, Lokhttp3/internal/ws/RealWebSocket;->reader:Lokhttp3/internal/ws/WebSocketReader;
  517. return-void
  518. :catchall_0
  519. move-exception p1
  520. :try_start_1
  521. monitor-exit p0
  522. :try_end_1
  523. .catchall {:try_start_1 .. :try_end_1} :catchall_0
  524. throw p1
  525. .end method
  526. .method public loopReader()V
  527. .locals 2
  528. .annotation system Ldalvik/annotation/Throws;
  529. value = {
  530. Ljava/io/IOException;
  531. }
  532. .end annotation
  533. :goto_0
  534. iget v0, p0, Lokhttp3/internal/ws/RealWebSocket;->receivedCloseCode:I
  535. const/4 v1, -0x1
  536. if-ne v0, v1, :cond_0
  537. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->reader:Lokhttp3/internal/ws/WebSocketReader;
  538. invoke-virtual {v0}, Lokhttp3/internal/ws/WebSocketReader;->processNextFrame()V
  539. goto :goto_0
  540. :cond_0
  541. return-void
  542. .end method
  543. .method public onReadClose(ILjava/lang/String;)V
  544. .locals 3
  545. const/4 v0, -0x1
  546. if-eq p1, v0, :cond_4
  547. monitor-enter p0
  548. :try_start_0
  549. iget v1, p0, Lokhttp3/internal/ws/RealWebSocket;->receivedCloseCode:I
  550. if-ne v1, v0, :cond_3
  551. iput p1, p0, Lokhttp3/internal/ws/RealWebSocket;->receivedCloseCode:I
  552. iput-object p2, p0, Lokhttp3/internal/ws/RealWebSocket;->receivedCloseReason:Ljava/lang/String;
  553. iget-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->enqueuedClose:Z
  554. const/4 v1, 0x0
  555. if-eqz v0, :cond_1
  556. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->messageAndCloseQueue:Ljava/util/ArrayDeque;
  557. invoke-virtual {v0}, Ljava/util/ArrayDeque;->isEmpty()Z
  558. move-result v0
  559. if-eqz v0, :cond_1
  560. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->streams:Lokhttp3/internal/ws/RealWebSocket$Streams;
  561. iput-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->streams:Lokhttp3/internal/ws/RealWebSocket$Streams;
  562. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->cancelFuture:Ljava/util/concurrent/ScheduledFuture;
  563. if-eqz v1, :cond_0
  564. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->cancelFuture:Ljava/util/concurrent/ScheduledFuture;
  565. const/4 v2, 0x0
  566. invoke-interface {v1, v2}, Ljava/util/concurrent/ScheduledFuture;->cancel(Z)Z
  567. :cond_0
  568. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  569. invoke-interface {v1}, Ljava/util/concurrent/ScheduledExecutorService;->shutdown()V
  570. goto :goto_0
  571. :cond_1
  572. move-object v0, v1
  573. :goto_0
  574. monitor-exit p0
  575. :try_end_0
  576. .catchall {:try_start_0 .. :try_end_0} :catchall_1
  577. :try_start_1
  578. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->listener:Lokhttp3/WebSocketListener;
  579. invoke-virtual {v1, p0, p1, p2}, Lokhttp3/WebSocketListener;->onClosing(Lokhttp3/WebSocket;ILjava/lang/String;)V
  580. if-eqz v0, :cond_2
  581. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->listener:Lokhttp3/WebSocketListener;
  582. invoke-virtual {v1, p0, p1, p2}, Lokhttp3/WebSocketListener;->onClosed(Lokhttp3/WebSocket;ILjava/lang/String;)V
  583. :try_end_1
  584. .catchall {:try_start_1 .. :try_end_1} :catchall_0
  585. :cond_2
  586. invoke-static {v0}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  587. return-void
  588. :catchall_0
  589. move-exception p1
  590. invoke-static {v0}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  591. throw p1
  592. :cond_3
  593. :try_start_2
  594. new-instance p1, Ljava/lang/IllegalStateException;
  595. const-string p2, "already closed"
  596. invoke-direct {p1, p2}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
  597. throw p1
  598. :catchall_1
  599. move-exception p1
  600. monitor-exit p0
  601. :try_end_2
  602. .catchall {:try_start_2 .. :try_end_2} :catchall_1
  603. throw p1
  604. :cond_4
  605. new-instance p1, Ljava/lang/IllegalArgumentException;
  606. invoke-direct {p1}, Ljava/lang/IllegalArgumentException;-><init>()V
  607. throw p1
  608. .end method
  609. .method public onReadMessage(Ljava/lang/String;)V
  610. .locals 1
  611. .annotation system Ldalvik/annotation/Throws;
  612. value = {
  613. Ljava/io/IOException;
  614. }
  615. .end annotation
  616. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->listener:Lokhttp3/WebSocketListener;
  617. invoke-virtual {v0, p0, p1}, Lokhttp3/WebSocketListener;->onMessage(Lokhttp3/WebSocket;Ljava/lang/String;)V
  618. return-void
  619. .end method
  620. .method public onReadMessage(Lokio/ByteString;)V
  621. .locals 1
  622. .annotation system Ldalvik/annotation/Throws;
  623. value = {
  624. Ljava/io/IOException;
  625. }
  626. .end annotation
  627. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->listener:Lokhttp3/WebSocketListener;
  628. invoke-virtual {v0, p0, p1}, Lokhttp3/WebSocketListener;->onMessage(Lokhttp3/WebSocket;Lokio/ByteString;)V
  629. return-void
  630. .end method
  631. .method public declared-synchronized onReadPing(Lokio/ByteString;)V
  632. .locals 1
  633. monitor-enter p0
  634. :try_start_0
  635. iget-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->failed:Z
  636. if-nez v0, :cond_1
  637. iget-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->enqueuedClose:Z
  638. if-eqz v0, :cond_0
  639. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->messageAndCloseQueue:Ljava/util/ArrayDeque;
  640. invoke-virtual {v0}, Ljava/util/ArrayDeque;->isEmpty()Z
  641. move-result v0
  642. if-eqz v0, :cond_0
  643. goto :goto_0
  644. :cond_0
  645. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->pongQueue:Ljava/util/ArrayDeque;
  646. invoke-virtual {v0, p1}, Ljava/util/ArrayDeque;->add(Ljava/lang/Object;)Z
  647. invoke-direct {p0}, Lokhttp3/internal/ws/RealWebSocket;->runWriter()V
  648. iget p1, p0, Lokhttp3/internal/ws/RealWebSocket;->pingCount:I
  649. add-int/lit8 p1, p1, 0x1
  650. iput p1, p0, Lokhttp3/internal/ws/RealWebSocket;->pingCount:I
  651. :try_end_0
  652. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  653. monitor-exit p0
  654. return-void
  655. :cond_1
  656. :goto_0
  657. monitor-exit p0
  658. return-void
  659. :catchall_0
  660. move-exception p1
  661. monitor-exit p0
  662. throw p1
  663. .end method
  664. .method public declared-synchronized onReadPong(Lokio/ByteString;)V
  665. .locals 0
  666. monitor-enter p0
  667. :try_start_0
  668. iget p1, p0, Lokhttp3/internal/ws/RealWebSocket;->pongCount:I
  669. add-int/lit8 p1, p1, 0x1
  670. iput p1, p0, Lokhttp3/internal/ws/RealWebSocket;->pongCount:I
  671. :try_end_0
  672. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  673. monitor-exit p0
  674. return-void
  675. :catchall_0
  676. move-exception p1
  677. monitor-exit p0
  678. throw p1
  679. .end method
  680. .method declared-synchronized pingCount()I
  681. .locals 1
  682. monitor-enter p0
  683. :try_start_0
  684. iget v0, p0, Lokhttp3/internal/ws/RealWebSocket;->pingCount:I
  685. :try_end_0
  686. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  687. monitor-exit p0
  688. return v0
  689. :catchall_0
  690. move-exception v0
  691. monitor-exit p0
  692. throw v0
  693. .end method
  694. .method declared-synchronized pong(Lokio/ByteString;)Z
  695. .locals 1
  696. monitor-enter p0
  697. :try_start_0
  698. iget-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->failed:Z
  699. if-nez v0, :cond_1
  700. iget-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->enqueuedClose:Z
  701. if-eqz v0, :cond_0
  702. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->messageAndCloseQueue:Ljava/util/ArrayDeque;
  703. invoke-virtual {v0}, Ljava/util/ArrayDeque;->isEmpty()Z
  704. move-result v0
  705. if-eqz v0, :cond_0
  706. goto :goto_1
  707. :cond_0
  708. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->pongQueue:Ljava/util/ArrayDeque;
  709. invoke-virtual {v0, p1}, Ljava/util/ArrayDeque;->add(Ljava/lang/Object;)Z
  710. invoke-direct {p0}, Lokhttp3/internal/ws/RealWebSocket;->runWriter()V
  711. :try_end_0
  712. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  713. const/4 p1, 0x1
  714. :goto_0
  715. monitor-exit p0
  716. return p1
  717. :cond_1
  718. :goto_1
  719. const/4 p1, 0x0
  720. goto :goto_0
  721. :catchall_0
  722. move-exception p1
  723. monitor-exit p0
  724. goto :goto_3
  725. :goto_2
  726. throw p1
  727. :goto_3
  728. goto :goto_2
  729. .end method
  730. .method declared-synchronized pongCount()I
  731. .locals 1
  732. monitor-enter p0
  733. :try_start_0
  734. iget v0, p0, Lokhttp3/internal/ws/RealWebSocket;->pongCount:I
  735. :try_end_0
  736. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  737. monitor-exit p0
  738. return v0
  739. :catchall_0
  740. move-exception v0
  741. monitor-exit p0
  742. throw v0
  743. .end method
  744. .method processNextFrame()Z
  745. .locals 3
  746. .annotation system Ldalvik/annotation/Throws;
  747. value = {
  748. Ljava/io/IOException;
  749. }
  750. .end annotation
  751. const/4 v0, 0x0
  752. :try_start_0
  753. iget-object v1, p0, Lokhttp3/internal/ws/RealWebSocket;->reader:Lokhttp3/internal/ws/WebSocketReader;
  754. invoke-virtual {v1}, Lokhttp3/internal/ws/WebSocketReader;->processNextFrame()V
  755. iget v1, p0, Lokhttp3/internal/ws/RealWebSocket;->receivedCloseCode:I
  756. :try_end_0
  757. .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
  758. const/4 v2, -0x1
  759. if-ne v1, v2, :cond_0
  760. const/4 v0, 0x1
  761. :cond_0
  762. return v0
  763. :catch_0
  764. move-exception v1
  765. const/4 v2, 0x0
  766. invoke-virtual {p0, v1, v2}, Lokhttp3/internal/ws/RealWebSocket;->failWebSocket(Ljava/lang/Exception;Lokhttp3/Response;)V
  767. return v0
  768. .end method
  769. .method public declared-synchronized queueSize()J
  770. .locals 2
  771. monitor-enter p0
  772. :try_start_0
  773. iget-wide v0, p0, Lokhttp3/internal/ws/RealWebSocket;->queueSize:J
  774. :try_end_0
  775. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  776. monitor-exit p0
  777. return-wide v0
  778. :catchall_0
  779. move-exception v0
  780. monitor-exit p0
  781. throw v0
  782. .end method
  783. .method public request()Lokhttp3/Request;
  784. .locals 1
  785. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->originalRequest:Lokhttp3/Request;
  786. return-object v0
  787. .end method
  788. .method public send(Ljava/lang/String;)Z
  789. .locals 1
  790. if-eqz p1, :cond_0
  791. invoke-static {p1}, Lokio/ByteString;->encodeUtf8(Ljava/lang/String;)Lokio/ByteString;
  792. move-result-object p1
  793. const/4 v0, 0x1
  794. invoke-direct {p0, p1, v0}, Lokhttp3/internal/ws/RealWebSocket;->send(Lokio/ByteString;I)Z
  795. move-result p1
  796. return p1
  797. :cond_0
  798. new-instance p1, Ljava/lang/NullPointerException;
  799. const-string v0, "text == null"
  800. invoke-direct {p1, v0}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V
  801. throw p1
  802. .end method
  803. .method public send(Lokio/ByteString;)Z
  804. .locals 1
  805. if-eqz p1, :cond_0
  806. const/4 v0, 0x2
  807. invoke-direct {p0, p1, v0}, Lokhttp3/internal/ws/RealWebSocket;->send(Lokio/ByteString;I)Z
  808. move-result p1
  809. return p1
  810. :cond_0
  811. new-instance p1, Ljava/lang/NullPointerException;
  812. const-string v0, "bytes == null"
  813. invoke-direct {p1, v0}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V
  814. throw p1
  815. .end method
  816. .method tearDown()V
  817. .locals 4
  818. .annotation system Ldalvik/annotation/Throws;
  819. value = {
  820. Ljava/lang/InterruptedException;
  821. }
  822. .end annotation
  823. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->cancelFuture:Ljava/util/concurrent/ScheduledFuture;
  824. if-eqz v0, :cond_0
  825. const/4 v1, 0x0
  826. invoke-interface {v0, v1}, Ljava/util/concurrent/ScheduledFuture;->cancel(Z)Z
  827. :cond_0
  828. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  829. invoke-interface {v0}, Ljava/util/concurrent/ScheduledExecutorService;->shutdown()V
  830. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  831. const-wide/16 v1, 0xa
  832. sget-object v3, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;
  833. invoke-interface {v0, v1, v2, v3}, Ljava/util/concurrent/ScheduledExecutorService;->awaitTermination(JLjava/util/concurrent/TimeUnit;)Z
  834. return-void
  835. .end method
  836. .method writeOneFrame()Z
  837. .locals 11
  838. .annotation system Ldalvik/annotation/Throws;
  839. value = {
  840. Ljava/io/IOException;
  841. }
  842. .end annotation
  843. monitor-enter p0
  844. :try_start_0
  845. iget-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->failed:Z
  846. const/4 v1, 0x0
  847. if-eqz v0, :cond_0
  848. monitor-exit p0
  849. return v1
  850. :cond_0
  851. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->writer:Lokhttp3/internal/ws/WebSocketWriter;
  852. iget-object v2, p0, Lokhttp3/internal/ws/RealWebSocket;->pongQueue:Ljava/util/ArrayDeque;
  853. invoke-virtual {v2}, Ljava/util/ArrayDeque;->poll()Ljava/lang/Object;
  854. move-result-object v2
  855. check-cast v2, Lokio/ByteString;
  856. const/4 v3, -0x1
  857. const/4 v4, 0x0
  858. if-nez v2, :cond_4
  859. iget-object v5, p0, Lokhttp3/internal/ws/RealWebSocket;->messageAndCloseQueue:Ljava/util/ArrayDeque;
  860. invoke-virtual {v5}, Ljava/util/ArrayDeque;->poll()Ljava/lang/Object;
  861. move-result-object v5
  862. instance-of v6, v5, Lokhttp3/internal/ws/RealWebSocket$Close;
  863. if-eqz v6, :cond_2
  864. iget v1, p0, Lokhttp3/internal/ws/RealWebSocket;->receivedCloseCode:I
  865. iget-object v6, p0, Lokhttp3/internal/ws/RealWebSocket;->receivedCloseReason:Ljava/lang/String;
  866. if-eq v1, v3, :cond_1
  867. iget-object v3, p0, Lokhttp3/internal/ws/RealWebSocket;->streams:Lokhttp3/internal/ws/RealWebSocket$Streams;
  868. iput-object v4, p0, Lokhttp3/internal/ws/RealWebSocket;->streams:Lokhttp3/internal/ws/RealWebSocket$Streams;
  869. iget-object v4, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  870. invoke-interface {v4}, Ljava/util/concurrent/ScheduledExecutorService;->shutdown()V
  871. move-object v4, v3
  872. goto :goto_1
  873. :cond_1
  874. iget-object v3, p0, Lokhttp3/internal/ws/RealWebSocket;->executor:Ljava/util/concurrent/ScheduledExecutorService;
  875. new-instance v7, Lokhttp3/internal/ws/RealWebSocket$CancelRunnable;
  876. invoke-direct {v7, p0}, Lokhttp3/internal/ws/RealWebSocket$CancelRunnable;-><init>(Lokhttp3/internal/ws/RealWebSocket;)V
  877. move-object v8, v5
  878. check-cast v8, Lokhttp3/internal/ws/RealWebSocket$Close;
  879. iget-wide v8, v8, Lokhttp3/internal/ws/RealWebSocket$Close;->cancelAfterCloseMillis:J
  880. sget-object v10, Ljava/util/concurrent/TimeUnit;->MILLISECONDS:Ljava/util/concurrent/TimeUnit;
  881. invoke-interface {v3, v7, v8, v9, v10}, Ljava/util/concurrent/ScheduledExecutorService;->schedule(Ljava/lang/Runnable;JLjava/util/concurrent/TimeUnit;)Ljava/util/concurrent/ScheduledFuture;
  882. move-result-object v3
  883. iput-object v3, p0, Lokhttp3/internal/ws/RealWebSocket;->cancelFuture:Ljava/util/concurrent/ScheduledFuture;
  884. goto :goto_1
  885. :cond_2
  886. if-nez v5, :cond_3
  887. monitor-exit p0
  888. return v1
  889. :cond_3
  890. move-object v6, v4
  891. goto :goto_0
  892. :cond_4
  893. move-object v5, v4
  894. move-object v6, v5
  895. :goto_0
  896. const/4 v1, -0x1
  897. :goto_1
  898. monitor-exit p0
  899. :try_end_0
  900. .catchall {:try_start_0 .. :try_end_0} :catchall_2
  901. if-eqz v2, :cond_5
  902. :try_start_1
  903. invoke-virtual {v0, v2}, Lokhttp3/internal/ws/WebSocketWriter;->writePong(Lokio/ByteString;)V
  904. goto :goto_2
  905. :cond_5
  906. instance-of v2, v5, Lokhttp3/internal/ws/RealWebSocket$Message;
  907. if-eqz v2, :cond_6
  908. move-object v1, v5
  909. check-cast v1, Lokhttp3/internal/ws/RealWebSocket$Message;
  910. iget-object v1, v1, Lokhttp3/internal/ws/RealWebSocket$Message;->data:Lokio/ByteString;
  911. check-cast v5, Lokhttp3/internal/ws/RealWebSocket$Message;
  912. iget v2, v5, Lokhttp3/internal/ws/RealWebSocket$Message;->formatOpcode:I
  913. invoke-virtual {v1}, Lokio/ByteString;->size()I
  914. move-result v3
  915. int-to-long v5, v3
  916. invoke-virtual {v0, v2, v5, v6}, Lokhttp3/internal/ws/WebSocketWriter;->newMessageSink(IJ)Lokio/Sink;
  917. move-result-object v0
  918. invoke-static {v0}, Lokio/Okio;->buffer(Lokio/Sink;)Lokio/BufferedSink;
  919. move-result-object v0
  920. invoke-interface {v0, v1}, Lokio/BufferedSink;->write(Lokio/ByteString;)Lokio/BufferedSink;
  921. invoke-interface {v0}, Lokio/Sink;->close()V
  922. monitor-enter p0
  923. :try_end_1
  924. .catchall {:try_start_1 .. :try_end_1} :catchall_1
  925. :try_start_2
  926. iget-wide v2, p0, Lokhttp3/internal/ws/RealWebSocket;->queueSize:J
  927. invoke-virtual {v1}, Lokio/ByteString;->size()I
  928. move-result v0
  929. int-to-long v0, v0
  930. sub-long/2addr v2, v0
  931. iput-wide v2, p0, Lokhttp3/internal/ws/RealWebSocket;->queueSize:J
  932. monitor-exit p0
  933. goto :goto_2
  934. :catchall_0
  935. move-exception v0
  936. monitor-exit p0
  937. :try_end_2
  938. .catchall {:try_start_2 .. :try_end_2} :catchall_0
  939. :try_start_3
  940. throw v0
  941. :cond_6
  942. instance-of v2, v5, Lokhttp3/internal/ws/RealWebSocket$Close;
  943. if-eqz v2, :cond_8
  944. check-cast v5, Lokhttp3/internal/ws/RealWebSocket$Close;
  945. iget v2, v5, Lokhttp3/internal/ws/RealWebSocket$Close;->code:I
  946. iget-object v3, v5, Lokhttp3/internal/ws/RealWebSocket$Close;->reason:Lokio/ByteString;
  947. invoke-virtual {v0, v2, v3}, Lokhttp3/internal/ws/WebSocketWriter;->writeClose(ILokio/ByteString;)V
  948. if-eqz v4, :cond_7
  949. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->listener:Lokhttp3/WebSocketListener;
  950. invoke-virtual {v0, p0, v1, v6}, Lokhttp3/WebSocketListener;->onClosed(Lokhttp3/WebSocket;ILjava/lang/String;)V
  951. :try_end_3
  952. .catchall {:try_start_3 .. :try_end_3} :catchall_1
  953. :cond_7
  954. :goto_2
  955. const/4 v0, 0x1
  956. invoke-static {v4}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  957. return v0
  958. :cond_8
  959. :try_start_4
  960. new-instance v0, Ljava/lang/AssertionError;
  961. invoke-direct {v0}, Ljava/lang/AssertionError;-><init>()V
  962. throw v0
  963. :try_end_4
  964. .catchall {:try_start_4 .. :try_end_4} :catchall_1
  965. :catchall_1
  966. move-exception v0
  967. invoke-static {v4}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  968. throw v0
  969. :catchall_2
  970. move-exception v0
  971. :try_start_5
  972. monitor-exit p0
  973. :try_end_5
  974. .catchall {:try_start_5 .. :try_end_5} :catchall_2
  975. throw v0
  976. .end method
  977. .method writePingFrame()V
  978. .locals 2
  979. monitor-enter p0
  980. :try_start_0
  981. iget-boolean v0, p0, Lokhttp3/internal/ws/RealWebSocket;->failed:Z
  982. if-eqz v0, :cond_0
  983. monitor-exit p0
  984. return-void
  985. :cond_0
  986. iget-object v0, p0, Lokhttp3/internal/ws/RealWebSocket;->writer:Lokhttp3/internal/ws/WebSocketWriter;
  987. monitor-exit p0
  988. :try_end_0
  989. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  990. :try_start_1
  991. sget-object v1, Lokio/ByteString;->EMPTY:Lokio/ByteString;
  992. invoke-virtual {v0, v1}, Lokhttp3/internal/ws/WebSocketWriter;->writePing(Lokio/ByteString;)V
  993. :try_end_1
  994. .catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_0
  995. goto :goto_0
  996. :catch_0
  997. move-exception v0
  998. const/4 v1, 0x0
  999. invoke-virtual {p0, v0, v1}, Lokhttp3/internal/ws/RealWebSocket;->failWebSocket(Ljava/lang/Exception;Lokhttp3/Response;)V
  1000. :goto_0
  1001. return-void
  1002. :catchall_0
  1003. move-exception v0
  1004. :try_start_2
  1005. monitor-exit p0
  1006. :try_end_2
  1007. .catchall {:try_start_2 .. :try_end_2} :catchall_0
  1008. throw v0
  1009. .end method