| Index: runtime/bin/socket.cc
|
| ===================================================================
|
| --- runtime/bin/socket.cc (revision 3621)
|
| +++ runtime/bin/socket.cc (working copy)
|
| @@ -5,6 +5,8 @@
|
| #include "bin/socket.h"
|
| #include "bin/dartutils.h"
|
|
|
| +#include "platform/utils.h"
|
| +
|
| #include "include/dart_api.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 maximum 16KB.
|
| + const intptr_t max_chunk_length = dart::Utils::Minimum(length, 16 * KB);
|
| + 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 =
|
| + dart::Utils::Minimum(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();
|
|
|