| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 uint8_t* buffer = new uint8_t[length]; | 56 uint8_t* buffer = new uint8_t[length]; |
| 57 intptr_t bytes_read = Socket::Read(socket, buffer, length); | 57 intptr_t bytes_read = Socket::Read(socket, buffer, length); |
| 58 if (bytes_read > 0) { | 58 if (bytes_read > 0) { |
| 59 Dart_Handle result = | 59 Dart_Handle result = |
| 60 Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); | 60 Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); |
| 61 if (Dart_IsError(result)) { | 61 if (Dart_IsError(result)) { |
| 62 bytes_read = -1; | 62 bytes_read = -1; |
| 63 } | 63 } |
| 64 } else if (bytes_read < 0) { | |
| 65 bytes_read = 0; | |
| 66 } | 64 } |
| 67 delete[] buffer; | 65 delete[] buffer; |
| 68 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); | 66 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); |
| 69 Dart_ExitScope(); | 67 Dart_ExitScope(); |
| 70 } | 68 } |
| 71 | 69 |
| 72 | 70 |
| 73 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { | 71 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { |
| 74 Dart_EnterScope(); | 72 Dart_EnterScope(); |
| 75 intptr_t socket = | 73 intptr_t socket = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 89 if (Dart_IsVMFlagSet("short_socket_write")) { | 87 if (Dart_IsVMFlagSet("short_socket_write")) { |
| 90 length = (length + 1) / 2; | 88 length = (length + 1) / 2; |
| 91 } | 89 } |
| 92 | 90 |
| 93 uint8_t* buffer = new uint8_t[length]; | 91 uint8_t* buffer = new uint8_t[length]; |
| 94 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); | 92 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); |
| 95 ASSERT(!Dart_IsError(result)); | 93 ASSERT(!Dart_IsError(result)); |
| 96 intptr_t total_bytes_written = | 94 intptr_t total_bytes_written = |
| 97 Socket::Write(socket, reinterpret_cast<void*>(buffer), length); | 95 Socket::Write(socket, reinterpret_cast<void*>(buffer), length); |
| 98 delete[] buffer; | 96 delete[] buffer; |
| 99 if (total_bytes_written < 0) { | |
| 100 total_bytes_written = 0; | |
| 101 } | |
| 102 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); | 97 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); |
| 103 Dart_ExitScope(); | 98 Dart_ExitScope(); |
| 104 } | 99 } |
| 105 | 100 |
| 106 | 101 |
| 107 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { | 102 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { |
| 108 Dart_EnterScope(); | 103 Dart_EnterScope(); |
| 109 intptr_t socket = | 104 intptr_t socket = |
| 110 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), | 105 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), |
| 111 DartUtils::kIdFieldName); | 106 DartUtils::kIdFieldName); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 DartUtils::kIdFieldName); | 148 DartUtils::kIdFieldName); |
| 154 Dart_Handle socketobj = Dart_GetNativeArgument(args, 1); | 149 Dart_Handle socketobj = Dart_GetNativeArgument(args, 1); |
| 155 intptr_t newSocket = ServerSocket::Accept(socket); | 150 intptr_t newSocket = ServerSocket::Accept(socket); |
| 156 if (newSocket >= 0) { | 151 if (newSocket >= 0) { |
| 157 DartUtils::SetIntegerInstanceField( | 152 DartUtils::SetIntegerInstanceField( |
| 158 socketobj, DartUtils::kIdFieldName, newSocket); | 153 socketobj, DartUtils::kIdFieldName, newSocket); |
| 159 } | 154 } |
| 160 Dart_SetReturnValue(args, Dart_NewBoolean(newSocket >= 0)); | 155 Dart_SetReturnValue(args, Dart_NewBoolean(newSocket >= 0)); |
| 161 Dart_ExitScope(); | 156 Dart_ExitScope(); |
| 162 } | 157 } |
| OLD | NEW |