| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
| 6 | 6 |
| 7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
| 8 #if defined(TARGET_OS_FUCHSIA) | 8 #if defined(TARGET_OS_FUCHSIA) |
| 9 | 9 |
| 10 #include "bin/socket.h" | 10 #include "bin/socket.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 LOG_INFO("Create: socket(SOCK_STREAM) -> fd %ld\n", fd); | 88 LOG_INFO("Create: socket(SOCK_STREAM) -> fd %ld\n", fd); |
| 89 if (!FDUtils::SetCloseOnExec(fd)) { | 89 if (!FDUtils::SetCloseOnExec(fd)) { |
| 90 LOG_ERR("Create: FDUtils::SetCloseOnExec(%ld) failed\n", fd); | 90 LOG_ERR("Create: FDUtils::SetCloseOnExec(%ld) failed\n", fd); |
| 91 FDUtils::SaveErrorAndClose(fd); | 91 FDUtils::SaveErrorAndClose(fd); |
| 92 return -1; | 92 return -1; |
| 93 } | 93 } |
| 94 return fd; | 94 return fd; |
| 95 } | 95 } |
| 96 | 96 |
| 97 | 97 |
| 98 static intptr_t CheckConnect(intptr_t fd) { | |
| 99 int val; | |
| 100 socklen_t vallen = sizeof(val); | |
| 101 LOG_INFO("CheckConnect: calling getsockopt(%ld)\n", fd); | |
| 102 intptr_t result = getsockopt(fd, SOL_SOCKET, SO_ERROR, &val, &vallen); | |
| 103 if (result != 0) { | |
| 104 FATAL1("CheckConnect: getsockopt(%ld) failed\n", fd); | |
| 105 } else if (vallen != sizeof(val)) { | |
| 106 FATAL1("CheckConnect: getsockopt(%ld) vallen != sizeof(val)!?!?\n", fd); | |
| 107 } else if (val != 0) { | |
| 108 LOG_ERR("CheckConnect: getsockopt(%ld) val = %d\n", fd, val); | |
| 109 return val; | |
| 110 } | |
| 111 LOG_INFO("CheckConnect: getsockopt(%ld) connected\n", fd); | |
| 112 return 0; | |
| 113 } | |
| 114 | |
| 115 | |
| 116 static intptr_t Connect(intptr_t fd, const RawAddr& addr) { | 98 static intptr_t Connect(intptr_t fd, const RawAddr& addr) { |
| 117 LOG_INFO("Connect: calling connect(%ld)\n", fd); | 99 LOG_INFO("Connect: calling connect(%ld)\n", fd); |
| 118 intptr_t result = NO_RETRY_EXPECTED( | 100 intptr_t result = NO_RETRY_EXPECTED( |
| 119 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr))); | 101 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr))); |
| 120 if ((result == 0) || (errno == EINPROGRESS)) { | 102 if ((result == 0) || (errno == EINPROGRESS)) { |
| 121 LOG_INFO("Connect: connect(%ld) succeeded\n", fd); | |
| 122 intptr_t error = 0; | |
| 123 // TODO(US-87): When the issue is resolved this check is no longer needed. | |
| 124 while ((error = CheckConnect(fd)) != 0) { | |
| 125 if (error != EINPROGRESS) { | |
| 126 errno = error; | |
| 127 FDUtils::SaveErrorAndClose(fd); | |
| 128 return -1; | |
| 129 } | |
| 130 } | |
| 131 return fd; | 103 return fd; |
| 132 } | 104 } |
| 133 LOG_ERR("Connect: connect(%ld) failed\n", fd); | 105 LOG_ERR("Connect: connect(%ld) failed\n", fd); |
| 134 FDUtils::SaveErrorAndClose(fd); | 106 FDUtils::SaveErrorAndClose(fd); |
| 135 return -1; | 107 return -1; |
| 136 } | 108 } |
| 137 | 109 |
| 138 | 110 |
| 139 intptr_t Socket::CreateConnect(const RawAddr& addr) { | 111 intptr_t Socket::CreateConnect(const RawAddr& addr) { |
| 140 intptr_t fd = Create(addr); | 112 intptr_t fd = Create(addr); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 454 |
| 483 | 455 |
| 484 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { | 456 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { |
| 485 LOG_ERR("Socket::GetNoDelay is unimplemented\n"); | 457 LOG_ERR("Socket::GetNoDelay is unimplemented\n"); |
| 486 UNIMPLEMENTED(); | 458 UNIMPLEMENTED(); |
| 487 return false; | 459 return false; |
| 488 } | 460 } |
| 489 | 461 |
| 490 | 462 |
| 491 bool Socket::SetNoDelay(intptr_t fd, bool enabled) { | 463 bool Socket::SetNoDelay(intptr_t fd, bool enabled) { |
| 492 // TODO(US-94): Enable. | |
| 493 #if 0 | |
| 494 int on = enabled ? 1 : 0; | 464 int on = enabled ? 1 : 0; |
| 495 return NO_RETRY_EXPECTED(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, | 465 return NO_RETRY_EXPECTED(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, |
| 496 reinterpret_cast<char*>(&on), | 466 reinterpret_cast<char*>(&on), |
| 497 sizeof(on))) == 0; | 467 sizeof(on))) == 0; |
| 498 #else | |
| 499 return true; | |
| 500 #endif | |
| 501 } | 468 } |
| 502 | 469 |
| 503 | 470 |
| 504 bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) { | 471 bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) { |
| 505 LOG_ERR("Socket::GetMulticastLoop is unimplemented\n"); | 472 LOG_ERR("Socket::GetMulticastLoop is unimplemented\n"); |
| 506 UNIMPLEMENTED(); | 473 UNIMPLEMENTED(); |
| 507 return false; | 474 return false; |
| 508 } | 475 } |
| 509 | 476 |
| 510 | 477 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 UNIMPLEMENTED(); | 528 UNIMPLEMENTED(); |
| 562 return false; | 529 return false; |
| 563 } | 530 } |
| 564 | 531 |
| 565 } // namespace bin | 532 } // namespace bin |
| 566 } // namespace dart | 533 } // namespace dart |
| 567 | 534 |
| 568 #endif // defined(TARGET_OS_FUCHSIA) | 535 #endif // defined(TARGET_OS_FUCHSIA) |
| 569 | 536 |
| 570 #endif // !defined(DART_IO_DISABLED) | 537 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |