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

Side by Side Diff: runtime/bin/socket.cc

Issue 18608005: Remove old code for dealing with non-typed buffers in Socket.write. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "bin/io_buffer.h" 5 #include "bin/io_buffer.h"
6 #include "bin/socket.h" 6 #include "bin/socket.h"
7 #include "bin/dartutils.h" 7 #include "bin/dartutils.h"
8 #include "bin/thread.h" 8 #include "bin/thread.h"
9 #include "bin/utils.h" 9 #include "bin/utils.h"
10 10
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 192 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
193 intptr_t socket = 0; 193 intptr_t socket = 0;
194 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket); 194 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
195 if (Dart_IsError(err)) Dart_PropagateError(err); 195 if (Dart_IsError(err)) Dart_PropagateError(err);
196 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); 196 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
197 ASSERT(Dart_IsList(buffer_obj)); 197 ASSERT(Dart_IsList(buffer_obj));
198 intptr_t offset = 198 intptr_t offset =
199 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 199 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
200 intptr_t length = 200 intptr_t length =
201 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); 201 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
202 intptr_t buffer_len = 0;
203 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len);
204 if (Dart_IsError(result)) {
205 Dart_PropagateError(result);
206 }
207 ASSERT((offset + length) <= buffer_len);
208
209 if (short_socket_writes) { 202 if (short_socket_writes) {
210 length = (length + 1) / 2; 203 length = (length + 1) / 2;
211 } 204 }
212
213 intptr_t total_bytes_written = 0;
214 intptr_t bytes_written = 0;
215 Dart_TypedData_Type type; 205 Dart_TypedData_Type type;
216 uint8_t* buffer = NULL; 206 uint8_t* buffer = NULL;
217 intptr_t len; 207 intptr_t len;
218 result = Dart_TypedDataAcquireData(buffer_obj, &type, 208 Dart_Handle result = Dart_TypedDataAcquireData(
219 reinterpret_cast<void**>(&buffer), &len); 209 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len);
220 if (!Dart_IsError(result)) { 210 if (Dart_IsError(result)) Dart_PropagateError(result);
221 buffer += offset; 211 ASSERT((offset + length) <= len);
222 bytes_written = Socket::Write(socket, buffer, length); 212 buffer += offset;
223 if (bytes_written >= 0) { 213 intptr_t bytes_written = Socket::Write(socket, buffer, length);
224 total_bytes_written = bytes_written; 214 if (bytes_written >= 0) {
225 Dart_TypedDataReleaseData(buffer_obj); 215 Dart_TypedDataReleaseData(buffer_obj);
226 } else { 216 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written));
227 // Extract OSError before we release data, as it may override the error.
228 OSError os_error;
229 Dart_TypedDataReleaseData(buffer_obj);
230 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
231 }
232 } else { 217 } else {
233 // Send data in chunks of maximum 16KB. 218 // Extract OSError before we release data, as it may override the error.
234 const intptr_t max_chunk_length = 219 OSError os_error;
235 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); 220 Dart_TypedDataReleaseData(buffer_obj);
236 buffer = new uint8_t[max_chunk_length]; 221 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
237 do {
238 intptr_t chunk_length =
239 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written);
240 result = Dart_ListGetAsBytes(buffer_obj,
241 offset + total_bytes_written,
242 buffer,
243 chunk_length);
244 if (Dart_IsError(result)) {
245 delete[] buffer;
246 Dart_PropagateError(result);
247 }
248 bytes_written =
249 Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length);
250 if (bytes_written >= 0) {
251 total_bytes_written += bytes_written;
252 } else {
253 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
254 }
255 } while (bytes_written > 0 && total_bytes_written < length);
256 delete[] buffer;
257 }
258 if (bytes_written >= 0) {
259 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written));
260 } 222 }
261 Dart_ExitScope(); 223 Dart_ExitScope();
262 } 224 }
263 225
264 226
265 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { 227 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) {
266 Dart_EnterScope(); 228 Dart_EnterScope();
267 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 229 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
268 intptr_t socket = 0; 230 intptr_t socket = 0;
269 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket); 231 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); 589 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id);
628 } 590 }
629 591
630 592
631 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { 593 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) {
632 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); 594 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id);
633 } 595 }
634 596
635 } // namespace bin 597 } // namespace bin
636 } // namespace dart 598 } // namespace dart
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