Chromium Code Reviews| Index: runtime/bin/socket.cc |
| =================================================================== |
| --- runtime/bin/socket.cc (revision 3621) |
| +++ runtime/bin/socket.cc (working copy) |
| @@ -2,6 +2,8 @@ |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| +#include <algorithm> |
|
Anders Johnsen
2012/01/26 19:50:27
Is this okay?
|
| + |
| #include "bin/socket.h" |
| #include "bin/dartutils.h" |
| @@ -88,11 +90,23 @@ |
| length = (length + 1) / 2; |
| } |
| - uint8_t* buffer = new uint8_t[length]; |
| - result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); |
| - ASSERT(!Dart_IsError(result)); |
| - intptr_t total_bytes_written = |
| - Socket::Write(socket, reinterpret_cast<void*>(buffer), length); |
| + // Send data in chunks of 16KB. |
| + const intptr_t max_chunk_length = 16384; |
| + uint8_t* buffer = new uint8_t[max_chunk_length]; |
| + intptr_t total_bytes_written = 0; |
| + intptr_t bytes_written = 0; |
| + do { |
| + intptr_t chunk_length = |
| + std::min(max_chunk_length, length - total_bytes_written); |
| + result = Dart_ListGetAsBytes(buffer_obj, |
| + offset + total_bytes_written, |
| + buffer, |
| + chunk_length); |
| + ASSERT(!Dart_IsError(result)); |
| + bytes_written = |
| + Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length); |
| + total_bytes_written += bytes_written; |
| + } while (bytes_written > 0 && total_bytes_written < length); |
| delete[] buffer; |
| Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); |
| Dart_ExitScope(); |