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

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

Issue 11023003: Clean up file implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 8 years, 2 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 | « runtime/bin/file_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 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 201
202 // For all errors we close the socket, call the error handler and 202 // For all errors we close the socket, call the error handler and
203 // disable further calls of the error handler. 203 // disable further calls of the error handler.
204 close(); 204 close();
205 if (error is OSError) { 205 if (error is OSError) {
206 doReportError(new SocketIOException(message, error)); 206 doReportError(new SocketIOException(message, error));
207 } else if (error is List) { 207 } else if (error is List) {
208 assert(_isErrorResponse(error)); 208 assert(_isErrorResponse(error));
209 switch (error[0]) { 209 switch (error[0]) {
210 case _FileUtils.ILLEGAL_ARGUMENT_RESPONSE: 210 case _ILLEGAL_ARGUMENT_RESPONSE:
211 doReportError(new ArgumentError()); 211 doReportError(new ArgumentError());
212 break; 212 break;
213 case _FileUtils.OSERROR_RESPONSE: 213 case _OSERROR_RESPONSE:
214 doReportError(new SocketIOException( 214 doReportError(new SocketIOException(
215 message, new OSError(error[2], error[1]))); 215 message, new OSError(error[2], error[1])));
216 break; 216 break;
217 default: 217 default:
218 doReportError(new Exception("Unknown error")); 218 doReportError(new Exception("Unknown error"));
219 break; 219 break;
220 } 220 }
221 } else { 221 } else {
222 doReportError(new SocketIOException(message)); 222 doReportError(new SocketIOException(message));
223 } 223 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 401 }
402 if (offset < 0) { 402 if (offset < 0) {
403 throw new IndexOutOfRangeException(offset); 403 throw new IndexOutOfRangeException(offset);
404 } 404 }
405 if (bytes < 0) { 405 if (bytes < 0) {
406 throw new IndexOutOfRangeException(bytes); 406 throw new IndexOutOfRangeException(bytes);
407 } 407 }
408 if ((offset + bytes) > buffer.length) { 408 if ((offset + bytes) > buffer.length) {
409 throw new IndexOutOfRangeException(offset + bytes); 409 throw new IndexOutOfRangeException(offset + bytes);
410 } 410 }
411 var fastBuffer = _ensureFastAndSerializableBuffer(buffer, offset, bytes); 411 _BufferAndOffset bufferAndOffset =
412 var result = _writeList(fastBuffer[0], fastBuffer[1], bytes); 412 _ensureFastAndSerializableBuffer(buffer, offset, bytes);
413 var result =
414 _writeList(bufferAndOffset.buffer, bufferAndOffset.offset, bytes);
413 if (result is OSError) { 415 if (result is OSError) {
414 _reportError(result, "Write failed"); 416 _reportError(result, "Write failed");
415 // 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
416 // report the error on the error handler. 418 // report the error on the error handler.
417 result = 0; 419 result = 0;
418 } 420 }
419 return result; 421 return result;
420 } 422 }
421 throw new SocketIOException("writeList failed - invalid socket handle"); 423 throw new SocketIOException("writeList failed - invalid socket handle");
422 } 424 }
423 425
424 _writeList(List<int> buffer, int offset, int bytes) 426 _writeList(List<int> buffer, int offset, int bytes)
425 native "Socket_WriteList"; 427 native "Socket_WriteList";
426 428
427 bool _isErrorResponse(response) { 429 bool _isErrorResponse(response) {
428 return response is List && response[0] != _FileUtils.SUCCESS_RESPONSE; 430 return response is List && response[0] != _SUCCESS_RESPONSE;
429 } 431 }
430 432
431 bool _createConnect(String host, int port) native "Socket_CreateConnect"; 433 bool _createConnect(String host, int port) native "Socket_CreateConnect";
432 434
433 void set onWrite(void callback()) { 435 void set onWrite(void callback()) {
434 if (_outputStream != null) throw new StreamException( 436 if (_outputStream != null) throw new StreamException(
435 "Cannot set write handler when output stream is used"); 437 "Cannot set write handler when output stream is used");
436 _clientWriteHandler = callback; 438 _clientWriteHandler = callback;
437 _updateOutHandler(); 439 _updateOutHandler();
438 } 440 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 bool _seenFirstOutEvent = false; 573 bool _seenFirstOutEvent = false;
572 bool _pipe = false; 574 bool _pipe = false;
573 Function _clientConnectHandler; 575 Function _clientConnectHandler;
574 Function _clientWriteHandler; 576 Function _clientWriteHandler;
575 SocketInputStream _inputStream; 577 SocketInputStream _inputStream;
576 SocketOutputStream _outputStream; 578 SocketOutputStream _outputStream;
577 String _remoteHost; 579 String _remoteHost;
578 int _remotePort; 580 int _remotePort;
579 static SendPort _socketService; 581 static SendPort _socketService;
580 } 582 }
OLDNEW
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698