| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/isolate_data.h" | 6 #include "bin/isolate_data.h" |
| 7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
| 8 #include "bin/socket.h" | 8 #include "bin/socket.h" |
| 9 #include "bin/thread.h" | 9 #include "bin/thread.h" |
| 10 #include "bin/lockers.h" | 10 #include "bin/lockers.h" |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } else if (bytes_read == 0) { | 286 } else if (bytes_read == 0) { |
| 287 // On MacOS when reading from a tty Ctrl-D will result in reading one | 287 // On MacOS when reading from a tty Ctrl-D will result in reading one |
| 288 // less byte then reported as available. | 288 // less byte then reported as available. |
| 289 Dart_SetReturnValue(args, Dart_Null()); | 289 Dart_SetReturnValue(args, Dart_Null()); |
| 290 } else { | 290 } else { |
| 291 ASSERT(bytes_read == -1); | 291 ASSERT(bytes_read == -1); |
| 292 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 292 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 293 } | 293 } |
| 294 } else { | 294 } else { |
| 295 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | 295 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| 296 Dart_Handle err = DartUtils::NewDartOSError(&os_error); | 296 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
| 297 if (Dart_IsError(err)) Dart_PropagateError(err); | |
| 298 Dart_SetReturnValue(args, err); | |
| 299 } | 297 } |
| 300 } | 298 } |
| 301 | 299 |
| 302 | 300 |
| 303 void FUNCTION_NAME(Socket_RecvFrom)(Dart_NativeArguments args) { | 301 void FUNCTION_NAME(Socket_RecvFrom)(Dart_NativeArguments args) { |
| 304 intptr_t socket = | 302 intptr_t socket = |
| 305 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 303 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 306 | 304 |
| 307 // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can | 305 // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can |
| 308 // handle 64k datagrams. | 306 // handle 64k datagrams. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 if (Dart_IsError(dart_args[3])) Dart_PropagateError(dart_args[3]); | 353 if (Dart_IsError(dart_args[3])) Dart_PropagateError(dart_args[3]); |
| 356 // TODO(sgjesse): Cache the _makeDatagram function somewhere. | 354 // TODO(sgjesse): Cache the _makeDatagram function somewhere. |
| 357 Dart_Handle io_lib = | 355 Dart_Handle io_lib = |
| 358 Dart_LookupLibrary(DartUtils::NewString("dart:io")); | 356 Dart_LookupLibrary(DartUtils::NewString("dart:io")); |
| 359 if (Dart_IsError(io_lib)) Dart_PropagateError(io_lib); | 357 if (Dart_IsError(io_lib)) Dart_PropagateError(io_lib); |
| 360 Dart_Handle result = | 358 Dart_Handle result = |
| 361 Dart_Invoke(io_lib, | 359 Dart_Invoke(io_lib, |
| 362 DartUtils::NewString("_makeDatagram"), | 360 DartUtils::NewString("_makeDatagram"), |
| 363 kNumArgs, | 361 kNumArgs, |
| 364 dart_args); | 362 dart_args); |
| 365 if (Dart_IsError(result)) Dart_PropagateError(result); | |
| 366 Dart_SetReturnValue(args, result); | 363 Dart_SetReturnValue(args, result); |
| 367 } | 364 } |
| 368 | 365 |
| 369 | 366 |
| 370 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { | 367 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { |
| 371 static bool short_socket_writes = Dart_IsVMFlagSet("short_socket_write"); | 368 static bool short_socket_writes = Dart_IsVMFlagSet("short_socket_write"); |
| 372 intptr_t socket = | 369 intptr_t socket = |
| 373 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 370 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 374 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 371 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 375 ASSERT(Dart_IsList(buffer_obj)); | 372 ASSERT(Dart_IsList(buffer_obj)); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 void FUNCTION_NAME(ServerSocket_Accept)(Dart_NativeArguments args) { | 556 void FUNCTION_NAME(ServerSocket_Accept)(Dart_NativeArguments args) { |
| 560 intptr_t socket = | 557 intptr_t socket = |
| 561 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 558 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 562 intptr_t new_socket = ServerSocket::Accept(socket); | 559 intptr_t new_socket = ServerSocket::Accept(socket); |
| 563 if (new_socket >= 0) { | 560 if (new_socket >= 0) { |
| 564 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 1), new_socket); | 561 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 1), new_socket); |
| 565 Dart_SetReturnValue(args, Dart_True()); | 562 Dart_SetReturnValue(args, Dart_True()); |
| 566 } else if (new_socket == ServerSocket::kTemporaryFailure) { | 563 } else if (new_socket == ServerSocket::kTemporaryFailure) { |
| 567 Dart_SetReturnValue(args, Dart_False()); | 564 Dart_SetReturnValue(args, Dart_False()); |
| 568 } else { | 565 } else { |
| 569 Dart_Handle err = DartUtils::NewDartOSError(); | 566 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 570 if (Dart_IsError(err)) Dart_PropagateError(err); | |
| 571 Dart_SetReturnValue(args, err); | |
| 572 } | 567 } |
| 573 } | 568 } |
| 574 | 569 |
| 575 | 570 |
| 576 CObject* Socket::LookupRequest(const CObjectArray& request) { | 571 CObject* Socket::LookupRequest(const CObjectArray& request) { |
| 577 if (request.Length() == 2 && | 572 if (request.Length() == 2 && |
| 578 request[0]->IsString() && | 573 request[0]->IsString() && |
| 579 request[1]->IsInt32()) { | 574 request[1]->IsInt32()) { |
| 580 CObjectString host(request[0]); | 575 CObjectString host(request[0]); |
| 581 CObjectInt32 type(request[1]); | 576 CObjectInt32 type(request[1]); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { | 848 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { |
| 854 intptr_t socket = 0; | 849 intptr_t socket = 0; |
| 855 Dart_Handle err = | 850 Dart_Handle err = |
| 856 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); | 851 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); |
| 857 if (Dart_IsError(err)) Dart_PropagateError(err); | 852 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 858 return socket; | 853 return socket; |
| 859 } | 854 } |
| 860 | 855 |
| 861 } // namespace bin | 856 } // namespace bin |
| 862 } // namespace dart | 857 } // namespace dart |
| OLD | NEW |