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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/io/io_sink.dart » ('j') | sdk/lib/io/io_sink.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket.cc
diff --git a/runtime/bin/socket.cc b/runtime/bin/socket.cc
index b97661d9f80f62d67bfc757613d8f06f38438e8a..d909202655107f0a50c2daa4b789dcd94ccab040 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -220,8 +220,15 @@ void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) {
if (!Dart_IsError(result)) {
buffer += offset;
bytes_written = Socket::Write(socket, buffer, length);
- if (bytes_written > 0) total_bytes_written = bytes_written;
- Dart_TypedDataReleaseData(buffer_obj);
+ if (bytes_written >= 0) {
+ total_bytes_written = bytes_written;
+ Dart_TypedDataReleaseData(buffer_obj);
+ } else {
+ // Extract OSError before we release data, as it may override the error.
+ OSError os_error;
+ Dart_TypedDataReleaseData(buffer_obj);
+ Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
+ }
} else {
// Send data in chunks of maximum 16KB.
const intptr_t max_chunk_length =
@@ -240,14 +247,16 @@ void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) {
}
bytes_written =
Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length);
- if (bytes_written > 0) total_bytes_written += bytes_written;
+ if (bytes_written >= 0) {
+ total_bytes_written += bytes_written;
+ } else {
+ Dart_SetReturnValue(args, DartUtils::NewDartOSError());
+ }
} while (bytes_written > 0 && total_bytes_written < length);
delete[] buffer;
}
if (bytes_written >= 0) {
Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written));
- } else {
- Dart_SetReturnValue(args, DartUtils::NewDartOSError());
}
Dart_ExitScope();
}
« 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