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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 2011, 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 #include <algorithm>
Anders Johnsen 2012/01/26 19:50:27 Is this okay?
6
5 #include "bin/socket.h" 7 #include "bin/socket.h"
6 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
7 9
8 #include "include/dart_api.h" 10 #include "include/dart_api.h"
9 11
10 12
11 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { 13 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) {
12 Dart_EnterScope(); 14 Dart_EnterScope();
13 Dart_Handle socketobj = Dart_GetNativeArgument(args, 0); 15 Dart_Handle socketobj = Dart_GetNativeArgument(args, 0);
14 const char* host = 16 const char* host =
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); 83 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
82 intptr_t buffer_len = 0; 84 intptr_t buffer_len = 0;
83 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); 85 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len);
84 ASSERT(!Dart_IsError(result)); 86 ASSERT(!Dart_IsError(result));
85 ASSERT((offset + length) <= buffer_len); 87 ASSERT((offset + length) <= buffer_len);
86 88
87 if (Dart_IsVMFlagSet("short_socket_write")) { 89 if (Dart_IsVMFlagSet("short_socket_write")) {
88 length = (length + 1) / 2; 90 length = (length + 1) / 2;
89 } 91 }
90 92
91 uint8_t* buffer = new uint8_t[length]; 93 // Send data in chunks of 16KB.
92 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); 94 const intptr_t max_chunk_length = 16384;
93 ASSERT(!Dart_IsError(result)); 95 uint8_t* buffer = new uint8_t[max_chunk_length];
94 intptr_t total_bytes_written = 96 intptr_t total_bytes_written = 0;
95 Socket::Write(socket, reinterpret_cast<void*>(buffer), length); 97 intptr_t bytes_written = 0;
98 do {
99 intptr_t chunk_length =
100 std::min(max_chunk_length, length - total_bytes_written);
101 result = Dart_ListGetAsBytes(buffer_obj,
102 offset + total_bytes_written,
103 buffer,
104 chunk_length);
105 ASSERT(!Dart_IsError(result));
106 bytes_written =
107 Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length);
108 total_bytes_written += bytes_written;
109 } while (bytes_written > 0 && total_bytes_written < length);
96 delete[] buffer; 110 delete[] buffer;
97 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); 111 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written));
98 Dart_ExitScope(); 112 Dart_ExitScope();
99 } 113 }
100 114
101 115
102 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { 116 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) {
103 Dart_EnterScope(); 117 Dart_EnterScope();
104 intptr_t socket = 118 intptr_t socket =
105 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), 119 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 DartUtils::kIdFieldName); 162 DartUtils::kIdFieldName);
149 Dart_Handle socketobj = Dart_GetNativeArgument(args, 1); 163 Dart_Handle socketobj = Dart_GetNativeArgument(args, 1);
150 intptr_t newSocket = ServerSocket::Accept(socket); 164 intptr_t newSocket = ServerSocket::Accept(socket);
151 if (newSocket >= 0) { 165 if (newSocket >= 0) {
152 DartUtils::SetIntegerInstanceField( 166 DartUtils::SetIntegerInstanceField(
153 socketobj, DartUtils::kIdFieldName, newSocket); 167 socketobj, DartUtils::kIdFieldName, newSocket);
154 } 168 }
155 Dart_SetReturnValue(args, Dart_NewBoolean(newSocket >= 0)); 169 Dart_SetReturnValue(args, Dart_NewBoolean(newSocket >= 0));
156 Dart_ExitScope(); 170 Dart_ExitScope();
157 } 171 }
OLDNEW
« 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