| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /* | 5 /* |
| 6 * SocketNativeWrapper is defined in native and holds a field to store the | 6 * SocketNativeWrapper is defined in native and holds a field to store the |
| 7 * native socket object. | 7 * native socket object. |
| 8 */ | 8 */ |
| 9 class _SocketBase { | 9 class _SocketBase { |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 /* | 35 /* |
| 36 * Multiplexes socket events to the right socket handler. | 36 * Multiplexes socket events to the right socket handler. |
| 37 */ | 37 */ |
| 38 void _multiplex(List<int> message) { | 38 void _multiplex(List<int> message) { |
| 39 assert(message.length == 1); | 39 assert(message.length == 1); |
| 40 _canActivateHandlers = false; | 40 _canActivateHandlers = false; |
| 41 int event_mask = message[0]; | 41 int event_mask = message[0]; |
| 42 for (int i = _FIRST_EVENT; i <= _LAST_EVENT; i++) { | 42 for (int i = _FIRST_EVENT; i <= _LAST_EVENT; i++) { |
| 43 if (((event_mask & (1 << i)) != 0) && _handlerMap[i] !== null) { | 43 if (((event_mask & (1 << i)) != 0) && _handlerMap[i] !== null) { |
| 44 var handleEvent = _handlerMap[i]; | 44 var handleEvent = _handlerMap[i]; |
| 45 /* | 45 |
| 46 * Unregister the out handler before executing it. | 46 // Unregister the out handler before executing it. |
| 47 */ | 47 if (i == _OUT_EVENT) _setHandler(i, null); |
| 48 if (i == _OUT_EVENT) { | 48 |
| 49 _setHandler(i, null); | 49 // Don't call the in handler if there is no data available |
| 50 } | 50 // after all. |
| 51 if (i == _IN_EVENT && this is _Socket && available() == 0) continue; |
| 52 |
| 51 handleEvent(); | 53 handleEvent(); |
| 52 } | 54 } |
| 53 } | 55 } |
| 54 _canActivateHandlers = true; | 56 _canActivateHandlers = true; |
| 55 _doActivateHandlers(); | 57 _doActivateHandlers(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 void _setHandler(int event, void callback()) { | 60 void _setHandler(int event, void callback()) { |
| 59 if (callback === null) { | 61 if (callback === null) { |
| 60 _handlerMask &= ~(1 << event); | 62 _handlerMask &= ~(1 << event); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 if (_outputStream == null) { | 289 if (_outputStream == null) { |
| 288 _outputStream = new SocketOutputStream(this); | 290 _outputStream = new SocketOutputStream(this); |
| 289 } | 291 } |
| 290 return _outputStream; | 292 return _outputStream; |
| 291 } | 293 } |
| 292 | 294 |
| 293 SocketInputStream _inputStream; | 295 SocketInputStream _inputStream; |
| 294 SocketOutputStream _outputStream; | 296 SocketOutputStream _outputStream; |
| 295 } | 297 } |
| 296 | 298 |
| OLD | NEW |