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

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
« no previous file with comments | « bin/secure_socket.cc ('k') | include/dart_api.h » ('j') | 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 Dart_PropagateError(result); 178 Dart_PropagateError(result);
179 } 179 }
180 ASSERT((offset + length) <= buffer_len); 180 ASSERT((offset + length) <= buffer_len);
181 181
182 if (short_socket_writes) { 182 if (short_socket_writes) {
183 length = (length + 1) / 2; 183 length = (length + 1) / 2;
184 } 184 }
185 185
186 intptr_t total_bytes_written = 0; 186 intptr_t total_bytes_written = 0;
187 intptr_t bytes_written = 0; 187 intptr_t bytes_written = 0;
188 if (Dart_IsByteArrayExternal(buffer_obj)) { 188 Dart_TypedData_Type type;
189 void* buffer = NULL; 189 uint8_t* buffer = NULL;
190 result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer); 190 intptr_t len;
191 if (Dart_IsError(result)) { 191 result = Dart_TypedDataAcquireData(buffer_obj, &type,
192 Dart_PropagateError(result); 192 reinterpret_cast<void**>(&buffer), &len);
193 } 193 if (!Dart_IsError(result)) {
194 buffer = static_cast<void*>(static_cast<uint8_t*>(buffer) + offset); 194 buffer += offset;
195 bytes_written = Socket::Write(socket, buffer, length); 195 bytes_written = Socket::Write(socket, buffer, length);
196 if (bytes_written > 0) total_bytes_written = bytes_written; 196 if (bytes_written > 0) total_bytes_written = bytes_written;
197 Dart_TypedDataReleaseData(buffer_obj);
197 } else { 198 } else {
198 // Send data in chunks of maximum 16KB. 199 // Send data in chunks of maximum 16KB.
199 const intptr_t max_chunk_length = 200 const intptr_t max_chunk_length =
200 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); 201 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB));
201 uint8_t* buffer = new uint8_t[max_chunk_length]; 202 buffer = new uint8_t[max_chunk_length];
202 do { 203 do {
203 intptr_t chunk_length = 204 intptr_t chunk_length =
204 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written); 205 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written);
205 result = Dart_ListGetAsBytes(buffer_obj, 206 result = Dart_ListGetAsBytes(buffer_obj,
206 offset + total_bytes_written, 207 offset + total_bytes_written,
207 buffer, 208 buffer,
208 chunk_length); 209 chunk_length);
209 if (Dart_IsError(result)) { 210 if (Dart_IsError(result)) {
210 delete[] buffer; 211 delete[] buffer;
211 Dart_PropagateError(result); 212 Dart_PropagateError(result);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 446
446 447
447 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { 448 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) {
448 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); 449 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id);
449 } 450 }
450 451
451 452
452 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { 453 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) {
453 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); 454 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id);
454 } 455 }
OLDNEW
« no previous file with comments | « bin/secure_socket.cc ('k') | include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698