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

Side by Side Diff: bin/socket.cc

Issue 12255018: Add typed data interface to Dart API, this only changes the C++ API as dicussed in a previous email… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 10 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
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 Dart_PropagateError(result); 173 Dart_PropagateError(result);
174 } 174 }
175 ASSERT((offset + length) <= buffer_len); 175 ASSERT((offset + length) <= buffer_len);
176 176
177 if (short_socket_writes) { 177 if (short_socket_writes) {
178 length = (length + 1) / 2; 178 length = (length + 1) / 2;
179 } 179 }
180 180
181 intptr_t total_bytes_written = 0; 181 intptr_t total_bytes_written = 0;
182 intptr_t bytes_written = 0; 182 intptr_t bytes_written = 0;
183 if (Dart_IsByteArrayExternal(buffer_obj)) { 183 if (Dart_IsExternalTypedData(buffer_obj) != kInvalid) {
184 Dart_TypedData_Type type;
184 void* buffer = NULL; 185 void* buffer = NULL;
185 result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer); 186 intptr_t len;
187 result = Dart_TypedDataAcquireData(buffer_obj, &type, &buffer, &len);
186 if (Dart_IsError(result)) { 188 if (Dart_IsError(result)) {
187 Dart_PropagateError(result); 189 Dart_PropagateError(result);
188 } 190 }
189 buffer = static_cast<void*>((static_cast<uint8_t*>(buffer) + offset)); 191 buffer = static_cast<void*>((static_cast<uint8_t*>(buffer) + offset));
190 bytes_written = Socket::Write(socket, buffer, length); 192 bytes_written = Socket::Write(socket, buffer, length);
191 if (bytes_written > 0) total_bytes_written = bytes_written; 193 if (bytes_written > 0) total_bytes_written = bytes_written;
194 Dart_TypedDataReleaseData(buffer_obj);
192 } else { 195 } else {
193 // Send data in chunks of maximum 16KB. 196 // Send data in chunks of maximum 16KB.
194 const intptr_t max_chunk_length = 197 const intptr_t max_chunk_length =
195 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); 198 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB));
196 uint8_t* buffer = new uint8_t[max_chunk_length]; 199 uint8_t* buffer = new uint8_t[max_chunk_length];
197 do { 200 do {
198 intptr_t chunk_length = 201 intptr_t chunk_length =
199 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written); 202 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written);
200 result = Dart_ListGetAsBytes(buffer_obj, 203 result = Dart_ListGetAsBytes(buffer_obj,
201 offset + total_bytes_written, 204 offset + total_bytes_written,
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 435
433 436
434 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { 437 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) {
435 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); 438 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id);
436 } 439 }
437 440
438 441
439 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { 442 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) {
440 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); 443 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id);
441 } 444 }
OLDNEW
« no previous file with comments | « bin/secure_socket.cc ('k') | include/dart_api.h » ('j') | include/dart_api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698