Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Side by Side Diff: runtime/bin/socket_impl.dart

Issue 9382001: Another attempt at fixing the Socket tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/socket_stream_impl.dart » ('j') | runtime/bin/socket_stream_impl.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 if (_closedWrite) _close(); 51 if (_closedWrite) _close();
52 } 52 }
53 53
54 var eventHandler = _handlerMap[i]; 54 var eventHandler = _handlerMap[i];
55 if (eventHandler != null) { 55 if (eventHandler != null) {
56 // Unregister the out handler before executing it. 56 // Unregister the out handler before executing it.
57 if (i == _OUT_EVENT) _setHandler(i, null); 57 if (i == _OUT_EVENT) _setHandler(i, null);
58 58
59 // Don't call the in handler if there is no data available 59 // Don't call the in handler if there is no data available
60 // after all. 60 // after all.
61 if (i == _IN_EVENT && this is _Socket && available() == 0) { 61 if ((i == _IN_EVENT) && (this is _Socket) && (available() == 0)) {
62 continue; 62 continue;
63 } 63 }
64 eventHandler(); 64 eventHandler();
65 } 65 }
66 } 66 }
67 } 67 }
68 _canActivateHandlers = true; 68 _canActivateHandlers = true;
69 _activateHandlers(); 69 _activateHandlers();
70 } 70 }
71 71
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 } else if (_handler != null) { 126 } else if (_handler != null) {
127 // This is to support closing sockets created but never assigned 127 // This is to support closing sockets created but never assigned
128 // any actual socket. 128 // any actual socket.
129 _handler.close(); 129 _handler.close();
130 _handler = null; 130 _handler = null;
131 } 131 }
132 } 132 }
133 133
134 void _closeWrite() { 134 void _closeWrite() {
135 if (_closedRead) { 135 if (_id >= 0) {
136 _close(); 136 if (_closedRead) {
137 } else { 137 _close();
138 _sendToEventHandler(1 << _SHUTDOWN_WRITE_COMMAND); 138 } else {
139 _sendToEventHandler(1 << _SHUTDOWN_WRITE_COMMAND);
140 }
141 _closedWrite = true;
139 } 142 }
140 _closedWrite = true;
141 } 143 }
142 144
143 void _closeRead() { 145 void _closeRead() {
144 if (_closedWrite) { 146 if (_id >= 0) {
145 _close(); 147 if (_closedWrite) {
146 } else { 148 _close();
147 _sendToEventHandler(1 << _SHUTDOWN_READ_COMMAND); 149 } else {
150 _sendToEventHandler(1 << _SHUTDOWN_READ_COMMAND);
151 }
152 _closedRead = true;
148 } 153 }
149 _closedRead = true;
150 } 154 }
151 155
152 void _close() { 156 void _close() {
153 _sendToEventHandler(1 << _CLOSE_COMMAND); 157 if (_id >= 0) {
154 _handler.close(); 158 _sendToEventHandler(1 << _CLOSE_COMMAND);
155 _handler = null; 159 _handler.close();
156 _id = -1; 160 _handler = null;
161 _id = -1;
162 }
157 } 163 }
158 164
159 void _sendToEventHandler(int data) { 165 void _sendToEventHandler(int data) {
160 if (_handler === null) { 166 if (_handler === null) {
161 _handler = new ReceivePort(); 167 _handler = new ReceivePort();
162 _handler.receive((var message, ignored) { _multiplex(message); }); 168 _handler.receive((var message, ignored) { _multiplex(message); });
163 } 169 }
170 assert(_id >= 0);
164 _EventHandler._sendData(_id, _handler, data); 171 _EventHandler._sendData(_id, _handler, data);
165 } 172 }
166 173
167 abstract bool _isListenSocket(); 174 abstract bool _isListenSocket();
168 abstract bool _isPipe(); 175 abstract bool _isPipe();
169 176
170 // Socket id is set from native. -1 indicates that the socket was closed. 177 // Socket id is set from native. -1 indicates that the socket was closed.
171 int _id; 178 int _id;
172 179
173 // Dedicated ReceivePort for socket events. 180 // Dedicated ReceivePort for socket events.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 382 }
376 383
377 void set dataHandler(void callback()) { 384 void set dataHandler(void callback()) {
378 if (_inputStream != null) throw new StreamException( 385 if (_inputStream != null) throw new StreamException(
379 "Cannot set data handler when input stream is used"); 386 "Cannot set data handler when input stream is used");
380 _dataHandler = callback; 387 _dataHandler = callback;
381 } 388 }
382 389
383 void set closeHandler(void callback()) { 390 void set closeHandler(void callback()) {
384 if (_inputStream != null) throw new StreamException( 391 if (_inputStream != null) throw new StreamException(
385 "Cannot set data handler when input stream is used"); 392 "Cannot set close handler when input stream is used");
386 _closeHandler = callback; 393 _closeHandler = callback;
387 } 394 }
388 395
389 bool _isListenSocket() => false; 396 bool _isListenSocket() => false;
390 397
391 bool _isPipe() => _pipe; 398 bool _isPipe() => _pipe;
392 399
393 InputStream get inputStream() { 400 InputStream get inputStream() {
394 if (_inputStream === null) { 401 if (_inputStream === null) {
395 if (_handlerMap[_IN_EVENT] !== null || 402 if (_handlerMap[_IN_EVENT] !== null ||
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 bool _seenFirstOutEvent = false; 465 bool _seenFirstOutEvent = false;
459 bool _closedRead = false; 466 bool _closedRead = false;
460 bool _closedWrite = false; 467 bool _closedWrite = false;
461 bool _pipe = false; 468 bool _pipe = false;
462 Function _clientConnectHandler; 469 Function _clientConnectHandler;
463 Function _clientWriteHandler; 470 Function _clientWriteHandler;
464 SocketInputStream _inputStream; 471 SocketInputStream _inputStream;
465 SocketOutputStream _outputStream; 472 SocketOutputStream _outputStream;
466 } 473 }
467 474
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/socket_stream_impl.dart » ('j') | runtime/bin/socket_stream_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698