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

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

Issue 18324006: Extract the correct os-error on Socket.write, and report correctly in IOSink. (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 | sdk/lib/io/io_sink.dart » ('j') | sdk/lib/io/io_sink.dart » ('J')
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 intptr_t total_bytes_written = 0; 213 intptr_t total_bytes_written = 0;
214 intptr_t bytes_written = 0; 214 intptr_t bytes_written = 0;
215 Dart_TypedData_Type type; 215 Dart_TypedData_Type type;
216 uint8_t* buffer = NULL; 216 uint8_t* buffer = NULL;
217 intptr_t len; 217 intptr_t len;
218 result = Dart_TypedDataAcquireData(buffer_obj, &type, 218 result = Dart_TypedDataAcquireData(buffer_obj, &type,
219 reinterpret_cast<void**>(&buffer), &len); 219 reinterpret_cast<void**>(&buffer), &len);
220 if (!Dart_IsError(result)) { 220 if (!Dart_IsError(result)) {
221 buffer += offset; 221 buffer += offset;
222 bytes_written = Socket::Write(socket, buffer, length); 222 bytes_written = Socket::Write(socket, buffer, length);
223 if (bytes_written > 0) total_bytes_written = bytes_written; 223 if (bytes_written >= 0) {
224 Dart_TypedDataReleaseData(buffer_obj); 224 total_bytes_written = bytes_written;
225 Dart_TypedDataReleaseData(buffer_obj);
226 } else {
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 }
225 } else { 232 } else {
226 // Send data in chunks of maximum 16KB. 233 // Send data in chunks of maximum 16KB.
227 const intptr_t max_chunk_length = 234 const intptr_t max_chunk_length =
228 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); 235 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB));
229 buffer = new uint8_t[max_chunk_length]; 236 buffer = new uint8_t[max_chunk_length];
230 do { 237 do {
231 intptr_t chunk_length = 238 intptr_t chunk_length =
232 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written); 239 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written);
233 result = Dart_ListGetAsBytes(buffer_obj, 240 result = Dart_ListGetAsBytes(buffer_obj,
234 offset + total_bytes_written, 241 offset + total_bytes_written,
235 buffer, 242 buffer,
236 chunk_length); 243 chunk_length);
237 if (Dart_IsError(result)) { 244 if (Dart_IsError(result)) {
238 delete[] buffer; 245 delete[] buffer;
239 Dart_PropagateError(result); 246 Dart_PropagateError(result);
240 } 247 }
241 bytes_written = 248 bytes_written =
242 Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length); 249 Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length);
243 if (bytes_written > 0) total_bytes_written += bytes_written; 250 if (bytes_written >= 0) {
251 total_bytes_written += bytes_written;
252 } else {
253 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
254 }
244 } while (bytes_written > 0 && total_bytes_written < length); 255 } while (bytes_written > 0 && total_bytes_written < length);
245 delete[] buffer; 256 delete[] buffer;
246 } 257 }
247 if (bytes_written >= 0) { 258 if (bytes_written >= 0) {
248 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); 259 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written));
249 } else {
250 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
251 } 260 }
252 Dart_ExitScope(); 261 Dart_ExitScope();
253 } 262 }
254 263
255 264
256 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { 265 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) {
257 Dart_EnterScope(); 266 Dart_EnterScope();
258 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 267 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
259 intptr_t socket = 0; 268 intptr_t socket = 0;
260 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket); 269 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); 627 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id);
619 } 628 }
620 629
621 630
622 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { 631 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) {
623 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); 632 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id);
624 } 633 }
625 634
626 } // namespace bin 635 } // namespace bin
627 } // namespace dart 636 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/io/io_sink.dart » ('j') | sdk/lib/io/io_sink.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698