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