| 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 #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(HOST_OS_LINUX) | 8 #if defined(HOST_OS_LINUX) |
| 9 | 9 |
| 10 #include "bin/socket_base.h" | 10 #include "bin/socket_base.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL || | 58 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL || |
| 59 error_number == EINVAL; | 59 error_number == EINVAL; |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 intptr_t SocketBase::Available(intptr_t fd) { | 63 intptr_t SocketBase::Available(intptr_t fd) { |
| 64 return FDUtils::AvailableBytes(fd); | 64 return FDUtils::AvailableBytes(fd); |
| 65 } | 65 } |
| 66 | 66 |
| 67 | 67 |
| 68 intptr_t SocketBase::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 68 intptr_t SocketBase::Read(intptr_t fd, |
| 69 void* buffer, |
| 70 intptr_t num_bytes, |
| 71 SocketOpKind sync) { |
| 69 ASSERT(fd >= 0); | 72 ASSERT(fd >= 0); |
| 70 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); | 73 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); |
| 71 ASSERT(EAGAIN == EWOULDBLOCK); | 74 ASSERT(EAGAIN == EWOULDBLOCK); |
| 72 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { | 75 if ((sync == kAsync) && (read_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 73 // If the read would block we need to retry and therefore return 0 | 76 // If the read would block we need to retry and therefore return 0 |
| 74 // as the number of bytes written. | 77 // as the number of bytes written. |
| 75 read_bytes = 0; | 78 read_bytes = 0; |
| 76 } | 79 } |
| 77 return read_bytes; | 80 return read_bytes; |
| 78 } | 81 } |
| 79 | 82 |
| 80 | 83 |
| 81 intptr_t SocketBase::RecvFrom(intptr_t fd, | 84 intptr_t SocketBase::RecvFrom(intptr_t fd, |
| 82 void* buffer, | 85 void* buffer, |
| 83 intptr_t num_bytes, | 86 intptr_t num_bytes, |
| 84 RawAddr* addr) { | 87 RawAddr* addr, |
| 88 SocketOpKind sync) { |
| 85 ASSERT(fd >= 0); | 89 ASSERT(fd >= 0); |
| 86 socklen_t addr_len = sizeof(addr->ss); | 90 socklen_t addr_len = sizeof(addr->ss); |
| 87 ssize_t read_bytes = TEMP_FAILURE_RETRY( | 91 ssize_t read_bytes = TEMP_FAILURE_RETRY( |
| 88 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); | 92 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); |
| 89 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { | 93 if ((sync == kAsync) && (read_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 90 // If the read would block we need to retry and therefore return 0 | 94 // If the read would block we need to retry and therefore return 0 |
| 91 // as the number of bytes written. | 95 // as the number of bytes written. |
| 92 read_bytes = 0; | 96 read_bytes = 0; |
| 93 } | 97 } |
| 94 return read_bytes; | 98 return read_bytes; |
| 95 } | 99 } |
| 96 | 100 |
| 97 | 101 |
| 98 intptr_t SocketBase::Write(intptr_t fd, | 102 intptr_t SocketBase::Write(intptr_t fd, |
| 99 const void* buffer, | 103 const void* buffer, |
| 100 intptr_t num_bytes) { | 104 intptr_t num_bytes, |
| 105 SocketOpKind sync) { |
| 101 ASSERT(fd >= 0); | 106 ASSERT(fd >= 0); |
| 102 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); | 107 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); |
| 103 ASSERT(EAGAIN == EWOULDBLOCK); | 108 ASSERT(EAGAIN == EWOULDBLOCK); |
| 104 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { | 109 if ((sync == kAsync) && (written_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 105 // If the would block we need to retry and therefore return 0 as | 110 // If the would block we need to retry and therefore return 0 as |
| 106 // the number of bytes written. | 111 // the number of bytes written. |
| 107 written_bytes = 0; | 112 written_bytes = 0; |
| 108 } | 113 } |
| 109 return written_bytes; | 114 return written_bytes; |
| 110 } | 115 } |
| 111 | 116 |
| 112 | 117 |
| 113 intptr_t SocketBase::SendTo(intptr_t fd, | 118 intptr_t SocketBase::SendTo(intptr_t fd, |
| 114 const void* buffer, | 119 const void* buffer, |
| 115 intptr_t num_bytes, | 120 intptr_t num_bytes, |
| 116 const RawAddr& addr) { | 121 const RawAddr& addr, |
| 122 SocketOpKind sync) { |
| 117 ASSERT(fd >= 0); | 123 ASSERT(fd >= 0); |
| 118 ssize_t written_bytes = | 124 ssize_t written_bytes = |
| 119 TEMP_FAILURE_RETRY(sendto(fd, buffer, num_bytes, 0, &addr.addr, | 125 TEMP_FAILURE_RETRY(sendto(fd, buffer, num_bytes, 0, &addr.addr, |
| 120 SocketAddress::GetAddrLength(addr))); | 126 SocketAddress::GetAddrLength(addr))); |
| 121 ASSERT(EAGAIN == EWOULDBLOCK); | 127 ASSERT(EAGAIN == EWOULDBLOCK); |
| 122 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { | 128 if ((sync == kAsync) && (written_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 123 // If the would block we need to retry and therefore return 0 as | 129 // If the would block we need to retry and therefore return 0 as |
| 124 // the number of bytes written. | 130 // the number of bytes written. |
| 125 written_bytes = 0; | 131 written_bytes = 0; |
| 126 } | 132 } |
| 127 return written_bytes; | 133 return written_bytes; |
| 128 } | 134 } |
| 129 | 135 |
| 130 | 136 |
| 131 intptr_t SocketBase::GetPort(intptr_t fd) { | 137 intptr_t SocketBase::GetPort(intptr_t fd) { |
| 132 ASSERT(fd >= 0); | 138 ASSERT(fd >= 0); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 return NO_RETRY_EXPECTED(setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, | 446 return NO_RETRY_EXPECTED(setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, |
| 441 sizeof(mreq))) == 0; | 447 sizeof(mreq))) == 0; |
| 442 } | 448 } |
| 443 | 449 |
| 444 } // namespace bin | 450 } // namespace bin |
| 445 } // namespace dart | 451 } // namespace dart |
| 446 | 452 |
| 447 #endif // defined(HOST_OS_LINUX) | 453 #endif // defined(HOST_OS_LINUX) |
| 448 | 454 |
| 449 #endif // !defined(DART_IO_DISABLED) | 455 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |