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

Unified Diff: runtime/bin/socket.cc

Issue 173633002: Don't try to call read, if len i 0. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/bin/socket_patch.dart » ('j') | no next file with comments »
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 fca6c54e253e47e33e465e818c68081f065d4a7e..fc528393b14b39fc7e746a2abce0084c065a8cd8 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -111,19 +111,17 @@ void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) {
intptr_t bytes_read = Socket::Read(socket, buffer, length);
if (bytes_read == length) {
Dart_SetReturnValue(args, result);
- } else if (bytes_read < length) {
+ } else if (bytes_read > 0) {
+ uint8_t* new_buffer = NULL;
+ Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer);
+ if (Dart_IsError(new_result)) Dart_PropagateError(new_result);
+ ASSERT(new_buffer != NULL);
+ memmove(new_buffer, buffer, bytes_read);
+ Dart_SetReturnValue(args, new_result);
+ } else if (bytes_read == 0) {
// On MacOS when reading from a tty Ctrl-D will result in reading one
// less byte then reported as available.
- if (bytes_read == 0) {
- Dart_SetReturnValue(args, Dart_Null());
- } else {
- uint8_t* new_buffer = NULL;
- Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer);
- if (Dart_IsError(new_result)) Dart_PropagateError(new_result);
- ASSERT(new_buffer != NULL);
- memmove(new_buffer, buffer, bytes_read);
- Dart_SetReturnValue(args, new_result);
- }
+ Dart_SetReturnValue(args, Dart_Null());
} else {
ASSERT(bytes_read == -1);
Dart_SetReturnValue(args, DartUtils::NewDartOSError());
« no previous file with comments | « no previous file | runtime/bin/socket_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698