OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.sdk.internal.websocket; | 5 package org.chromium.sdk.internal.websocket; |
6 | 6 |
7 import java.io.IOException; | 7 import java.io.IOException; |
8 import java.nio.ByteBuffer; | 8 import java.nio.ByteBuffer; |
9 import java.nio.CharBuffer; | 9 import java.nio.CharBuffer; |
10 import java.nio.charset.Charset; | 10 import java.nio.charset.Charset; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 INPUT_STREAM_PROBLEM, | 63 INPUT_STREAM_PROBLEM, |
64 | 64 |
65 /** | 65 /** |
66 * Closed as requested by {@link WsConnection#close()}. | 66 * Closed as requested by {@link WsConnection#close()}. |
67 */ | 67 */ |
68 USER_REQUEST, | 68 USER_REQUEST, |
69 | 69 |
70 /** | 70 /** |
71 * Connection close has been requested from remote side. | 71 * Connection close has been requested from remote side. |
72 */ | 72 */ |
73 REMOTE_CLOSE_REQUEST | 73 REMOTE_CLOSE_REQUEST, |
| 74 |
| 75 /** |
| 76 * Remote side silently closed connection (without breaking a message). |
| 77 */ |
| 78 REMOTE_SILENTLY_CLOSED, |
74 } | 79 } |
75 | 80 |
76 @Override | 81 @Override |
77 public RelayOk runInDispatchThread(final Runnable runnable, final SyncCallback
syncCallback) { | 82 public RelayOk runInDispatchThread(final Runnable runnable, final SyncCallback
syncCallback) { |
78 MessageDispatcher messageDispatcher = new MessageDispatcher() { | 83 MessageDispatcher messageDispatcher = new MessageDispatcher() { |
79 @Override | 84 @Override |
80 boolean dispatch(Listener userListener) { | 85 boolean dispatch(Listener userListener) { |
81 RuntimeException ex = null; | 86 RuntimeException ex = null; |
82 try { | 87 try { |
83 runnable.run(); | 88 runnable.run(); |
(...skipping 18 matching lines...) Expand all Loading... |
102 @Override | 107 @Override |
103 public void startListening(final Listener listener) { | 108 public void startListening(final Listener listener) { |
104 final INPUT loggableReader = socketWrapper.getLoggableInput(); | 109 final INPUT loggableReader = socketWrapper.getLoggableInput(); |
105 Runnable listenRunnable = new Runnable() { | 110 Runnable listenRunnable = new Runnable() { |
106 @Override | 111 @Override |
107 public void run() { | 112 public void run() { |
108 Exception closeCause = null; | 113 Exception closeCause = null; |
109 CloseReason closeReason = null; | 114 CloseReason closeReason = null; |
110 try { | 115 try { |
111 closeReason = runListenLoop(loggableReader); | 116 closeReason = runListenLoop(loggableReader); |
| 117 if (closeReason == CloseReason.REMOTE_SILENTLY_CLOSED) { |
| 118 LOGGER.log(Level.INFO, |
| 119 "Remote side silently closed connection without 'close' message"
); |
| 120 } |
112 } catch (IOException e) { | 121 } catch (IOException e) { |
113 closeCause = e; | 122 closeCause = e; |
114 LOGGER.log(Level.SEVERE, "Connection read failure", e); | 123 LOGGER.log(Level.SEVERE, "Connection read failure", e); |
115 } catch (InterruptedException e) { | 124 } catch (InterruptedException e) { |
116 closeCause = e; | 125 closeCause = e; |
117 closeReason = CloseReason.USER_REQUEST; | 126 closeReason = CloseReason.USER_REQUEST; |
118 LOGGER.log(Level.SEVERE, "Thread interruption", e); | 127 LOGGER.log(Level.SEVERE, "Thread interruption", e); |
119 } finally { | 128 } finally { |
120 synchronized (dispatchQueue) { | 129 synchronized (dispatchQueue) { |
121 dispatchQueue.add(EOS_MESSAGE_DISPATCHER); | 130 dispatchQueue.add(EOS_MESSAGE_DISPATCHER); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 private static final SignalConverter<AbstractSocketWrapper.ShutdownSignal, Clo
seReason> | 307 private static final SignalConverter<AbstractSocketWrapper.ShutdownSignal, Clo
seReason> |
299 SOCKET_TO_CONNECTION = | 308 SOCKET_TO_CONNECTION = |
300 new SignalConverter<AbstractSocketWrapper.ShutdownSignal, CloseReason>() { | 309 new SignalConverter<AbstractSocketWrapper.ShutdownSignal, CloseReason>() { |
301 @Override public CloseReason convert(AbstractSocketWrapper.ShutdownSigna
l source) { | 310 @Override public CloseReason convert(AbstractSocketWrapper.ShutdownSigna
l source) { |
302 return CloseReason.CONNECTION_CLOSED; | 311 return CloseReason.CONNECTION_CLOSED; |
303 } | 312 } |
304 }; | 313 }; |
305 | 314 |
306 private static final RelayOk DISPATCH_THREAD_PROMISES_TO_RELAY_OK = new RelayO
k() {}; | 315 private static final RelayOk DISPATCH_THREAD_PROMISES_TO_RELAY_OK = new RelayO
k() {}; |
307 } | 316 } |
OLD | NEW |