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

Unified Diff: runtime/bin/socket.cc

Issue 9220008: Send data in chunks when writing to socket. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698