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

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

Issue 9254022: Make sure to use an ObjectArray when writing to a socket (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Really address the review comments from ager@ Created 8 years, 11 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) 2011, 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
11 // EVENT flags indicate the events that actually happened. The 11 // EVENT flags indicate the events that actually happened. The
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 315 }
316 if (offset < 0) { 316 if (offset < 0) {
317 throw new IndexOutOfRangeException(offset); 317 throw new IndexOutOfRangeException(offset);
318 } 318 }
319 if (bytes < 0) { 319 if (bytes < 0) {
320 throw new IndexOutOfRangeException(bytes); 320 throw new IndexOutOfRangeException(bytes);
321 } 321 }
322 if ((offset + bytes) > buffer.length) { 322 if ((offset + bytes) > buffer.length) {
323 throw new IndexOutOfRangeException(offset + bytes); 323 throw new IndexOutOfRangeException(offset + bytes);
324 } 324 }
325 var bytes_written = _writeList(buffer, offset, bytes); 325 // When using the Dart C API access to ObjectArray by index is
326 // currently much faster. This function will make a copy of the
327 // supplied List to an ObjectArray if it isn't already.
328 ObjectArray outBuffer;
329 int outOffset = offset;
330 if (buffer is ObjectArray) {
331 outBuffer = buffer;
332 } else {
333 outBuffer = new ObjectArray(bytes);
334 outOffset = 0;
335 int j = offset;
336 for (int i = 0; i < bytes; i++) {
337 outBuffer[i] = buffer[j];
338 j++;
339 }
340 }
341 var bytes_written = _writeList(outBuffer, outOffset, bytes);
326 if (bytes_written < 0) { 342 if (bytes_written < 0) {
327 // If writing fails we return 0 as the number of bytes and 343 // If writing fails we return 0 as the number of bytes and
328 // report the error on the error handler. 344 // report the error on the error handler.
329 bytes_written = 0; 345 bytes_written = 0;
330 _reportError(); 346 _reportError();
331 } 347 }
332 return bytes_written; 348 return bytes_written;
333 } 349 }
334 throw new 350 throw new
335 SocketIOException("Error: writeList failed - invalid socket handle"); 351 SocketIOException("Error: writeList failed - invalid socket handle");
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 bool _seenFirstOutEvent = false; 471 bool _seenFirstOutEvent = false;
456 bool _closedRead = false; 472 bool _closedRead = false;
457 bool _closedWrite = false; 473 bool _closedWrite = false;
458 bool _pipe = false; 474 bool _pipe = false;
459 Function _clientConnectHandler; 475 Function _clientConnectHandler;
460 Function _clientWriteHandler; 476 Function _clientWriteHandler;
461 SocketInputStream _inputStream; 477 SocketInputStream _inputStream;
462 SocketOutputStream _outputStream; 478 SocketOutputStream _outputStream;
463 } 479 }
464 480
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