| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } else { | 100 } else { |
| 101 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 101 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 Dart_ExitScope(); | 104 Dart_ExitScope(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 | 107 |
| 108 void FUNCTION_NAME(Socket_ReadList)(Dart_NativeArguments args) { | 108 void FUNCTION_NAME(Socket_ReadList)(Dart_NativeArguments args) { |
| 109 Dart_EnterScope(); | 109 Dart_EnterScope(); |
| 110 static bool short_socket_reads = Dart_IsVMFlagSet("short_socket_read"); |
| 110 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); | 111 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); |
| 111 intptr_t socket = 0; | 112 intptr_t socket = 0; |
| 112 Socket::GetSocketIdNativeField(socket_obj, &socket); | 113 Socket::GetSocketIdNativeField(socket_obj, &socket); |
| 113 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 114 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 114 int64_t offset = 0; | 115 int64_t offset = 0; |
| 115 int64_t length = 0; | 116 int64_t length = 0; |
| 116 Dart_Handle offset_obj = Dart_GetNativeArgument(args, 2); | 117 Dart_Handle offset_obj = Dart_GetNativeArgument(args, 2); |
| 117 Dart_Handle length_obj = Dart_GetNativeArgument(args, 3); | 118 Dart_Handle length_obj = Dart_GetNativeArgument(args, 3); |
| 118 if (Dart_IsList(buffer_obj) && | 119 if (Dart_IsList(buffer_obj) && |
| 119 DartUtils::GetInt64Value(offset_obj, &offset) && | 120 DartUtils::GetInt64Value(offset_obj, &offset) && |
| 120 DartUtils::GetInt64Value(length_obj, &length)) { | 121 DartUtils::GetInt64Value(length_obj, &length)) { |
| 121 intptr_t buffer_len = 0; | 122 intptr_t buffer_len = 0; |
| 122 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); | 123 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| 123 if (Dart_IsError(result)) { | 124 if (Dart_IsError(result)) { |
| 124 Dart_PropagateError(result); | 125 Dart_PropagateError(result); |
| 125 } | 126 } |
| 126 ASSERT((offset + length) <= buffer_len); | 127 ASSERT((offset + length) <= buffer_len); |
| 127 if (Dart_IsVMFlagSet("short_socket_read")) { | 128 if (short_socket_reads) { |
| 128 length = (length + 1) / 2; | 129 length = (length + 1) / 2; |
| 129 } | 130 } |
| 130 uint8_t* buffer = new uint8_t[length]; | 131 uint8_t* buffer = new uint8_t[length]; |
| 131 intptr_t bytes_read = Socket::Read(socket, buffer, length); | 132 intptr_t bytes_read = Socket::Read(socket, buffer, length); |
| 132 if (bytes_read > 0) { | 133 if (bytes_read > 0) { |
| 133 Dart_Handle result = | 134 Dart_Handle result = |
| 134 Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); | 135 Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); |
| 135 if (Dart_IsError(result)) { | 136 if (Dart_IsError(result)) { |
| 136 delete[] buffer; | 137 delete[] buffer; |
| 137 Dart_PropagateError(result); | 138 Dart_PropagateError(result); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 149 if (Dart_IsError(err)) Dart_PropagateError(err); | 150 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 150 Dart_SetReturnValue(args, err); | 151 Dart_SetReturnValue(args, err); |
| 151 } | 152 } |
| 152 | 153 |
| 153 Dart_ExitScope(); | 154 Dart_ExitScope(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 | 157 |
| 157 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { | 158 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { |
| 158 Dart_EnterScope(); | 159 Dart_EnterScope(); |
| 160 static bool short_socket_writes = Dart_IsVMFlagSet("short_socket_write"); |
| 159 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); | 161 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); |
| 160 intptr_t socket = 0; | 162 intptr_t socket = 0; |
| 161 Socket::GetSocketIdNativeField(socket_obj, &socket); | 163 Socket::GetSocketIdNativeField(socket_obj, &socket); |
| 162 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 164 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 163 ASSERT(Dart_IsList(buffer_obj)); | 165 ASSERT(Dart_IsList(buffer_obj)); |
| 164 intptr_t offset = | 166 intptr_t offset = |
| 165 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 167 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 166 intptr_t length = | 168 intptr_t length = |
| 167 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 169 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 168 intptr_t buffer_len = 0; | 170 intptr_t buffer_len = 0; |
| 169 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); | 171 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| 170 if (Dart_IsError(result)) { | 172 if (Dart_IsError(result)) { |
| 171 Dart_PropagateError(result); | 173 Dart_PropagateError(result); |
| 172 } | 174 } |
| 173 ASSERT((offset + length) <= buffer_len); | 175 ASSERT((offset + length) <= buffer_len); |
| 174 | 176 |
| 175 if (Dart_IsVMFlagSet("short_socket_write")) { | 177 if (short_socket_writes) { |
| 176 length = (length + 1) / 2; | 178 length = (length + 1) / 2; |
| 177 } | 179 } |
| 178 | 180 |
| 179 intptr_t total_bytes_written = 0; | 181 intptr_t total_bytes_written = 0; |
| 180 intptr_t bytes_written = 0; | 182 intptr_t bytes_written = 0; |
| 181 if (Dart_IsByteArrayExternal(buffer_obj)) { | 183 if (Dart_IsByteArrayExternal(buffer_obj)) { |
| 182 void* buffer = NULL; | 184 void* buffer = NULL; |
| 183 result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer); | 185 result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer); |
| 184 if (Dart_IsError(result)) { | 186 if (Dart_IsError(result)) { |
| 185 Dart_PropagateError(result); | 187 Dart_PropagateError(result); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 415 |
| 414 | 416 |
| 415 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { | 417 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { |
| 416 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); | 418 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 417 } | 419 } |
| 418 | 420 |
| 419 | 421 |
| 420 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { | 422 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { |
| 421 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); | 423 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 422 } | 424 } |
| OLD | NEW |