| 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 class _SocketBase { | 6 class _SocketBase { |
| 7 // Bit flags used when communicating between the eventhandler and | 7 // Bit flags used when communicating between the eventhandler and |
| 8 // dart code. The EVENT flags are used to indicate events of | 8 // dart code. The EVENT flags are used to indicate events of |
| 9 // interest when sending a message from dart code to the | 9 // interest when sending a message from dart code to the |
| 10 // eventhandler. When receiving a message from the eventhandler the | 10 // eventhandler. When receiving a message from the eventhandler the |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 | 41 |
| 42 /* | 42 /* |
| 43 * Multiplexes socket events to the right socket handler. | 43 * Multiplexes socket events to the right socket handler. |
| 44 */ | 44 */ |
| 45 void _multiplex(List<int> message) { | 45 void _multiplex(List<int> message) { |
| 46 assert(message.length == 1); | 46 assert(message.length == 1); |
| 47 _canActivateHandlers = false; | 47 _canActivateHandlers = false; |
| 48 int event_mask = message[0]; | 48 int event_mask = message[0]; |
| 49 for (int i = _FIRST_EVENT; i <= _LAST_EVENT; i++) { | 49 for (int i = _FIRST_EVENT; i <= _LAST_EVENT; i++) { |
| 50 if (((event_mask & (1 << i)) != 0) && _handlerMap[i] !== null) { | 50 if (((event_mask & (1 << i)) != 0) && _handlerMap[i] != null) { |
| 51 var handleEvent = _handlerMap[i]; | 51 var handleEvent = _handlerMap[i]; |
| 52 | 52 |
| 53 // Unregister the out handler before executing it. | 53 // Unregister the out handler before executing it. |
| 54 if (i == _OUT_EVENT) _setHandler(i, null); | 54 if (i == _OUT_EVENT) _setHandler(i, null); |
| 55 | 55 |
| 56 // Don't call the in handler if there is no data available | 56 // Don't call the in handler if there is no data available |
| 57 // after all. | 57 // after all. |
| 58 if (i == _IN_EVENT && this is _Socket && available() == 0) continue; | 58 if (i == _IN_EVENT && this is _Socket && available() == 0) continue; |
| 59 | 59 |
| 60 handleEvent(); | 60 handleEvent(); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 _canActivateHandlers = true; | 63 _canActivateHandlers = true; |
| 64 _doActivateHandlers(); | 64 _activateHandlers(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void _setHandler(int event, void callback()) { | 67 void _setHandler(int event, void callback()) { |
| 68 if (callback === null) { | 68 if (callback == null) { |
| 69 _handlerMask &= ~(1 << event); | 69 _handlerMask &= ~(1 << event); |
| 70 } else { | 70 } else { |
| 71 _handlerMask |= (1 << event); | 71 _handlerMask |= (1 << event); |
| 72 } | 72 } |
| 73 _handlerMap[event] = callback; | 73 _handlerMap[event] = callback; |
| 74 _doActivateHandlers(); | 74 _activateHandlers(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void _getPort() native "Socket_GetPort"; | 77 void _getPort() native "Socket_GetPort"; |
| 78 | 78 |
| 79 void setErrorHandler(void callback()) { | 79 void setErrorHandler(void callback()) { |
| 80 _setHandler(_ERROR_EVENT, callback); | 80 _setHandler(_ERROR_EVENT, callback); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void _doActivateHandlers() { | 83 void _activateHandlers() { |
| 84 if (_canActivateHandlers && (_id >= 0)) { | 84 if (_canActivateHandlers && (_id >= 0)) { |
| 85 int data = _handlerMask; | 85 int data = _handlerMask; |
| 86 if (_isListenSocket()) data |= (1 << _LISTENING_SOCKET); | 86 if (_isListenSocket()) data |= (1 << _LISTENING_SOCKET); |
| 87 EventHandler._sendData(_id, _handler, data); | 87 EventHandler._sendData(_id, _handler, data); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 void _scheduleEvent(int event) { | 91 void _scheduleEvent(int event) { |
| 92 _handler.toSendPort().send([1 << event], null); | 92 _handler.toSendPort().send([1 << event], null); |
| 93 } | 93 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 if (_outputStream === null) { | 303 if (_outputStream === null) { |
| 304 _outputStream = new SocketOutputStream(this); | 304 _outputStream = new SocketOutputStream(this); |
| 305 } | 305 } |
| 306 return _outputStream; | 306 return _outputStream; |
| 307 } | 307 } |
| 308 | 308 |
| 309 SocketInputStream _inputStream; | 309 SocketInputStream _inputStream; |
| 310 SocketOutputStream _outputStream; | 310 SocketOutputStream _outputStream; |
| 311 } | 311 } |
| 312 | 312 |
| OLD | NEW |