| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_ANDROID) | 8 #if defined(HOST_OS_ANDROID) |
| 9 | 9 |
| 10 #include "bin/socket_base.h" | 10 #include "bin/socket_base.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL || | 55 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL || |
| 56 error_number == EINVAL; | 56 error_number == EINVAL; |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 intptr_t SocketBase::Available(intptr_t fd) { | 60 intptr_t SocketBase::Available(intptr_t fd) { |
| 61 return FDUtils::AvailableBytes(fd); | 61 return FDUtils::AvailableBytes(fd); |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| 65 intptr_t SocketBase::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 65 intptr_t SocketBase::Read(intptr_t fd, |
| 66 void* buffer, |
| 67 intptr_t num_bytes, |
| 68 SocketOpKind sync) { |
| 66 ASSERT(fd >= 0); | 69 ASSERT(fd >= 0); |
| 67 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); | 70 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); |
| 68 ASSERT(EAGAIN == EWOULDBLOCK); | 71 ASSERT(EAGAIN == EWOULDBLOCK); |
| 69 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { | 72 if ((sync == kAsync) && (read_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 70 // If the read would block we need to retry and therefore return 0 | 73 // If the read would block we need to retry and therefore return 0 |
| 71 // as the number of bytes written. | 74 // as the number of bytes written. |
| 72 read_bytes = 0; | 75 read_bytes = 0; |
| 73 } | 76 } |
| 74 return read_bytes; | 77 return read_bytes; |
| 75 } | 78 } |
| 76 | 79 |
| 77 | 80 |
| 78 intptr_t SocketBase::RecvFrom(intptr_t fd, | 81 intptr_t SocketBase::RecvFrom(intptr_t fd, |
| 79 void* buffer, | 82 void* buffer, |
| 80 intptr_t num_bytes, | 83 intptr_t num_bytes, |
| 81 RawAddr* addr) { | 84 RawAddr* addr, |
| 85 SocketOpKind sync) { |
| 82 ASSERT(fd >= 0); | 86 ASSERT(fd >= 0); |
| 83 socklen_t addr_len = sizeof(addr->ss); | 87 socklen_t addr_len = sizeof(addr->ss); |
| 84 ssize_t read_bytes = TEMP_FAILURE_RETRY( | 88 ssize_t read_bytes = TEMP_FAILURE_RETRY( |
| 85 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); | 89 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); |
| 86 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { | 90 if ((sync == kAsync) && (read_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 87 // If the read would block we need to retry and therefore return 0 | 91 // If the read would block we need to retry and therefore return 0 |
| 88 // as the number of bytes written. | 92 // as the number of bytes written. |
| 89 read_bytes = 0; | 93 read_bytes = 0; |
| 90 } | 94 } |
| 91 return read_bytes; | 95 return read_bytes; |
| 92 } | 96 } |
| 93 | 97 |
| 94 | 98 |
| 95 intptr_t SocketBase::Write(intptr_t fd, | 99 intptr_t SocketBase::Write(intptr_t fd, |
| 96 const void* buffer, | 100 const void* buffer, |
| 97 intptr_t num_bytes) { | 101 intptr_t num_bytes, |
| 102 SocketOpKind sync) { |
| 98 ASSERT(fd >= 0); | 103 ASSERT(fd >= 0); |
| 99 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); | 104 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); |
| 100 ASSERT(EAGAIN == EWOULDBLOCK); | 105 ASSERT(EAGAIN == EWOULDBLOCK); |
| 101 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { | 106 if ((sync == kAsync) && (written_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 102 // If the would block we need to retry and therefore return 0 as | 107 // If the would block we need to retry and therefore return 0 as |
| 103 // the number of bytes written. | 108 // the number of bytes written. |
| 104 written_bytes = 0; | 109 written_bytes = 0; |
| 105 } | 110 } |
| 106 return written_bytes; | 111 return written_bytes; |
| 107 } | 112 } |
| 108 | 113 |
| 109 | 114 |
| 110 intptr_t SocketBase::SendTo(intptr_t fd, | 115 intptr_t SocketBase::SendTo(intptr_t fd, |
| 111 const void* buffer, | 116 const void* buffer, |
| 112 intptr_t num_bytes, | 117 intptr_t num_bytes, |
| 113 const RawAddr& addr) { | 118 const RawAddr& addr, |
| 119 SocketOpKind sync) { |
| 114 ASSERT(fd >= 0); | 120 ASSERT(fd >= 0); |
| 115 ssize_t written_bytes = | 121 ssize_t written_bytes = |
| 116 TEMP_FAILURE_RETRY(sendto(fd, buffer, num_bytes, 0, &addr.addr, | 122 TEMP_FAILURE_RETRY(sendto(fd, buffer, num_bytes, 0, &addr.addr, |
| 117 SocketAddress::GetAddrLength(addr))); | 123 SocketAddress::GetAddrLength(addr))); |
| 118 ASSERT(EAGAIN == EWOULDBLOCK); | 124 ASSERT(EAGAIN == EWOULDBLOCK); |
| 119 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { | 125 if ((sync == kAsync) && (written_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 120 // If the would block we need to retry and therefore return 0 as | 126 // If the would block we need to retry and therefore return 0 as |
| 121 // the number of bytes written. | 127 // the number of bytes written. |
| 122 written_bytes = 0; | 128 written_bytes = 0; |
| 123 } | 129 } |
| 124 return written_bytes; | 130 return written_bytes; |
| 125 } | 131 } |
| 126 | 132 |
| 127 | 133 |
| 128 intptr_t SocketBase::GetPort(intptr_t fd) { | 134 intptr_t SocketBase::GetPort(intptr_t fd) { |
| 129 ASSERT(fd >= 0); | 135 ASSERT(fd >= 0); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 return NO_RETRY_EXPECTED(setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, | 403 return NO_RETRY_EXPECTED(setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, |
| 398 sizeof(mreq))) == 0; | 404 sizeof(mreq))) == 0; |
| 399 } | 405 } |
| 400 | 406 |
| 401 } // namespace bin | 407 } // namespace bin |
| 402 } // namespace dart | 408 } // namespace dart |
| 403 | 409 |
| 404 #endif // defined(HOST_OS_ANDROID) | 410 #endif // defined(HOST_OS_ANDROID) |
| 405 | 411 |
| 406 #endif // !defined(DART_IO_DISABLED) | 412 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |