OLD | NEW |
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 extends NativeFieldWrapperClass1 { | 6 class _SocketBase extends NativeFieldWrapperClass1 { |
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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 362 } |
363 | 363 |
364 _available() native "Socket_Available"; | 364 _available() native "Socket_Available"; |
365 | 365 |
366 int readList(List<int> buffer, int offset, int bytes) { | 366 int readList(List<int> buffer, int offset, int bytes) { |
367 if (!_closed) { | 367 if (!_closed) { |
368 if (bytes == 0) { | 368 if (bytes == 0) { |
369 return 0; | 369 return 0; |
370 } | 370 } |
371 if (offset < 0) { | 371 if (offset < 0) { |
372 throw new IndexOutOfRangeException(offset); | 372 throw new RangeError(offset); |
373 } | 373 } |
374 if (bytes < 0) { | 374 if (bytes < 0) { |
375 throw new IndexOutOfRangeException(bytes); | 375 throw new RangeError(bytes); |
376 } | 376 } |
377 if ((offset + bytes) > buffer.length) { | 377 if ((offset + bytes) > buffer.length) { |
378 throw new IndexOutOfRangeException(offset + bytes); | 378 throw new RangeError(offset + bytes); |
379 } | 379 } |
380 var result = _readList(buffer, offset, bytes); | 380 var result = _readList(buffer, offset, bytes); |
381 if (result is OSError) { | 381 if (result is OSError) { |
382 _reportError(result, "Read failed"); | 382 _reportError(result, "Read failed"); |
383 return -1; | 383 return -1; |
384 } | 384 } |
385 return result; | 385 return result; |
386 } | 386 } |
387 throw new | 387 throw new |
388 SocketIOException("Error: readList failed - invalid socket handle"); | 388 SocketIOException("Error: readList failed - invalid socket handle"); |
389 } | 389 } |
390 | 390 |
391 _readList(List<int> buffer, int offset, int bytes) native "Socket_ReadList"; | 391 _readList(List<int> buffer, int offset, int bytes) native "Socket_ReadList"; |
392 | 392 |
393 int writeList(List<int> buffer, int offset, int bytes) { | 393 int writeList(List<int> buffer, int offset, int bytes) { |
394 if (buffer is! List || offset is! int || bytes is! int) { | 394 if (buffer is! List || offset is! int || bytes is! int) { |
395 throw new ArgumentError( | 395 throw new ArgumentError( |
396 "Invalid arguments to writeList on Socket"); | 396 "Invalid arguments to writeList on Socket"); |
397 } | 397 } |
398 if (!_closed) { | 398 if (!_closed) { |
399 if (bytes == 0) { | 399 if (bytes == 0) { |
400 return 0; | 400 return 0; |
401 } | 401 } |
402 if (offset < 0) { | 402 if (offset < 0) { |
403 throw new IndexOutOfRangeException(offset); | 403 throw new RangeError(offset); |
404 } | 404 } |
405 if (bytes < 0) { | 405 if (bytes < 0) { |
406 throw new IndexOutOfRangeException(bytes); | 406 throw new RangeError(bytes); |
407 } | 407 } |
408 if ((offset + bytes) > buffer.length) { | 408 if ((offset + bytes) > buffer.length) { |
409 throw new IndexOutOfRangeException(offset + bytes); | 409 throw new RangeError(offset + bytes); |
410 } | 410 } |
411 _BufferAndOffset bufferAndOffset = | 411 _BufferAndOffset bufferAndOffset = |
412 _ensureFastAndSerializableBuffer(buffer, offset, bytes); | 412 _ensureFastAndSerializableBuffer(buffer, offset, bytes); |
413 var result = | 413 var result = |
414 _writeList(bufferAndOffset.buffer, bufferAndOffset.offset, bytes); | 414 _writeList(bufferAndOffset.buffer, bufferAndOffset.offset, bytes); |
415 if (result is OSError) { | 415 if (result is OSError) { |
416 _reportError(result, "Write failed"); | 416 _reportError(result, "Write failed"); |
417 // If writing fails we return 0 as the number of bytes and | 417 // If writing fails we return 0 as the number of bytes and |
418 // report the error on the error handler. | 418 // report the error on the error handler. |
419 result = 0; | 419 result = 0; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 bool _seenFirstOutEvent = false; | 573 bool _seenFirstOutEvent = false; |
574 bool _pipe = false; | 574 bool _pipe = false; |
575 Function _clientConnectHandler; | 575 Function _clientConnectHandler; |
576 Function _clientWriteHandler; | 576 Function _clientWriteHandler; |
577 SocketInputStream _inputStream; | 577 SocketInputStream _inputStream; |
578 SocketOutputStream _outputStream; | 578 SocketOutputStream _outputStream; |
579 String _remoteHost; | 579 String _remoteHost; |
580 int _remotePort; | 580 int _remotePort; |
581 static SendPort _socketService; | 581 static SendPort _socketService; |
582 } | 582 } |
OLD | NEW |