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

Unified Diff: runtime/bin/socket.cc

Issue 171503009: Remove SocketData and now only pass the dart port to epoll. (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 | « runtime/bin/eventhandler_win.cc ('k') | runtime/bin/socket_linux.cc » ('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 f25bd3465d93c832fd7850c05d8b5f95e79e6ff4..fca6c54e253e47e33e465e818c68081f065d4a7e 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -99,50 +99,40 @@ void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) {
static bool short_socket_reads = Dart_IsVMFlagSet("short_socket_read");
intptr_t socket =
Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0));
- intptr_t available = Socket::Available(socket);
- if (available > 0) {
- int64_t length = 0;
- if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) {
- if (length == -1 || available < length) {
- length = available;
- }
- if (short_socket_reads) {
- length = (length + 1) / 2;
- }
- uint8_t* buffer = NULL;
- Dart_Handle result = IOBuffer::Allocate(length, &buffer);
- if (Dart_IsError(result)) Dart_PropagateError(result);
- ASSERT(buffer != NULL);
- intptr_t bytes_read = Socket::Read(socket, buffer, length);
- if (bytes_read == length) {
- Dart_SetReturnValue(args, result);
- } else if (bytes_read < length) {
- // 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);
- }
+ int64_t length = 0;
+ if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) {
+ if (short_socket_reads) {
+ length = (length + 1) / 2;
+ }
+ uint8_t* buffer = NULL;
+ Dart_Handle result = IOBuffer::Allocate(length, &buffer);
+ if (Dart_IsError(result)) Dart_PropagateError(result);
+ ASSERT(buffer != NULL);
+ intptr_t bytes_read = Socket::Read(socket, buffer, length);
+ if (bytes_read == length) {
+ Dart_SetReturnValue(args, result);
+ } else if (bytes_read < length) {
+ // 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 {
- ASSERT(bytes_read == -1);
- Dart_SetReturnValue(args, DartUtils::NewDartOSError());
+ 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 {
- OSError os_error(-1, "Invalid argument", OSError::kUnknown);
- Dart_Handle err = DartUtils::NewDartOSError(&os_error);
- if (Dart_IsError(err)) Dart_PropagateError(err);
- Dart_SetReturnValue(args, err);
+ ASSERT(bytes_read == -1);
+ Dart_SetReturnValue(args, DartUtils::NewDartOSError());
}
- } else if (available == 0) {
- Dart_SetReturnValue(args, Dart_Null());
} else {
- Dart_SetReturnValue(args, DartUtils::NewDartOSError());
+ OSError os_error(-1, "Invalid argument", OSError::kUnknown);
+ Dart_Handle err = DartUtils::NewDartOSError(&os_error);
+ if (Dart_IsError(err)) Dart_PropagateError(err);
+ Dart_SetReturnValue(args, err);
}
}
« no previous file with comments | « runtime/bin/eventhandler_win.cc ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698