| 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(HOST_OS_FUCHSIA) | 8 #if defined(HOST_OS_FUCHSIA) |
| 9 | 9 |
| 10 #include "bin/socket.h" | 10 #include "bin/socket.h" |
| 11 #include "bin/socket_fuchsia.h" | 11 #include "bin/socket_common_fuchsia.h" |
| 12 | 12 |
| 13 #include <errno.h> // NOLINT | 13 #include <errno.h> // NOLINT |
| 14 #include <fcntl.h> // NOLINT | 14 #include <fcntl.h> // NOLINT |
| 15 #include <ifaddrs.h> // NOLINT | 15 #include <ifaddrs.h> // NOLINT |
| 16 #include <net/if.h> // NOLINT | 16 #include <net/if.h> // NOLINT |
| 17 #include <netinet/tcp.h> // NOLINT | 17 #include <netinet/tcp.h> // NOLINT |
| 18 #include <stdio.h> // NOLINT | 18 #include <stdio.h> // NOLINT |
| 19 #include <stdlib.h> // NOLINT | 19 #include <stdlib.h> // NOLINT |
| 20 #include <string.h> // NOLINT | 20 #include <string.h> // NOLINT |
| 21 #include <sys/ioctl.h> // NOLINT | 21 #include <sys/ioctl.h> // NOLINT |
| (...skipping 26 matching lines...) Expand all Loading... |
| 48 #else | 48 #else |
| 49 #define LOG_ERR(msg, ...) | 49 #define LOG_ERR(msg, ...) |
| 50 #define LOG_INFO(msg, ...) | 50 #define LOG_INFO(msg, ...) |
| 51 #endif // defined(SOCKET_LOG_INFO) || defined(SOCKET_LOG_ERROR) | 51 #endif // defined(SOCKET_LOG_INFO) || defined(SOCKET_LOG_ERROR) |
| 52 | 52 |
| 53 namespace dart { | 53 namespace dart { |
| 54 namespace bin { | 54 namespace bin { |
| 55 | 55 |
| 56 SocketAddress::SocketAddress(struct sockaddr* sa) { | 56 SocketAddress::SocketAddress(struct sockaddr* sa) { |
| 57 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); | 57 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); |
| 58 if (!Socket::FormatNumericAddress(*reinterpret_cast<RawAddr*>(sa), as_string_, | 58 if (!BaseSocket::FormatNumericAddress(*reinterpret_cast<RawAddr*>(sa), |
| 59 INET6_ADDRSTRLEN)) { | 59 as_string_, INET6_ADDRSTRLEN)) { |
| 60 as_string_[0] = 0; | 60 as_string_[0] = 0; |
| 61 } | 61 } |
| 62 socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa)); | 62 socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa)); |
| 63 memmove(reinterpret_cast<void*>(&addr_), sa, salen); | 63 memmove(reinterpret_cast<void*>(&addr_), sa, salen); |
| 64 } | 64 } |
| 65 | 65 |
| 66 | 66 |
| 67 bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) { | 67 bool BaseSocket::FormatNumericAddress(const RawAddr& addr, |
| 68 char* address, |
| 69 int len) { |
| 68 socklen_t salen = SocketAddress::GetAddrLength(addr); | 70 socklen_t salen = SocketAddress::GetAddrLength(addr); |
| 69 LOG_INFO("Socket::FormatNumericAddress: calling getnameinfo\n"); | 71 LOG_INFO("BaseSocket::FormatNumericAddress: calling getnameinfo\n"); |
| 70 return (NO_RETRY_EXPECTED(getnameinfo(&addr.addr, salen, address, len, NULL, | 72 return (NO_RETRY_EXPECTED(getnameinfo(&addr.addr, salen, address, len, NULL, |
| 71 0, NI_NUMERICHOST) == 0)); | 73 0, NI_NUMERICHOST) == 0)); |
| 72 } | 74 } |
| 73 | 75 |
| 74 | 76 |
| 75 Socket::Socket(intptr_t fd) | 77 Socket::Socket(intptr_t fd) |
| 76 : ReferenceCounted(), fd_(fd), port_(ILLEGAL_PORT) {} | 78 : ReferenceCounted(), fd_(fd), port_(ILLEGAL_PORT) {} |
| 77 | 79 |
| 78 | 80 |
| 79 void Socket::SetClosedFd() { | 81 void Socket::SetClosedFd() { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 LOG_ERR("CreateConnect: FDUtils::SetNonBlocking(%ld) failed\n", fd); | 128 LOG_ERR("CreateConnect: FDUtils::SetNonBlocking(%ld) failed\n", fd); |
| 127 FDUtils::SaveErrorAndClose(fd); | 129 FDUtils::SaveErrorAndClose(fd); |
| 128 return -1; | 130 return -1; |
| 129 } | 131 } |
| 130 return Connect(fd, addr); | 132 return Connect(fd, addr); |
| 131 } | 133 } |
| 132 | 134 |
| 133 | 135 |
| 134 intptr_t Socket::CreateBindConnect(const RawAddr& addr, | 136 intptr_t Socket::CreateBindConnect(const RawAddr& addr, |
| 135 const RawAddr& source_addr) { | 137 const RawAddr& source_addr) { |
| 136 LOG_ERR("Socket::CreateBindConnect is unimplemented\n"); | 138 LOG_ERR("BaseSocket::CreateBindConnect is unimplemented\n"); |
| 137 UNIMPLEMENTED(); | 139 UNIMPLEMENTED(); |
| 138 return -1; | 140 return -1; |
| 139 } | 141 } |
| 140 | 142 |
| 141 | 143 |
| 142 bool Socket::IsBindError(intptr_t error_number) { | 144 bool BaseSocket::IsBindError(intptr_t error_number) { |
| 143 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL || | 145 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL || |
| 144 error_number == EINVAL; | 146 error_number == EINVAL; |
| 145 } | 147 } |
| 146 | 148 |
| 147 | 149 |
| 148 intptr_t Socket::Available(intptr_t fd) { | 150 intptr_t BaseSocket::Available(intptr_t fd) { |
| 149 intptr_t available = FDUtils::AvailableBytes(fd); | 151 intptr_t available = FDUtils::AvailableBytes(fd); |
| 150 LOG_INFO("Socket::Available(%ld) = %ld\n", fd, available); | 152 LOG_INFO("BaseSocket::Available(%ld) = %ld\n", fd, available); |
| 151 return available; | 153 return available; |
| 152 } | 154 } |
| 153 | 155 |
| 154 | 156 |
| 155 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 157 intptr_t BaseSocket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
| 156 ASSERT(fd >= 0); | 158 ASSERT(fd >= 0); |
| 157 LOG_INFO("Socket::Read: calling read(%ld, %p, %ld)\n", fd, buffer, num_bytes); | 159 LOG_INFO("BaseSocket::Read: calling read(%ld, %p, %ld)\n", fd, buffer, |
| 160 num_bytes); |
| 158 ssize_t read_bytes = NO_RETRY_EXPECTED(read(fd, buffer, num_bytes)); | 161 ssize_t read_bytes = NO_RETRY_EXPECTED(read(fd, buffer, num_bytes)); |
| 159 ASSERT(EAGAIN == EWOULDBLOCK); | 162 ASSERT(EAGAIN == EWOULDBLOCK); |
| 160 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { | 163 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 161 // If the read would block we need to retry and therefore return 0 | 164 // If the read would block we need to retry and therefore return 0 |
| 162 // as the number of bytes written. | 165 // as the number of bytes written. |
| 163 read_bytes = 0; | 166 read_bytes = 0; |
| 164 } else if (read_bytes == -1) { | 167 } else if (read_bytes == -1) { |
| 165 LOG_ERR("Socket::Read: read(%ld, %p, %ld) failed\n", fd, buffer, num_bytes); | 168 LOG_ERR("BaseSocket::Read: read(%ld, %p, %ld) failed\n", fd, buffer, |
| 169 num_bytes); |
| 166 } else { | 170 } else { |
| 167 LOG_INFO("Socket::Read: read(%ld, %p, %ld) succeeded\n", fd, buffer, | 171 LOG_INFO("BaseSocket::Read: read(%ld, %p, %ld) succeeded\n", fd, buffer, |
| 168 num_bytes); | 172 num_bytes); |
| 169 } | 173 } |
| 170 return read_bytes; | 174 return read_bytes; |
| 171 } | 175 } |
| 172 | 176 |
| 173 | 177 |
| 174 intptr_t Socket::RecvFrom(intptr_t fd, | 178 intptr_t BaseSocket::RecvFrom(intptr_t fd, |
| 175 void* buffer, | 179 void* buffer, |
| 176 intptr_t num_bytes, | 180 intptr_t num_bytes, |
| 177 RawAddr* addr) { | 181 RawAddr* addr) { |
| 178 LOG_ERR("Socket::RecvFrom is unimplemented\n"); | 182 LOG_ERR("BaseSocket::RecvFrom is unimplemented\n"); |
| 179 UNIMPLEMENTED(); | 183 UNIMPLEMENTED(); |
| 180 return -1; | 184 return -1; |
| 181 } | 185 } |
| 182 | 186 |
| 183 | 187 |
| 184 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { | 188 intptr_t BaseSocket::Write(intptr_t fd, |
| 189 const void* buffer, |
| 190 intptr_t num_bytes) { |
| 185 ASSERT(fd >= 0); | 191 ASSERT(fd >= 0); |
| 186 LOG_INFO("Socket::Write: calling write(%ld, %p, %ld)\n", fd, buffer, | 192 LOG_INFO("BaseSocket::Write: calling write(%ld, %p, %ld)\n", fd, buffer, |
| 187 num_bytes); | 193 num_bytes); |
| 188 ssize_t written_bytes = NO_RETRY_EXPECTED(write(fd, buffer, num_bytes)); | 194 ssize_t written_bytes = NO_RETRY_EXPECTED(write(fd, buffer, num_bytes)); |
| 189 ASSERT(EAGAIN == EWOULDBLOCK); | 195 ASSERT(EAGAIN == EWOULDBLOCK); |
| 190 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { | 196 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { |
| 191 // If the would block we need to retry and therefore return 0 as | 197 // If the would block we need to retry and therefore return 0 as |
| 192 // the number of bytes written. | 198 // the number of bytes written. |
| 193 written_bytes = 0; | 199 written_bytes = 0; |
| 194 } else if (written_bytes == -1) { | 200 } else if (written_bytes == -1) { |
| 195 LOG_ERR("Socket::Write: write(%ld, %p, %ld) failed\n", fd, buffer, | 201 LOG_ERR("BaseSocket::Write: write(%ld, %p, %ld) failed\n", fd, buffer, |
| 196 num_bytes); | 202 num_bytes); |
| 197 } else { | 203 } else { |
| 198 LOG_INFO("Socket::Write: write(%ld, %p, %ld) succeeded\n", fd, buffer, | 204 LOG_INFO("BaseSocket::Write: write(%ld, %p, %ld) succeeded\n", fd, buffer, |
| 199 num_bytes); | 205 num_bytes); |
| 200 } | 206 } |
| 201 return written_bytes; | 207 return written_bytes; |
| 202 } | 208 } |
| 203 | 209 |
| 204 | 210 |
| 205 intptr_t Socket::SendTo(intptr_t fd, | 211 intptr_t BaseSocket::SendTo(intptr_t fd, |
| 206 const void* buffer, | 212 const void* buffer, |
| 207 intptr_t num_bytes, | 213 intptr_t num_bytes, |
| 208 const RawAddr& addr) { | 214 const RawAddr& addr) { |
| 209 LOG_ERR("Socket::SendTo is unimplemented\n"); | 215 LOG_ERR("BaseSocket::SendTo is unimplemented\n"); |
| 210 UNIMPLEMENTED(); | 216 UNIMPLEMENTED(); |
| 211 return -1; | 217 return -1; |
| 212 } | 218 } |
| 213 | 219 |
| 214 | 220 |
| 215 intptr_t Socket::GetPort(intptr_t fd) { | 221 intptr_t BaseSocket::GetPort(intptr_t fd) { |
| 216 ASSERT(fd >= 0); | 222 ASSERT(fd >= 0); |
| 217 RawAddr raw; | 223 RawAddr raw; |
| 218 socklen_t size = sizeof(raw); | 224 socklen_t size = sizeof(raw); |
| 219 LOG_INFO("Socket::GetPort: calling getsockname(%ld)\n", fd); | 225 LOG_INFO("BaseSocket::GetPort: calling getsockname(%ld)\n", fd); |
| 220 if (NO_RETRY_EXPECTED(getsockname(fd, &raw.addr, &size))) { | 226 if (NO_RETRY_EXPECTED(getsockname(fd, &raw.addr, &size))) { |
| 221 return 0; | 227 return 0; |
| 222 } | 228 } |
| 223 return SocketAddress::GetAddrPort(raw); | 229 return SocketAddress::GetAddrPort(raw); |
| 224 } | 230 } |
| 225 | 231 |
| 226 | 232 |
| 227 SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) { | 233 SocketAddress* BaseSocket::GetRemotePeer(intptr_t fd, intptr_t* port) { |
| 228 ASSERT(fd >= 0); | 234 ASSERT(fd >= 0); |
| 229 RawAddr raw; | 235 RawAddr raw; |
| 230 socklen_t size = sizeof(raw); | 236 socklen_t size = sizeof(raw); |
| 231 if (NO_RETRY_EXPECTED(getpeername(fd, &raw.addr, &size))) { | 237 if (NO_RETRY_EXPECTED(getpeername(fd, &raw.addr, &size))) { |
| 232 return NULL; | 238 return NULL; |
| 233 } | 239 } |
| 234 *port = SocketAddress::GetAddrPort(raw); | 240 *port = SocketAddress::GetAddrPort(raw); |
| 235 return new SocketAddress(&raw.addr); | 241 return new SocketAddress(&raw.addr); |
| 236 } | 242 } |
| 237 | 243 |
| 238 | 244 |
| 239 void Socket::GetError(intptr_t fd, OSError* os_error) { | 245 void BaseSocket::GetError(intptr_t fd, OSError* os_error) { |
| 240 LOG_ERR("Socket::GetError is unimplemented\n"); | 246 LOG_ERR("BaseSocket::GetError is unimplemented\n"); |
| 241 UNIMPLEMENTED(); | 247 UNIMPLEMENTED(); |
| 242 } | 248 } |
| 243 | 249 |
| 244 | 250 |
| 245 int Socket::GetType(intptr_t fd) { | 251 int BaseSocket::GetType(intptr_t fd) { |
| 246 LOG_ERR("Socket::GetType is unimplemented\n"); | 252 LOG_ERR("BaseSocket::GetType is unimplemented\n"); |
| 247 UNIMPLEMENTED(); | 253 UNIMPLEMENTED(); |
| 248 return File::kOther; | 254 return File::kOther; |
| 249 } | 255 } |
| 250 | 256 |
| 251 | 257 |
| 252 intptr_t Socket::GetStdioHandle(intptr_t num) { | 258 intptr_t BaseSocket::GetStdioHandle(intptr_t num) { |
| 253 LOG_ERR("Socket::GetStdioHandle is unimplemented\n"); | 259 LOG_ERR("BaseSocket::GetStdioHandle is unimplemented\n"); |
| 254 UNIMPLEMENTED(); | 260 UNIMPLEMENTED(); |
| 255 return num; | 261 return num; |
| 256 } | 262 } |
| 257 | 263 |
| 258 | 264 |
| 259 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, | 265 AddressList<SocketAddress>* BaseSocket::LookupAddress(const char* host, |
| 260 int type, | 266 int type, |
| 261 OSError** os_error) { | 267 OSError** os_error) { |
| 262 // Perform a name lookup for a host name. | 268 // Perform a name lookup for a host name. |
| 263 struct addrinfo hints; | 269 struct addrinfo hints; |
| 264 memset(&hints, 0, sizeof(hints)); | 270 memset(&hints, 0, sizeof(hints)); |
| 265 hints.ai_family = SocketAddress::FromType(type); | 271 hints.ai_family = SocketAddress::FromType(type); |
| 266 hints.ai_socktype = SOCK_STREAM; | 272 hints.ai_socktype = SOCK_STREAM; |
| 267 hints.ai_flags = AI_ADDRCONFIG; | 273 hints.ai_flags = AI_ADDRCONFIG; |
| 268 hints.ai_protocol = IPPROTO_TCP; | 274 hints.ai_protocol = IPPROTO_TCP; |
| 269 struct addrinfo* info = NULL; | 275 struct addrinfo* info = NULL; |
| 270 LOG_INFO("Socket::LookupAddress: calling getaddrinfo\n"); | 276 LOG_INFO("BaseSocket::LookupAddress: calling getaddrinfo\n"); |
| 271 int status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info)); | 277 int status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info)); |
| 272 if (status != 0) { | 278 if (status != 0) { |
| 273 // We failed, try without AI_ADDRCONFIG. This can happen when looking up | 279 // We failed, try without AI_ADDRCONFIG. This can happen when looking up |
| 274 // e.g. '::1', when there are no global IPv6 addresses. | 280 // e.g. '::1', when there are no global IPv6 addresses. |
| 275 hints.ai_flags = 0; | 281 hints.ai_flags = 0; |
| 276 LOG_INFO("Socket::LookupAddress: calling getaddrinfo again\n"); | 282 LOG_INFO("BaseSocket::LookupAddress: calling getaddrinfo again\n"); |
| 277 status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info)); | 283 status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info)); |
| 278 if (status != 0) { | 284 if (status != 0) { |
| 279 ASSERT(*os_error == NULL); | 285 ASSERT(*os_error == NULL); |
| 280 *os_error = | 286 *os_error = |
| 281 new OSError(status, gai_strerror(status), OSError::kGetAddressInfo); | 287 new OSError(status, gai_strerror(status), OSError::kGetAddressInfo); |
| 282 return NULL; | 288 return NULL; |
| 283 } | 289 } |
| 284 } | 290 } |
| 285 intptr_t count = 0; | 291 intptr_t count = 0; |
| 286 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { | 292 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { |
| 287 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) { | 293 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) { |
| 288 count++; | 294 count++; |
| 289 } | 295 } |
| 290 } | 296 } |
| 291 intptr_t i = 0; | 297 intptr_t i = 0; |
| 292 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); | 298 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); |
| 293 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { | 299 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { |
| 294 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) { | 300 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) { |
| 295 addresses->SetAt(i, new SocketAddress(c->ai_addr)); | 301 addresses->SetAt(i, new SocketAddress(c->ai_addr)); |
| 296 i++; | 302 i++; |
| 297 } | 303 } |
| 298 } | 304 } |
| 299 freeaddrinfo(info); | 305 freeaddrinfo(info); |
| 300 return addresses; | 306 return addresses; |
| 301 } | 307 } |
| 302 | 308 |
| 303 | 309 |
| 304 bool Socket::ReverseLookup(const RawAddr& addr, | 310 bool BaseSocket::ReverseLookup(const RawAddr& addr, |
| 305 char* host, | 311 char* host, |
| 306 intptr_t host_len, | 312 intptr_t host_len, |
| 307 OSError** os_error) { | 313 OSError** os_error) { |
| 308 LOG_ERR("Socket::ReverseLookup is unimplemented\n"); | 314 LOG_ERR("BaseSocket::ReverseLookup is unimplemented\n"); |
| 309 UNIMPLEMENTED(); | 315 UNIMPLEMENTED(); |
| 310 return false; | 316 return false; |
| 311 } | 317 } |
| 312 | 318 |
| 313 | 319 |
| 314 bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) { | 320 bool BaseSocket::ParseAddress(int type, const char* address, RawAddr* addr) { |
| 315 int result; | 321 int result; |
| 316 if (type == SocketAddress::TYPE_IPV4) { | 322 if (type == SocketAddress::TYPE_IPV4) { |
| 317 result = NO_RETRY_EXPECTED(inet_pton(AF_INET, address, &addr->in.sin_addr)); | 323 result = NO_RETRY_EXPECTED(inet_pton(AF_INET, address, &addr->in.sin_addr)); |
| 318 } else { | 324 } else { |
| 319 ASSERT(type == SocketAddress::TYPE_IPV6); | 325 ASSERT(type == SocketAddress::TYPE_IPV6); |
| 320 result = | 326 result = |
| 321 NO_RETRY_EXPECTED(inet_pton(AF_INET6, address, &addr->in6.sin6_addr)); | 327 NO_RETRY_EXPECTED(inet_pton(AF_INET6, address, &addr->in6.sin6_addr)); |
| 322 } | 328 } |
| 323 return (result == 1); | 329 return (result == 1); |
| 324 } | 330 } |
| 325 | 331 |
| 326 | 332 |
| 327 intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) { | 333 intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) { |
| 328 LOG_ERR("Socket::CreateBindDatagram is unimplemented\n"); | 334 LOG_ERR("BaseSocket::CreateBindDatagram is unimplemented\n"); |
| 329 UNIMPLEMENTED(); | 335 UNIMPLEMENTED(); |
| 330 return -1; | 336 return -1; |
| 331 } | 337 } |
| 332 | 338 |
| 333 | 339 |
| 334 bool Socket::ListInterfacesSupported() { | 340 bool BaseSocket::ListInterfacesSupported() { |
| 335 return false; | 341 return false; |
| 336 } | 342 } |
| 337 | 343 |
| 338 | 344 |
| 339 AddressList<InterfaceSocketAddress>* Socket::ListInterfaces( | 345 AddressList<InterfaceSocketAddress>* BaseSocket::ListInterfaces( |
| 340 int type, | 346 int type, |
| 341 OSError** os_error) { | 347 OSError** os_error) { |
| 342 UNIMPLEMENTED(); | 348 UNIMPLEMENTED(); |
| 343 return NULL; | 349 return NULL; |
| 344 } | 350 } |
| 345 | 351 |
| 346 | 352 |
| 347 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr, | 353 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr, |
| 348 intptr_t backlog, | 354 intptr_t backlog, |
| 349 bool v6_only) { | 355 bool v6_only) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 377 if (NO_RETRY_EXPECTED( | 383 if (NO_RETRY_EXPECTED( |
| 378 bind(fd, &addr.addr, SocketAddress::GetAddrLength(addr))) < 0) { | 384 bind(fd, &addr.addr, SocketAddress::GetAddrLength(addr))) < 0) { |
| 379 LOG_ERR("ServerSocket::CreateBindListen: bind(%ld) failed\n", fd); | 385 LOG_ERR("ServerSocket::CreateBindListen: bind(%ld) failed\n", fd); |
| 380 FDUtils::SaveErrorAndClose(fd); | 386 FDUtils::SaveErrorAndClose(fd); |
| 381 return -1; | 387 return -1; |
| 382 } | 388 } |
| 383 LOG_INFO("ServerSocket::CreateBindListen: bind(%ld) succeeded\n", fd); | 389 LOG_INFO("ServerSocket::CreateBindListen: bind(%ld) succeeded\n", fd); |
| 384 | 390 |
| 385 // Test for invalid socket port 65535 (some browsers disallow it). | 391 // Test for invalid socket port 65535 (some browsers disallow it). |
| 386 if ((SocketAddress::GetAddrPort(addr) == 0) && | 392 if ((SocketAddress::GetAddrPort(addr) == 0) && |
| 387 (Socket::GetPort(fd) == 65535)) { | 393 (BaseSocket::GetPort(fd) == 65535)) { |
| 388 // Don't close the socket until we have created a new socket, ensuring | 394 // Don't close the socket until we have created a new socket, ensuring |
| 389 // that we do not get the bad port number again. | 395 // that we do not get the bad port number again. |
| 390 intptr_t new_fd = CreateBindListen(addr, backlog, v6_only); | 396 intptr_t new_fd = CreateBindListen(addr, backlog, v6_only); |
| 391 FDUtils::SaveErrorAndClose(fd); | 397 FDUtils::SaveErrorAndClose(fd); |
| 392 return new_fd; | 398 return new_fd; |
| 393 } | 399 } |
| 394 | 400 |
| 395 LOG_INFO("ServerSocket::CreateBindListen: calling listen(%ld)\n", fd); | 401 LOG_INFO("ServerSocket::CreateBindListen: calling listen(%ld)\n", fd); |
| 396 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { | 402 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { |
| 397 LOG_ERR("ServerSocket::CreateBindListen: listen failed(%ld)\n", fd); | 403 LOG_ERR("ServerSocket::CreateBindListen: listen failed(%ld)\n", fd); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 if (!FDUtils::SetNonBlocking(socket)) { | 457 if (!FDUtils::SetNonBlocking(socket)) { |
| 452 LOG_ERR("FDUtils::SetNonBlocking(%ld) failed\n", socket); | 458 LOG_ERR("FDUtils::SetNonBlocking(%ld) failed\n", socket); |
| 453 FDUtils::SaveErrorAndClose(socket); | 459 FDUtils::SaveErrorAndClose(socket); |
| 454 return -1; | 460 return -1; |
| 455 } | 461 } |
| 456 } | 462 } |
| 457 return socket; | 463 return socket; |
| 458 } | 464 } |
| 459 | 465 |
| 460 | 466 |
| 461 void Socket::Close(intptr_t fd) { | 467 void BaseSocket::Close(intptr_t fd) { |
| 462 ASSERT(fd >= 0); | 468 ASSERT(fd >= 0); |
| 463 NO_RETRY_EXPECTED(close(fd)); | 469 NO_RETRY_EXPECTED(close(fd)); |
| 464 } | 470 } |
| 465 | 471 |
| 466 | 472 |
| 467 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { | 473 bool BaseSocket::GetNoDelay(intptr_t fd, bool* enabled) { |
| 468 LOG_ERR("Socket::GetNoDelay is unimplemented\n"); | 474 LOG_ERR("BaseSocket::GetNoDelay is unimplemented\n"); |
| 469 UNIMPLEMENTED(); | 475 UNIMPLEMENTED(); |
| 470 return false; | 476 return false; |
| 471 } | 477 } |
| 472 | 478 |
| 473 | 479 |
| 474 bool Socket::SetNoDelay(intptr_t fd, bool enabled) { | 480 bool BaseSocket::SetNoDelay(intptr_t fd, bool enabled) { |
| 475 int on = enabled ? 1 : 0; | 481 int on = enabled ? 1 : 0; |
| 476 return NO_RETRY_EXPECTED(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, | 482 return NO_RETRY_EXPECTED(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, |
| 477 reinterpret_cast<char*>(&on), | 483 reinterpret_cast<char*>(&on), |
| 478 sizeof(on))) == 0; | 484 sizeof(on))) == 0; |
| 479 } | 485 } |
| 480 | 486 |
| 481 | 487 |
| 482 bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) { | 488 bool BaseSocket::GetMulticastLoop(intptr_t fd, |
| 483 LOG_ERR("Socket::GetMulticastLoop is unimplemented\n"); | 489 intptr_t protocol, |
| 490 bool* enabled) { |
| 491 LOG_ERR("BaseSocket::GetMulticastLoop is unimplemented\n"); |
| 484 UNIMPLEMENTED(); | 492 UNIMPLEMENTED(); |
| 485 return false; | 493 return false; |
| 486 } | 494 } |
| 487 | 495 |
| 488 | 496 |
| 489 bool Socket::SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled) { | 497 bool BaseSocket::SetMulticastLoop(intptr_t fd, |
| 490 LOG_ERR("Socket::SetMulticastLoop is unimplemented\n"); | 498 intptr_t protocol, |
| 499 bool enabled) { |
| 500 LOG_ERR("BaseSocket::SetMulticastLoop is unimplemented\n"); |
| 491 UNIMPLEMENTED(); | 501 UNIMPLEMENTED(); |
| 492 return false; | 502 return false; |
| 493 } | 503 } |
| 494 | 504 |
| 495 | 505 |
| 496 bool Socket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) { | 506 bool BaseSocket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) { |
| 497 LOG_ERR("Socket::GetMulticastHops is unimplemented\n"); | 507 LOG_ERR("BaseSocket::GetMulticastHops is unimplemented\n"); |
| 498 UNIMPLEMENTED(); | 508 UNIMPLEMENTED(); |
| 499 return false; | 509 return false; |
| 500 } | 510 } |
| 501 | 511 |
| 502 | 512 |
| 503 bool Socket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) { | 513 bool BaseSocket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) { |
| 504 LOG_ERR("Socket::SetMulticastHops is unimplemented\n"); | 514 LOG_ERR("BaseSocket::SetMulticastHops is unimplemented\n"); |
| 505 UNIMPLEMENTED(); | 515 UNIMPLEMENTED(); |
| 506 return false; | 516 return false; |
| 507 } | 517 } |
| 508 | 518 |
| 509 | 519 |
| 510 bool Socket::GetBroadcast(intptr_t fd, bool* enabled) { | 520 bool BaseSocket::GetBroadcast(intptr_t fd, bool* enabled) { |
| 511 LOG_ERR("Socket::GetBroadcast is unimplemented\n"); | 521 LOG_ERR("BaseSocket::GetBroadcast is unimplemented\n"); |
| 512 UNIMPLEMENTED(); | 522 UNIMPLEMENTED(); |
| 513 return false; | 523 return false; |
| 514 } | 524 } |
| 515 | 525 |
| 516 | 526 |
| 517 bool Socket::SetBroadcast(intptr_t fd, bool enabled) { | 527 bool BaseSocket::SetBroadcast(intptr_t fd, bool enabled) { |
| 518 LOG_ERR("Socket::SetBroadcast is unimplemented\n"); | 528 LOG_ERR("BaseSocket::SetBroadcast is unimplemented\n"); |
| 519 UNIMPLEMENTED(); | 529 UNIMPLEMENTED(); |
| 520 return false; | 530 return false; |
| 521 } | 531 } |
| 522 | 532 |
| 523 | 533 |
| 524 bool Socket::JoinMulticast(intptr_t fd, | 534 bool BaseSocket::JoinMulticast(intptr_t fd, |
| 525 const RawAddr& addr, | 535 const RawAddr& addr, |
| 526 const RawAddr&, | 536 const RawAddr&, |
| 527 int interfaceIndex) { | 537 int interfaceIndex) { |
| 528 LOG_ERR("Socket::JoinMulticast is unimplemented\n"); | 538 LOG_ERR("BaseSocket::JoinMulticast is unimplemented\n"); |
| 529 UNIMPLEMENTED(); | 539 UNIMPLEMENTED(); |
| 530 return false; | 540 return false; |
| 531 } | 541 } |
| 532 | 542 |
| 533 | 543 |
| 534 bool Socket::LeaveMulticast(intptr_t fd, | 544 bool BaseSocket::LeaveMulticast(intptr_t fd, |
| 535 const RawAddr& addr, | 545 const RawAddr& addr, |
| 536 const RawAddr&, | 546 const RawAddr&, |
| 537 int interfaceIndex) { | 547 int interfaceIndex) { |
| 538 LOG_ERR("Socket::LeaveMulticast is unimplemented\n"); | 548 LOG_ERR("BaseSocket::LeaveMulticast is unimplemented\n"); |
| 539 UNIMPLEMENTED(); | 549 UNIMPLEMENTED(); |
| 540 return false; | 550 return false; |
| 541 } | 551 } |
| 542 | 552 |
| 543 } // namespace bin | 553 } // namespace bin |
| 544 } // namespace dart | 554 } // namespace dart |
| 545 | 555 |
| 546 #endif // defined(HOST_OS_FUCHSIA) | 556 #endif // defined(HOST_OS_FUCHSIA) |
| 547 | 557 |
| 548 #endif // !defined(DART_IO_DISABLED) | 558 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |