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

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

Issue 8386029: Consistently use setters to set event handlers in native APIs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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 | « runtime/bin/socket.dart ('k') | runtime/bin/socket_stream.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 _activateHandlers(); 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 set errorHandler(void callback()) {
80 _setHandler(_ERROR_EVENT, callback); 80 _setHandler(_ERROR_EVENT, callback);
81 } 81 }
82 82
83 void _activateHandlers() { 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 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 throw new 179 throw new
180 SocketIOException("Error: accept failed - invalid socket handle"); 180 SocketIOException("Error: accept failed - invalid socket handle");
181 } 181 }
182 182
183 bool _accept(Socket socket) native "ServerSocket_Accept"; 183 bool _accept(Socket socket) native "ServerSocket_Accept";
184 184
185 bool _createBindListen(String bindAddress, int port, int backlog) 185 bool _createBindListen(String bindAddress, int port, int backlog)
186 native "ServerSocket_CreateBindListen"; 186 native "ServerSocket_CreateBindListen";
187 187
188 void setConnectionHandler(void callback()) { 188 void set connectionHandler(void callback()) {
189 _setHandler(_IN_EVENT, callback); 189 _setHandler(_IN_EVENT, callback);
190 } 190 }
191 191
192 bool _isListenSocket() => true; 192 bool _isListenSocket() => true;
193 } 193 }
194 194
195 195
196 class _Socket extends _SocketBase implements Socket { 196 class _Socket extends _SocketBase implements Socket {
197 /* 197 /*
198 * Constructor for socket. First a socket object is allocated 198 * Constructor for socket. First a socket object is allocated
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 262 }
263 throw new 263 throw new
264 SocketIOException("Error: writeList failed - invalid socket handle"); 264 SocketIOException("Error: writeList failed - invalid socket handle");
265 } 265 }
266 266
267 int _writeList(List<int> buffer, int offset, int bytes) 267 int _writeList(List<int> buffer, int offset, int bytes)
268 native "Socket_WriteList"; 268 native "Socket_WriteList";
269 269
270 bool _createConnect(String host, int port) native "Socket_CreateConnect"; 270 bool _createConnect(String host, int port) native "Socket_CreateConnect";
271 271
272 void setWriteHandler(void callback()) { 272 void set writeHandler(void callback()) {
273 _setHandler(_OUT_EVENT, callback); 273 _setHandler(_OUT_EVENT, callback);
274 } 274 }
275 275
276 void setConnectHandler(void callback()) { 276 void set connectHandler(void callback()) {
277 _setHandler(_OUT_EVENT, callback); 277 _setHandler(_OUT_EVENT, callback);
278 } 278 }
279 279
280 void setDataHandler(void callback()) { 280 void set dataHandler(void callback()) {
281 _setHandler(_IN_EVENT, callback); 281 _setHandler(_IN_EVENT, callback);
282 } 282 }
283 283
284 void setCloseHandler(void callback()) { 284 void set closeHandler(void callback()) {
285 _setHandler(_CLOSE_EVENT, callback); 285 _setHandler(_CLOSE_EVENT, callback);
286 } 286 }
287 287
288 bool _isListenSocket() => false; 288 bool _isListenSocket() => false;
289 289
290 InputStream get inputStream() { 290 InputStream get inputStream() {
291 if (_inputStream === null) { 291 if (_inputStream === null) {
292 _inputStream = new SocketInputStream(this); 292 _inputStream = new SocketInputStream(this);
293 } 293 }
294 return _inputStream; 294 return _inputStream;
295 } 295 }
296 296
297 OutputStream get outputStream() { 297 OutputStream get outputStream() {
298 if (_outputStream === null) { 298 if (_outputStream === null) {
299 _outputStream = new SocketOutputStream(this); 299 _outputStream = new SocketOutputStream(this);
300 } 300 }
301 return _outputStream; 301 return _outputStream;
302 } 302 }
303 303
304 SocketInputStream _inputStream; 304 SocketInputStream _inputStream;
305 SocketOutputStream _outputStream; 305 SocketOutputStream _outputStream;
306 } 306 }
307 307
OLDNEW
« no previous file with comments | « runtime/bin/socket.dart ('k') | runtime/bin/socket_stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698