Chromium Code Reviews| Index: runtime/bin/socket_patch.dart |
| =================================================================== |
| --- runtime/bin/socket_patch.dart (revision 17848) |
| +++ runtime/bin/socket_patch.dart (working copy) |
| @@ -690,27 +690,31 @@ |
| } |
| void write() { |
| - if (subscription == null) return; |
| - assert(buffer != null); |
| - // Write as much as possible. |
| - offset += socket._write(buffer, offset, buffer.length - offset); |
| - if (offset < buffer.length) { |
| - if (!paused) { |
| - paused = true; |
| - // TODO(ajohnsen): It would be nice to avoid this check. |
| - // Some info: socket._write can emit an event, if it fails to write. |
| - // If the user closes the socket in that event, stop() will be called |
| - // before we get a change to pause. |
| - if (subscription == null) return; |
| - subscription.pause(); |
| + try { |
| + if (subscription == null) return; |
| + assert(buffer != null); |
| + // Write as much as possible. |
| + offset += socket._write(buffer, offset, buffer.length - offset); |
|
Mads Ager (google)
2013/01/31 07:53:30
Accidental indentation change?
Søren Gjesse
2013/01/31 12:12:01
Done.
|
| + if (offset < buffer.length) { |
| + if (!paused) { |
| + paused = true; |
| + // TODO(ajohnsen): It would be nice to avoid this check. |
| + // Some info: socket._write can emit an event, if it fails to write. |
| + // If the user closes the socket in that event, stop() will be called |
| + // before we get a change to pause. |
| + if (subscription == null) return; |
| + subscription.pause(); |
| + } |
| + socket._enableWriteEvent(); |
| + } else { |
| + buffer = null; |
| + if (paused) { |
| + paused = false; |
| + subscription.resume(); |
| + } |
| } |
| - socket._enableWriteEvent(); |
| - } else { |
| - buffer = null; |
| - if (paused) { |
| - paused = false; |
| - subscription.resume(); |
| - } |
| + } catch (e) { |
| + socket._consumerDone(e); |
| } |
| } |
| @@ -906,12 +910,12 @@ |
| } |
| } |
| - void _consumerDone() { |
| + void _consumerDone([error]) { |
| if (_raw != null) { |
| _raw.shutdown(SocketDirection.SEND); |
| _disableWriteEvent(); |
| } |
| - _done(); |
| + _done(error); |
| } |
| } |