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

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

Issue 9703023: Fix some minor static type issues in dart:io implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 9 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
« runtime/bin/file_impl.dart ('K') | « runtime/bin/process_impl.dart ('k') | no next file » | 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) 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 _closedRead && 84 _closedRead &&
85 _handlerMask == 0 && 85 _handlerMask == 0 &&
86 _handler != null) { 86 _handler != null) {
87 _handler.close(); 87 _handler.close();
88 _handler = null; 88 _handler = null;
89 } else { 89 } else {
90 _activateHandlers(); 90 _activateHandlers();
91 } 91 }
92 } 92 }
93 93
94 void _getPort() native "Socket_GetPort"; 94 int _getPort() native "Socket_GetPort";
95 95
96 void set onError(void callback()) { 96 void set onError(void callback()) {
97 _setHandler(_ERROR_EVENT, callback); 97 _setHandler(_ERROR_EVENT, callback);
98 } 98 }
99 99
100 void _activateHandlers() { 100 void _activateHandlers() {
101 if (_canActivateHandlers && (_id >= 0)) { 101 if (_canActivateHandlers && (_id >= 0)) {
102 if (_handlerMask == 0) { 102 if (_handlerMask == 0) {
103 if (_handler != null) { 103 if (_handler != null) {
104 _handler.close(); 104 _handler.close();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 // Indicates if native interrupts can be activated. 200 // Indicates if native interrupts can be activated.
201 bool _canActivateHandlers; 201 bool _canActivateHandlers;
202 202
203 // Holds the port of the socket, null if not known. 203 // Holds the port of the socket, null if not known.
204 int _port; 204 int _port;
205 205
206 // Hash code for the socket. Currently this is just a counter. 206 // Hash code for the socket. Currently this is just a counter.
207 int _hashCode; 207 int _hashCode;
208 static int _nextHashCode = 0; 208 static int _nextHashCode = 0;
209 bool _closedRead = false;
210 bool _closedWrite = false;
209 } 211 }
210 212
211 213
212 class _ServerSocket extends _SocketBase implements ServerSocket { 214 class _ServerSocket extends _SocketBase implements ServerSocket {
213 // Constructor for server socket. First a socket object is allocated 215 // Constructor for server socket. First a socket object is allocated
214 // in which the native socket is stored. After that _createBind 216 // in which the native socket is stored. After that _createBind
215 // is called which creates a file descriptor and binds the given address 217 // is called which creates a file descriptor and binds the given address
216 // and port to the socket. Null is returned if file descriptor creation or 218 // and port to the socket. Null is returned if file descriptor creation or
217 // bind failed. 219 // bind failed.
218 factory _ServerSocket(String bindAddress, int port, int backlog) { 220 factory _ServerSocket(String bindAddress, int port, int backlog) {
219 ServerSocket socket = new _ServerSocket._internal(); 221 _ServerSocket socket = new _ServerSocket._internal();
220 if (!socket._createBindListen(bindAddress, port, backlog)) { 222 if (!socket._createBindListen(bindAddress, port, backlog)) {
221 socket.close(); 223 socket.close();
222 return null; 224 return null;
223 } 225 }
224 if (port != 0) { 226 if (port != 0) {
225 socket._port = port; 227 socket._port = port;
226 } 228 }
227 return socket; 229 return socket;
228 } 230 }
229 231
(...skipping 24 matching lines...) Expand all
254 } 256 }
255 257
256 258
257 class _Socket extends _SocketBase implements Socket { 259 class _Socket extends _SocketBase implements Socket {
258 // Constructor for socket. First a socket object is allocated 260 // Constructor for socket. First a socket object is allocated
259 // in which the native socket is stored. After that _createConnect is 261 // in which the native socket is stored. After that _createConnect is
260 // called which creates a file discriptor and connects to the given 262 // called which creates a file discriptor and connects to the given
261 // host on the given port. Null is returned if file descriptor creation 263 // host on the given port. Null is returned if file descriptor creation
262 // or connect failed. 264 // or connect failed.
263 factory _Socket(String host, int port) { 265 factory _Socket(String host, int port) {
264 Socket socket = new _Socket._internal(); 266 _Socket socket = new _Socket._internal();
265 if (!socket._createConnect(host, port)) { 267 if (!socket._createConnect(host, port)) {
266 socket.close(); 268 socket.close();
267 return null; 269 return null;
268 } 270 }
269 return socket; 271 return socket;
270 } 272 }
271 273
272 _Socket._internal(); 274 _Socket._internal();
273 _Socket._internalReadOnly() : _closedWrite = true, _pipe = true; 275 _Socket._internalReadOnly() : _pipe = true { super._closedWrite = true; }
274 _Socket._internalWriteOnly() : _closedRead = true, _pipe = true; 276 _Socket._internalWriteOnly() : _pipe = true { super._closedRead = true; }
275 277
276 int available() { 278 int available() {
277 if (_id >= 0) { 279 if (_id >= 0) {
278 return _available(); 280 return _available();
279 } 281 }
280 throw new 282 throw new
281 SocketIOException("Error: available failed - invalid socket handle"); 283 SocketIOException("Error: available failed - invalid socket handle");
282 } 284 }
283 285
284 int _available() native "Socket_Available"; 286 int _available() native "Socket_Available";
285 287
286 bool get closed() => _closed;
287
288 int readList(List<int> buffer, int offset, int bytes) { 288 int readList(List<int> buffer, int offset, int bytes) {
289 if (_id >= 0) { 289 if (_id >= 0) {
290 if (bytes == 0) { 290 if (bytes == 0) {
291 return 0; 291 return 0;
292 } 292 }
293 if (offset < 0) { 293 if (offset < 0) {
294 throw new IndexOutOfRangeException(offset); 294 throw new IndexOutOfRangeException(offset);
295 } 295 }
296 if (bytes < 0) { 296 if (bytes < 0) {
297 throw new IndexOutOfRangeException(bytes); 297 throw new IndexOutOfRangeException(bytes);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } else { 471 } else {
472 if (_seenFirstOutEvent) { 472 if (_seenFirstOutEvent) {
473 _onWrite = _clientWriteHandler; 473 _onWrite = _clientWriteHandler;
474 } else { 474 } else {
475 _onWrite = firstWriteHandler; 475 _onWrite = firstWriteHandler;
476 } 476 }
477 } 477 }
478 } 478 }
479 479
480 bool _seenFirstOutEvent = false; 480 bool _seenFirstOutEvent = false;
481 bool _closedRead = false;
482 bool _closedWrite = false;
483 bool _pipe = false; 481 bool _pipe = false;
484 Function _clientConnectHandler; 482 Function _clientConnectHandler;
485 Function _clientWriteHandler; 483 Function _clientWriteHandler;
486 SocketInputStream _inputStream; 484 SocketInputStream _inputStream;
487 SocketOutputStream _outputStream; 485 SocketOutputStream _outputStream;
488 } 486 }
489 487
OLDNEW
« runtime/bin/file_impl.dart ('K') | « runtime/bin/process_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698