| 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 "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 | 9 |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| 11 | 11 |
| 12 | 12 |
| 13 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { | 13 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { |
| 14 Dart_EnterScope(); | 14 Dart_EnterScope(); |
| 15 Dart_Handle socketobj = Dart_GetNativeArgument(args, 0); | 15 Dart_Handle socketobj = Dart_GetNativeArgument(args, 0); |
| 16 const char* host = | 16 const char* host = |
| 17 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); | 17 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
| 18 intptr_t port = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 18 intptr_t port = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 19 intptr_t socket = Socket::CreateConnect(host, port); | 19 intptr_t socket = Socket::CreateConnect(host, port); |
| 20 DartUtils::SetIntegerInstanceField( | 20 DartUtils::SetIntegerField( |
| 21 socketobj, DartUtils::kIdFieldName, socket); | 21 socketobj, DartUtils::kIdFieldName, socket); |
| 22 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); | 22 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); |
| 23 Dart_ExitScope(); | 23 Dart_ExitScope(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 | 26 |
| 27 void FUNCTION_NAME(Socket_Available)(Dart_NativeArguments args) { | 27 void FUNCTION_NAME(Socket_Available)(Dart_NativeArguments args) { |
| 28 Dart_EnterScope(); | 28 Dart_EnterScope(); |
| 29 intptr_t socket = | 29 intptr_t socket = |
| 30 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), | 30 DartUtils::GetIntegerField(Dart_GetNativeArgument(args, 0), |
| 31 DartUtils::kIdFieldName); | 31 DartUtils::kIdFieldName); |
| 32 intptr_t available = Socket::Available(socket); | 32 intptr_t available = Socket::Available(socket); |
| 33 Dart_SetReturnValue(args, Dart_NewInteger(available)); | 33 Dart_SetReturnValue(args, Dart_NewInteger(available)); |
| 34 Dart_ExitScope(); | 34 Dart_ExitScope(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 void FUNCTION_NAME(Socket_ReadList)(Dart_NativeArguments args) { | 38 void FUNCTION_NAME(Socket_ReadList)(Dart_NativeArguments args) { |
| 39 Dart_EnterScope(); | 39 Dart_EnterScope(); |
| 40 intptr_t socket = | 40 intptr_t socket = |
| 41 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), | 41 DartUtils::GetIntegerField(Dart_GetNativeArgument(args, 0), |
| 42 DartUtils::kIdFieldName); | 42 DartUtils::kIdFieldName); |
| 43 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 43 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 44 ASSERT(Dart_IsList(buffer_obj)); | 44 ASSERT(Dart_IsList(buffer_obj)); |
| 45 intptr_t offset = | 45 intptr_t offset = |
| 46 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 46 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 47 intptr_t length = | 47 intptr_t length = |
| 48 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 48 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 49 intptr_t buffer_len = 0; | 49 intptr_t buffer_len = 0; |
| 50 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); | 50 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| 51 ASSERT(!Dart_IsError(result)); | 51 ASSERT(!Dart_IsError(result)); |
| 52 ASSERT((offset + length) <= buffer_len); | 52 ASSERT((offset + length) <= buffer_len); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 66 } | 66 } |
| 67 delete[] buffer; | 67 delete[] buffer; |
| 68 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); | 68 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); |
| 69 Dart_ExitScope(); | 69 Dart_ExitScope(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 | 72 |
| 73 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { | 73 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { |
| 74 Dart_EnterScope(); | 74 Dart_EnterScope(); |
| 75 intptr_t socket = | 75 intptr_t socket = |
| 76 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), | 76 DartUtils::GetIntegerField(Dart_GetNativeArgument(args, 0), |
| 77 DartUtils::kIdFieldName); | 77 DartUtils::kIdFieldName); |
| 78 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 78 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 79 ASSERT(Dart_IsList(buffer_obj)); | 79 ASSERT(Dart_IsList(buffer_obj)); |
| 80 intptr_t offset = | 80 intptr_t offset = |
| 81 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 81 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 82 intptr_t length = | 82 intptr_t length = |
| 83 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 83 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 84 intptr_t buffer_len = 0; | 84 intptr_t buffer_len = 0; |
| 85 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); | 85 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| 86 ASSERT(!Dart_IsError(result)); | 86 ASSERT(!Dart_IsError(result)); |
| 87 ASSERT((offset + length) <= buffer_len); | 87 ASSERT((offset + length) <= buffer_len); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 110 } while (bytes_written > 0 && total_bytes_written < length); | 110 } while (bytes_written > 0 && total_bytes_written < length); |
| 111 delete[] buffer; | 111 delete[] buffer; |
| 112 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); | 112 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); |
| 113 Dart_ExitScope(); | 113 Dart_ExitScope(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 | 116 |
| 117 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { | 117 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { |
| 118 Dart_EnterScope(); | 118 Dart_EnterScope(); |
| 119 intptr_t socket = | 119 intptr_t socket = |
| 120 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), | 120 DartUtils::GetIntegerField(Dart_GetNativeArgument(args, 0), |
| 121 DartUtils::kIdFieldName); | 121 DartUtils::kIdFieldName); |
| 122 intptr_t port = Socket::GetPort(socket); | 122 intptr_t port = Socket::GetPort(socket); |
| 123 Dart_SetReturnValue(args, Dart_NewInteger(port)); | 123 Dart_SetReturnValue(args, Dart_NewInteger(port)); |
| 124 Dart_ExitScope(); | 124 Dart_ExitScope(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 | 127 |
| 128 void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) { | 128 void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) { |
| 129 Dart_EnterScope(); | 129 Dart_EnterScope(); |
| 130 Dart_Handle socketobj = Dart_GetNativeArgument(args, 0); | 130 Dart_Handle socketobj = Dart_GetNativeArgument(args, 0); |
| 131 intptr_t num = | 131 intptr_t num = |
| 132 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 132 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| 133 ASSERT(num == 0 || num == 1 || num == 2); | 133 ASSERT(num == 0 || num == 1 || num == 2); |
| 134 intptr_t socket = Socket::GetStdioHandle(num); | 134 intptr_t socket = Socket::GetStdioHandle(num); |
| 135 DartUtils::SetIntegerInstanceField( | 135 DartUtils::SetIntegerField( |
| 136 socketobj, DartUtils::kIdFieldName, socket); | 136 socketobj, DartUtils::kIdFieldName, socket); |
| 137 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); | 137 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); |
| 138 Dart_ExitScope(); | 138 Dart_ExitScope(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 | 141 |
| 142 void FUNCTION_NAME(ServerSocket_CreateBindListen)(Dart_NativeArguments args) { | 142 void FUNCTION_NAME(ServerSocket_CreateBindListen)(Dart_NativeArguments args) { |
| 143 Dart_EnterScope(); | 143 Dart_EnterScope(); |
| 144 Dart_Handle socketobj = Dart_GetNativeArgument(args, 0); | 144 Dart_Handle socketobj = Dart_GetNativeArgument(args, 0); |
| 145 const char* bindAddress = | 145 const char* bindAddress = |
| 146 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); | 146 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
| 147 intptr_t port = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 147 intptr_t port = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 148 intptr_t backlog = | 148 intptr_t backlog = |
| 149 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 149 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 150 intptr_t socket = | 150 intptr_t socket = |
| 151 ServerSocket::CreateBindListen(bindAddress, port, backlog); | 151 ServerSocket::CreateBindListen(bindAddress, port, backlog); |
| 152 DartUtils::SetIntegerInstanceField( | 152 DartUtils::SetIntegerField( |
| 153 socketobj, DartUtils::kIdFieldName, socket); | 153 socketobj, DartUtils::kIdFieldName, socket); |
| 154 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); | 154 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); |
| 155 Dart_ExitScope(); | 155 Dart_ExitScope(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 | 158 |
| 159 void FUNCTION_NAME(ServerSocket_Accept)(Dart_NativeArguments args) { | 159 void FUNCTION_NAME(ServerSocket_Accept)(Dart_NativeArguments args) { |
| 160 Dart_EnterScope(); | 160 Dart_EnterScope(); |
| 161 intptr_t socket = | 161 intptr_t socket = |
| 162 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), | 162 DartUtils::GetIntegerField(Dart_GetNativeArgument(args, 0), |
| 163 DartUtils::kIdFieldName); | 163 DartUtils::kIdFieldName); |
| 164 Dart_Handle socketobj = Dart_GetNativeArgument(args, 1); | 164 Dart_Handle socketobj = Dart_GetNativeArgument(args, 1); |
| 165 intptr_t newSocket = ServerSocket::Accept(socket); | 165 intptr_t newSocket = ServerSocket::Accept(socket); |
| 166 if (newSocket >= 0) { | 166 if (newSocket >= 0) { |
| 167 DartUtils::SetIntegerInstanceField( | 167 DartUtils::SetIntegerField( |
| 168 socketobj, DartUtils::kIdFieldName, newSocket); | 168 socketobj, DartUtils::kIdFieldName, newSocket); |
| 169 } | 169 } |
| 170 Dart_SetReturnValue(args, Dart_NewBoolean(newSocket >= 0)); | 170 Dart_SetReturnValue(args, Dart_NewBoolean(newSocket >= 0)); |
| 171 Dart_ExitScope(); | 171 Dart_ExitScope(); |
| 172 } | 172 } |
| OLD | NEW |