| 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 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "bin/socket.h" | 8 #include "bin/socket.h" |
| 9 #include "bin/socket_android.h" | 9 #include "bin/socket_android.h" |
| 10 | 10 |
| 11 #include <errno.h> // NOLINT | 11 #include <errno.h> // NOLINT |
| 12 #include <netinet/tcp.h> // NOLINT |
| 12 #include <stdio.h> // NOLINT | 13 #include <stdio.h> // NOLINT |
| 13 #include <stdlib.h> // NOLINT | 14 #include <stdlib.h> // NOLINT |
| 14 #include <string.h> // NOLINT | 15 #include <string.h> // NOLINT |
| 15 #include <sys/stat.h> // NOLINT | 16 #include <sys/stat.h> // NOLINT |
| 16 #include <unistd.h> // NOLINT | 17 #include <unistd.h> // NOLINT |
| 17 #include <netinet/tcp.h> // NOLINT | |
| 18 | 18 |
| 19 #include "bin/fdutils.h" | 19 #include "bin/fdutils.h" |
| 20 #include "bin/file.h" | 20 #include "bin/file.h" |
| 21 #include "platform/signal_blocker.h" | 21 #include "platform/signal_blocker.h" |
| 22 | 22 |
| 23 namespace dart { | 23 namespace dart { |
| 24 namespace bin { | 24 namespace bin { |
| 25 | 25 |
| 26 SocketAddress::SocketAddress(struct sockaddr* sa) { | 26 SocketAddress::SocketAddress(struct sockaddr* sa) { |
| 27 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); | 27 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); |
| 28 if (!Socket::FormatNumericAddress( | 28 if (!Socket::FormatNumericAddress( |
| 29 *reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { | 29 *reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { |
| 30 as_string_[0] = 0; | 30 as_string_[0] = 0; |
| 31 } | 31 } |
| 32 socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa)); | 32 socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa)); |
| 33 memmove(reinterpret_cast<void *>(&addr_), sa, salen); | 33 memmove(reinterpret_cast<void *>(&addr_), sa, salen); |
| 34 } | 34 } |
| 35 | 35 |
| 36 | 36 |
| 37 bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) { | 37 bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) { |
| 38 socklen_t salen = SocketAddress::GetAddrLength(addr); | 38 socklen_t salen = SocketAddress::GetAddrLength(addr); |
| 39 if (NO_RETRY_EXPECTED(getnameinfo(&addr.addr, | 39 return (NO_RETRY_EXPECTED(getnameinfo( |
| 40 salen, | 40 &addr.addr, salen, address, len, NULL, 0, NI_NUMERICHOST)) == 0); |
| 41 address, | |
| 42 len, | |
| 43 NULL, | |
| 44 0, | |
| 45 NI_NUMERICHOST)) != 0) { | |
| 46 return false; | |
| 47 } | |
| 48 return true; | |
| 49 } | 41 } |
| 50 | 42 |
| 51 | 43 |
| 52 bool Socket::Initialize() { | 44 bool Socket::Initialize() { |
| 53 // Nothing to do on Android. | 45 // Nothing to do on Android. |
| 54 return true; | 46 return true; |
| 55 } | 47 } |
| 56 | 48 |
| 57 | 49 |
| 58 static intptr_t Create(const RawAddr& addr) { | 50 static intptr_t Create(const RawAddr& addr) { |
| 59 intptr_t fd; | 51 intptr_t fd; |
| 60 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); | 52 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); |
| 61 if (fd < 0) { | 53 if (fd < 0) { |
| 62 return -1; | 54 return -1; |
| 63 } | 55 } |
| 64 FDUtils::SetCloseOnExec(fd); | 56 FDUtils::SetCloseOnExec(fd); |
| 65 return fd; | 57 return fd; |
| 66 } | 58 } |
| 67 | 59 |
| 68 | 60 |
| 69 static intptr_t Connect(intptr_t fd, const RawAddr& addr) { | 61 static intptr_t Connect(intptr_t fd, const RawAddr& addr) { |
| 70 intptr_t result = TEMP_FAILURE_RETRY( | 62 intptr_t result = TEMP_FAILURE_RETRY( |
| 71 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr))); | 63 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr))); |
| 72 if (result == 0 || errno == EINPROGRESS) { | 64 if ((result == 0) || (errno == EINPROGRESS)) { |
| 73 return fd; | 65 return fd; |
| 74 } | 66 } |
| 75 VOID_TEMP_FAILURE_RETRY(close(fd)); | 67 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 76 return -1; | 68 return -1; |
| 77 } | 69 } |
| 78 | 70 |
| 79 | 71 |
| 80 intptr_t Socket::CreateConnect(const RawAddr& addr) { | 72 intptr_t Socket::CreateConnect(const RawAddr& addr) { |
| 81 intptr_t fd = Create(addr); | 73 intptr_t fd = Create(addr); |
| 82 if (fd < 0) { | 74 if (fd < 0) { |
| 83 return fd; | 75 return fd; |
| 84 } | 76 } |
| 85 | 77 |
| 86 FDUtils::SetNonBlocking(fd); | 78 FDUtils::SetNonBlocking(fd); |
| 87 | 79 |
| 88 return Connect(fd, addr); | 80 return Connect(fd, addr); |
| 89 } | 81 } |
| 90 | 82 |
| 91 | 83 |
| 92 intptr_t Socket::CreateBindConnect(const RawAddr& addr, | 84 intptr_t Socket::CreateBindConnect(const RawAddr& addr, |
| 93 const RawAddr& source_addr) { | 85 const RawAddr& source_addr) { |
| 94 intptr_t fd = Create(addr); | 86 intptr_t fd = Create(addr); |
| 95 if (fd < 0) { | 87 if (fd < 0) { |
| 96 return fd; | 88 return fd; |
| 97 } | 89 } |
| 98 | 90 |
| 99 intptr_t result = TEMP_FAILURE_RETRY( | 91 intptr_t result = TEMP_FAILURE_RETRY( |
| 100 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr))); | 92 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr))); |
| 101 if (result != 0 && errno != EINPROGRESS) { | 93 if ((result != 0) && (errno != EINPROGRESS)) { |
| 102 VOID_TEMP_FAILURE_RETRY(close(fd)); | 94 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 103 return -1; | 95 return -1; |
| 104 } | 96 } |
| 105 | 97 |
| 106 return Connect(fd, addr); | 98 return Connect(fd, addr); |
| 107 } | 99 } |
| 108 | 100 |
| 109 | 101 |
| 110 intptr_t Socket::Available(intptr_t fd) { | 102 intptr_t Socket::Available(intptr_t fd) { |
| 111 return FDUtils::AvailableBytes(fd); | 103 return FDUtils::AvailableBytes(fd); |
| 112 } | 104 } |
| 113 | 105 |
| 114 | 106 |
| 115 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 107 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
| 116 ASSERT(fd >= 0); | 108 ASSERT(fd >= 0); |
| 117 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); | 109 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); |
| 118 ASSERT(EAGAIN == EWOULDBLOCK); | 110 ASSERT(EAGAIN == EWOULDBLOCK); |
| 119 if (read_bytes == -1 && errno == EWOULDBLOCK) { | 111 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 120 // If the read would block we need to retry and therefore return 0 | 112 // If the read would block we need to retry and therefore return 0 |
| 121 // as the number of bytes written. | 113 // as the number of bytes written. |
| 122 read_bytes = 0; | 114 read_bytes = 0; |
| 123 } | 115 } |
| 124 return read_bytes; | 116 return read_bytes; |
| 125 } | 117 } |
| 126 | 118 |
| 127 | 119 |
| 128 intptr_t Socket::RecvFrom( | 120 intptr_t Socket::RecvFrom( |
| 129 intptr_t fd, void* buffer, intptr_t num_bytes, RawAddr* addr) { | 121 intptr_t fd, void* buffer, intptr_t num_bytes, RawAddr* addr) { |
| 130 ASSERT(fd >= 0); | 122 ASSERT(fd >= 0); |
| 131 socklen_t addr_len = sizeof(addr->ss); | 123 socklen_t addr_len = sizeof(addr->ss); |
| 132 ssize_t read_bytes = TEMP_FAILURE_RETRY( | 124 ssize_t read_bytes = TEMP_FAILURE_RETRY( |
| 133 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); | 125 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); |
| 134 if (read_bytes == -1 && errno == EWOULDBLOCK) { | 126 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 135 // If the read would block we need to retry and therefore return 0 | 127 // If the read would block we need to retry and therefore return 0 |
| 136 // as the number of bytes written. | 128 // as the number of bytes written. |
| 137 read_bytes = 0; | 129 read_bytes = 0; |
| 138 } | 130 } |
| 139 return read_bytes; | 131 return read_bytes; |
| 140 } | 132 } |
| 141 | 133 |
| 142 | 134 |
| 143 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { | 135 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { |
| 144 ASSERT(fd >= 0); | 136 ASSERT(fd >= 0); |
| 145 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); | 137 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); |
| 146 ASSERT(EAGAIN == EWOULDBLOCK); | 138 ASSERT(EAGAIN == EWOULDBLOCK); |
| 147 if (written_bytes == -1 && errno == EWOULDBLOCK) { | 139 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 148 // If the would block we need to retry and therefore return 0 as | 140 // If the would block we need to retry and therefore return 0 as |
| 149 // the number of bytes written. | 141 // the number of bytes written. |
| 150 written_bytes = 0; | 142 written_bytes = 0; |
| 151 } | 143 } |
| 152 return written_bytes; | 144 return written_bytes; |
| 153 } | 145 } |
| 154 | 146 |
| 155 | 147 |
| 156 intptr_t Socket::SendTo( | 148 intptr_t Socket::SendTo( |
| 157 intptr_t fd, const void* buffer, intptr_t num_bytes, const RawAddr& addr) { | 149 intptr_t fd, const void* buffer, intptr_t num_bytes, const RawAddr& addr) { |
| 158 ASSERT(fd >= 0); | 150 ASSERT(fd >= 0); |
| 159 ssize_t written_bytes = TEMP_FAILURE_RETRY( | 151 ssize_t written_bytes = TEMP_FAILURE_RETRY( |
| 160 sendto(fd, buffer, num_bytes, 0, | 152 sendto(fd, buffer, num_bytes, 0, |
| 161 &addr.addr, SocketAddress::GetAddrLength(addr))); | 153 &addr.addr, SocketAddress::GetAddrLength(addr))); |
| 162 ASSERT(EAGAIN == EWOULDBLOCK); | 154 ASSERT(EAGAIN == EWOULDBLOCK); |
| 163 if (written_bytes == -1 && errno == EWOULDBLOCK) { | 155 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 164 // If the would block we need to retry and therefore return 0 as | 156 // If the would block we need to retry and therefore return 0 as |
| 165 // the number of bytes written. | 157 // the number of bytes written. |
| 166 written_bytes = 0; | 158 written_bytes = 0; |
| 167 } | 159 } |
| 168 return written_bytes; | 160 return written_bytes; |
| 169 } | 161 } |
| 170 | 162 |
| 171 | 163 |
| 172 intptr_t Socket::GetPort(intptr_t fd) { | 164 intptr_t Socket::GetPort(intptr_t fd) { |
| 173 ASSERT(fd >= 0); | 165 ASSERT(fd >= 0); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 200 SO_ERROR, | 192 SO_ERROR, |
| 201 reinterpret_cast<void*>(&errorNumber), | 193 reinterpret_cast<void*>(&errorNumber), |
| 202 &len); | 194 &len); |
| 203 os_error->SetCodeAndMessage(OSError::kSystem, errorNumber); | 195 os_error->SetCodeAndMessage(OSError::kSystem, errorNumber); |
| 204 } | 196 } |
| 205 | 197 |
| 206 | 198 |
| 207 int Socket::GetType(intptr_t fd) { | 199 int Socket::GetType(intptr_t fd) { |
| 208 struct stat buf; | 200 struct stat buf; |
| 209 int result = fstat(fd, &buf); | 201 int result = fstat(fd, &buf); |
| 210 if (result == -1) return -1; | 202 if (result == -1) { |
| 211 if (S_ISCHR(buf.st_mode)) return File::kTerminal; | 203 return -1; |
| 212 if (S_ISFIFO(buf.st_mode)) return File::kPipe; | 204 } |
| 213 if (S_ISREG(buf.st_mode)) return File::kFile; | 205 if (S_ISCHR(buf.st_mode)) { |
| 206 return File::kTerminal; |
| 207 } |
| 208 if (S_ISFIFO(buf.st_mode)) { |
| 209 return File::kPipe; |
| 210 } |
| 211 if (S_ISREG(buf.st_mode)) { |
| 212 return File::kFile; |
| 213 } |
| 214 return File::kOther; | 214 return File::kOther; |
| 215 } | 215 } |
| 216 | 216 |
| 217 | 217 |
| 218 intptr_t Socket::GetStdioHandle(intptr_t num) { | 218 intptr_t Socket::GetStdioHandle(intptr_t num) { |
| 219 return num; | 219 return num; |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, | 223 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 240 if (status != 0) { | 240 if (status != 0) { |
| 241 ASSERT(*os_error == NULL); | 241 ASSERT(*os_error == NULL); |
| 242 *os_error = new OSError(status, | 242 *os_error = new OSError(status, |
| 243 gai_strerror(status), | 243 gai_strerror(status), |
| 244 OSError::kGetAddressInfo); | 244 OSError::kGetAddressInfo); |
| 245 return NULL; | 245 return NULL; |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 intptr_t count = 0; | 248 intptr_t count = 0; |
| 249 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { | 249 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { |
| 250 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++; | 250 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) { |
| 251 count++; |
| 252 } |
| 251 } | 253 } |
| 252 intptr_t i = 0; | 254 intptr_t i = 0; |
| 253 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); | 255 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); |
| 254 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { | 256 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { |
| 255 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) { | 257 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) { |
| 256 addresses->SetAt(i, new SocketAddress(c->ai_addr)); | 258 addresses->SetAt(i, new SocketAddress(c->ai_addr)); |
| 257 i++; | 259 i++; |
| 258 } | 260 } |
| 259 } | 261 } |
| 260 freeaddrinfo(info); | 262 freeaddrinfo(info); |
| 261 return addresses; | 263 return addresses; |
| 262 } | 264 } |
| 263 | 265 |
| 264 | 266 |
| 265 bool Socket::ReverseLookup(const RawAddr& addr, | 267 bool Socket::ReverseLookup(const RawAddr& addr, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 287 | 289 |
| 288 | 290 |
| 289 bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) { | 291 bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) { |
| 290 int result; | 292 int result; |
| 291 if (type == SocketAddress::TYPE_IPV4) { | 293 if (type == SocketAddress::TYPE_IPV4) { |
| 292 result = inet_pton(AF_INET, address, &addr->in.sin_addr); | 294 result = inet_pton(AF_INET, address, &addr->in.sin_addr); |
| 293 } else { | 295 } else { |
| 294 ASSERT(type == SocketAddress::TYPE_IPV6); | 296 ASSERT(type == SocketAddress::TYPE_IPV6); |
| 295 result = inet_pton(AF_INET6, address, &addr->in6.sin6_addr); | 297 result = inet_pton(AF_INET6, address, &addr->in6.sin6_addr); |
| 296 } | 298 } |
| 297 return result == 1; | 299 return (result == 1); |
| 298 } | 300 } |
| 299 | 301 |
| 300 | 302 |
| 301 intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) { | 303 intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) { |
| 302 intptr_t fd; | 304 intptr_t fd; |
| 303 | 305 |
| 304 fd = NO_RETRY_EXPECTED(socket(addr.addr.sa_family, SOCK_DGRAM, IPPROTO_UDP)); | 306 fd = NO_RETRY_EXPECTED(socket(addr.addr.sa_family, SOCK_DGRAM, IPPROTO_UDP)); |
| 305 if (fd < 0) return -1; | 307 if (fd < 0) { |
| 308 return -1; |
| 309 } |
| 306 | 310 |
| 307 FDUtils::SetCloseOnExec(fd); | 311 FDUtils::SetCloseOnExec(fd); |
| 308 | 312 |
| 309 if (reuseAddress) { | 313 if (reuseAddress) { |
| 310 int optval = 1; | 314 int optval = 1; |
| 311 VOID_NO_RETRY_EXPECTED( | 315 VOID_NO_RETRY_EXPECTED( |
| 312 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); | 316 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
| 313 } | 317 } |
| 314 | 318 |
| 315 if (NO_RETRY_EXPECTED( | 319 if (NO_RETRY_EXPECTED( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 333 return NULL; | 337 return NULL; |
| 334 } | 338 } |
| 335 | 339 |
| 336 | 340 |
| 337 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr, | 341 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr, |
| 338 intptr_t backlog, | 342 intptr_t backlog, |
| 339 bool v6_only) { | 343 bool v6_only) { |
| 340 intptr_t fd; | 344 intptr_t fd; |
| 341 | 345 |
| 342 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); | 346 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); |
| 343 if (fd < 0) return -1; | 347 if (fd < 0) { |
| 348 return -1; |
| 349 } |
| 344 | 350 |
| 345 FDUtils::SetCloseOnExec(fd); | 351 FDUtils::SetCloseOnExec(fd); |
| 346 | 352 |
| 347 int optval = 1; | 353 int optval = 1; |
| 348 VOID_NO_RETRY_EXPECTED( | 354 VOID_NO_RETRY_EXPECTED( |
| 349 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); | 355 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
| 350 | 356 |
| 351 if (addr.ss.ss_family == AF_INET6) { | 357 if (addr.ss.ss_family == AF_INET6) { |
| 352 optval = v6_only ? 1 : 0; | 358 optval = v6_only ? 1 : 0; |
| 353 VOID_NO_RETRY_EXPECTED( | 359 VOID_NO_RETRY_EXPECTED( |
| 354 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval))); | 360 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval))); |
| 355 } | 361 } |
| 356 | 362 |
| 357 if (NO_RETRY_EXPECTED( | 363 if (NO_RETRY_EXPECTED( |
| 358 bind(fd, | 364 bind(fd, |
| 359 &addr.addr, | 365 &addr.addr, |
| 360 SocketAddress::GetAddrLength(addr))) < 0) { | 366 SocketAddress::GetAddrLength(addr))) < 0) { |
| 361 VOID_TEMP_FAILURE_RETRY(close(fd)); | 367 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 362 return -1; | 368 return -1; |
| 363 } | 369 } |
| 364 | 370 |
| 365 // Test for invalid socket port 65535 (some browsers disallow it). | 371 // Test for invalid socket port 65535 (some browsers disallow it). |
| 366 if (SocketAddress::GetAddrPort(addr) == 0 && Socket::GetPort(fd) == 65535) { | 372 if ((SocketAddress::GetAddrPort(addr)) == 0 && |
| 373 (Socket::GetPort(fd) == 65535)) { |
| 367 // Don't close the socket until we have created a new socket, ensuring | 374 // Don't close the socket until we have created a new socket, ensuring |
| 368 // that we do not get the bad port number again. | 375 // that we do not get the bad port number again. |
| 369 intptr_t new_fd = CreateBindListen(addr, backlog, v6_only); | 376 intptr_t new_fd = CreateBindListen(addr, backlog, v6_only); |
| 370 int err = errno; | 377 int err = errno; |
| 371 VOID_TEMP_FAILURE_RETRY(close(fd)); | 378 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 372 errno = err; | 379 errno = err; |
| 373 return new_fd; | 380 return new_fd; |
| 374 } | 381 } |
| 375 | 382 |
| 376 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { | 383 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 435 |
| 429 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { | 436 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { |
| 430 int on; | 437 int on; |
| 431 socklen_t len = sizeof(on); | 438 socklen_t len = sizeof(on); |
| 432 int err = NO_RETRY_EXPECTED(getsockopt(fd, | 439 int err = NO_RETRY_EXPECTED(getsockopt(fd, |
| 433 IPPROTO_TCP, | 440 IPPROTO_TCP, |
| 434 TCP_NODELAY, | 441 TCP_NODELAY, |
| 435 reinterpret_cast<void *>(&on), | 442 reinterpret_cast<void *>(&on), |
| 436 &len)); | 443 &len)); |
| 437 if (err == 0) { | 444 if (err == 0) { |
| 438 *enabled = on == 1; | 445 *enabled = (on == 1); |
| 439 } | 446 } |
| 440 return err == 0; | 447 return (err == 0); |
| 441 } | 448 } |
| 442 | 449 |
| 443 | 450 |
| 444 bool Socket::SetNoDelay(intptr_t fd, bool enabled) { | 451 bool Socket::SetNoDelay(intptr_t fd, bool enabled) { |
| 445 int on = enabled ? 1 : 0; | 452 int on = enabled ? 1 : 0; |
| 446 return NO_RETRY_EXPECTED(setsockopt(fd, | 453 return NO_RETRY_EXPECTED(setsockopt(fd, |
| 447 IPPROTO_TCP, | 454 IPPROTO_TCP, |
| 448 TCP_NODELAY, | 455 TCP_NODELAY, |
| 449 reinterpret_cast<char *>(&on), | 456 reinterpret_cast<char *>(&on), |
| 450 sizeof(on))) == 0; | 457 sizeof(on))) == 0; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 | 521 |
| 515 bool Socket::GetBroadcast(intptr_t fd, bool* enabled) { | 522 bool Socket::GetBroadcast(intptr_t fd, bool* enabled) { |
| 516 int on; | 523 int on; |
| 517 socklen_t len = sizeof(on); | 524 socklen_t len = sizeof(on); |
| 518 int err = NO_RETRY_EXPECTED(getsockopt(fd, | 525 int err = NO_RETRY_EXPECTED(getsockopt(fd, |
| 519 SOL_SOCKET, | 526 SOL_SOCKET, |
| 520 SO_BROADCAST, | 527 SO_BROADCAST, |
| 521 reinterpret_cast<char *>(&on), | 528 reinterpret_cast<char *>(&on), |
| 522 &len)); | 529 &len)); |
| 523 if (err == 0) { | 530 if (err == 0) { |
| 524 *enabled = on == 1; | 531 *enabled = (on == 1); |
| 525 } | 532 } |
| 526 return err == 0; | 533 return (err == 0); |
| 527 } | 534 } |
| 528 | 535 |
| 529 | 536 |
| 530 bool Socket::SetBroadcast(intptr_t fd, bool enabled) { | 537 bool Socket::SetBroadcast(intptr_t fd, bool enabled) { |
| 531 int on = enabled ? 1 : 0; | 538 int on = enabled ? 1 : 0; |
| 532 return NO_RETRY_EXPECTED(setsockopt(fd, | 539 return NO_RETRY_EXPECTED(setsockopt(fd, |
| 533 SOL_SOCKET, | 540 SOL_SOCKET, |
| 534 SO_BROADCAST, | 541 SO_BROADCAST, |
| 535 reinterpret_cast<char *>(&on), | 542 reinterpret_cast<char *>(&on), |
| 536 sizeof(on))) == 0; | 543 sizeof(on))) == 0; |
| 537 } | 544 } |
| 538 | 545 |
| 539 | 546 |
| 540 bool Socket::JoinMulticast( | 547 bool Socket::JoinMulticast( |
| 541 intptr_t fd, const RawAddr& addr, const RawAddr&, int interfaceIndex) { | 548 intptr_t fd, const RawAddr& addr, const RawAddr&, int interfaceIndex) { |
| 542 int proto = addr.addr.sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6; | 549 int proto = (addr.addr.sa_family == AF_INET) ? IPPROTO_IP : IPPROTO_IPV6; |
| 543 struct group_req mreq; | 550 struct group_req mreq; |
| 544 mreq.gr_interface = interfaceIndex; | 551 mreq.gr_interface = interfaceIndex; |
| 545 memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr)); | 552 memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr)); |
| 546 return NO_RETRY_EXPECTED(setsockopt( | 553 return NO_RETRY_EXPECTED(setsockopt( |
| 547 fd, proto, MCAST_JOIN_GROUP, &mreq, sizeof(mreq))) == 0; | 554 fd, proto, MCAST_JOIN_GROUP, &mreq, sizeof(mreq))) == 0; |
| 548 } | 555 } |
| 549 | 556 |
| 550 | 557 |
| 551 bool Socket::LeaveMulticast( | 558 bool Socket::LeaveMulticast( |
| 552 intptr_t fd, const RawAddr& addr, const RawAddr&, int interfaceIndex) { | 559 intptr_t fd, const RawAddr& addr, const RawAddr&, int interfaceIndex) { |
| 553 int proto = addr.addr.sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6; | 560 int proto = (addr.addr.sa_family == AF_INET) ? IPPROTO_IP : IPPROTO_IPV6; |
| 554 struct group_req mreq; | 561 struct group_req mreq; |
| 555 mreq.gr_interface = interfaceIndex; | 562 mreq.gr_interface = interfaceIndex; |
| 556 memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr)); | 563 memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr)); |
| 557 return NO_RETRY_EXPECTED(setsockopt( | 564 return NO_RETRY_EXPECTED(setsockopt( |
| 558 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; | 565 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; |
| 559 } | 566 } |
| 560 | 567 |
| 561 } // namespace bin | 568 } // namespace bin |
| 562 } // namespace dart | 569 } // namespace dart |
| 563 | 570 |
| 564 #endif // defined(TARGET_OS_ANDROID) | 571 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |