| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/socket.h" | 5 #include "bin/socket.h" |
| 6 #include "bin/dartutils.h" | 6 #include "bin/dartutils.h" |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 Dart_EnterScope(); | 37 Dart_EnterScope(); |
| 38 intptr_t socket = | 38 intptr_t socket = |
| 39 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), | 39 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), |
| 40 DartUtils::kIdFieldName); | 40 DartUtils::kIdFieldName); |
| 41 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 41 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 42 ASSERT(Dart_IsArray(buffer_obj)); | 42 ASSERT(Dart_IsArray(buffer_obj)); |
| 43 intptr_t offset = | 43 intptr_t offset = |
| 44 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 44 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 45 intptr_t length = | 45 intptr_t length = |
| 46 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 46 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 47 Dart_Result result = Dart_GetLength(buffer_obj); | 47 intptr_t buffer_len = 0; |
| 48 ASSERT(Dart_IsValidResult(result)); | 48 Dart_Handle result = Dart_GetLength(buffer_obj, &buffer_len); |
| 49 ASSERT((offset + length) <= Dart_GetResultAsCIntptr(result)); | 49 ASSERT(Dart_IsValid(result)); |
| 50 ASSERT((offset + length) <= buffer_len); |
| 50 | 51 |
| 51 if (Dart_IsVMFlagSet("short_socket_read")) { | 52 if (Dart_IsVMFlagSet("short_socket_read")) { |
| 52 length = (length + 1) / 2; | 53 length = (length + 1) / 2; |
| 53 } | 54 } |
| 54 | 55 |
| 55 uint8_t* buffer = new uint8_t[length]; | 56 uint8_t* buffer = new uint8_t[length]; |
| 56 intptr_t bytes_read = Socket::Read(socket, buffer, length); | 57 intptr_t bytes_read = Socket::Read(socket, buffer, length); |
| 57 if (bytes_read > 0) { | 58 if (bytes_read > 0) { |
| 58 Dart_Result result = Dart_ArraySet(buffer_obj, offset, buffer, bytes_read); | 59 Dart_Handle result = Dart_ArraySet(buffer_obj, offset, buffer, bytes_read); |
| 59 ASSERT(Dart_IsValidResult(result)); | 60 ASSERT(Dart_IsValid(result)); |
| 60 } else if (bytes_read < 0) { | 61 } else if (bytes_read < 0) { |
| 61 bytes_read = 0; | 62 bytes_read = 0; |
| 62 } | 63 } |
| 63 delete[] buffer; | 64 delete[] buffer; |
| 64 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); | 65 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); |
| 65 Dart_ExitScope(); | 66 Dart_ExitScope(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 | 69 |
| 69 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { | 70 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { |
| 70 Dart_EnterScope(); | 71 Dart_EnterScope(); |
| 71 intptr_t socket = | 72 intptr_t socket = |
| 72 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), | 73 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), |
| 73 DartUtils::kIdFieldName); | 74 DartUtils::kIdFieldName); |
| 74 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 75 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 75 ASSERT(Dart_IsArray(buffer_obj)); | 76 ASSERT(Dart_IsArray(buffer_obj)); |
| 76 intptr_t offset = | 77 intptr_t offset = |
| 77 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 78 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 78 intptr_t length = | 79 intptr_t length = |
| 79 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 80 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 80 Dart_Result result = Dart_GetLength(buffer_obj); | 81 intptr_t buffer_len = 0; |
| 81 ASSERT(Dart_IsValidResult(result)); | 82 Dart_Handle result = Dart_GetLength(buffer_obj, &buffer_len); |
| 82 ASSERT((offset + length) <= Dart_GetResultAsCIntptr(result)); | 83 ASSERT(Dart_IsValid(result)); |
| 84 ASSERT((offset + length) <= buffer_len); |
| 83 | 85 |
| 84 if (Dart_IsVMFlagSet("short_socket_write")) { | 86 if (Dart_IsVMFlagSet("short_socket_write")) { |
| 85 length = (length + 1) / 2; | 87 length = (length + 1) / 2; |
| 86 } | 88 } |
| 87 | 89 |
| 88 uint8_t* buffer = new uint8_t[length]; | 90 uint8_t* buffer = new uint8_t[length]; |
| 89 result = Dart_ArrayGet(buffer_obj, offset, buffer, length); | 91 result = Dart_ArrayGet(buffer_obj, offset, buffer, length); |
| 90 ASSERT(Dart_IsValidResult(result)); | 92 ASSERT(Dart_IsValid(result)); |
| 91 intptr_t total_bytes_written = | 93 intptr_t total_bytes_written = |
| 92 Socket::Write(socket, reinterpret_cast<void*>(buffer), length); | 94 Socket::Write(socket, reinterpret_cast<void*>(buffer), length); |
| 93 delete[] buffer; | 95 delete[] buffer; |
| 94 if (total_bytes_written < 0) { | 96 if (total_bytes_written < 0) { |
| 95 total_bytes_written = 0; | 97 total_bytes_written = 0; |
| 96 } | 98 } |
| 97 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); | 99 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); |
| 98 Dart_ExitScope(); | 100 Dart_ExitScope(); |
| 99 } | 101 } |
| 100 | 102 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 DartUtils::kIdFieldName); | 136 DartUtils::kIdFieldName); |
| 135 Dart_Handle socketobj = Dart_GetNativeArgument(args, 1); | 137 Dart_Handle socketobj = Dart_GetNativeArgument(args, 1); |
| 136 intptr_t newSocket = ServerSocket::Accept(socket); | 138 intptr_t newSocket = ServerSocket::Accept(socket); |
| 137 if (newSocket >= 0) { | 139 if (newSocket >= 0) { |
| 138 DartUtils::SetIntegerInstanceField( | 140 DartUtils::SetIntegerInstanceField( |
| 139 socketobj, DartUtils::kIdFieldName, newSocket); | 141 socketobj, DartUtils::kIdFieldName, newSocket); |
| 140 } | 142 } |
| 141 Dart_SetReturnValue(args, Dart_NewBoolean(newSocket >= 0)); | 143 Dart_SetReturnValue(args, Dart_NewBoolean(newSocket >= 0)); |
| 142 Dart_ExitScope(); | 144 Dart_ExitScope(); |
| 143 } | 145 } |
| OLD | NEW |