Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Side by Side Diff: runtime/bin/socket_fuchsia.cc

Issue 2515643004: Fuchsia: Partial implementation of dart:io sockets (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(TARGET_OS_FUCHSIA) 8 #if defined(TARGET_OS_FUCHSIA)
9 9
10 #include "bin/socket.h" 10 #include "bin/socket.h"
11 #include "bin/socket_fuchsia.h" 11 #include "bin/socket_fuchsia.h"
12 12
13 #include <errno.h> // NOLINT
14 #include <fcntl.h> // NOLINT
15 #include <ifaddrs.h> // NOLINT
16 #include <net/if.h> // NOLINT
17 #include <netinet/tcp.h> // NOLINT
18 #include <stdio.h> // NOLINT
19 #include <stdlib.h> // NOLINT
20 #include <string.h> // NOLINT
21 #include <sys/ioctl.h> // NOLINT
22 #include <sys/stat.h> // NOLINT
23 #include <unistd.h> // NOLINT
24
25 #include "bin/fdutils.h"
13 #include "bin/file.h" 26 #include "bin/file.h"
27 #include "platform/signal_blocker.h"
28
29 // #define SOCKET_LOG_INFO 1
30 // #define SOCKET_LOG_ERROR 1
31
32 // 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.
34 #if defined(SOCKET_LOG_INFO) || defined(SOCKET_LOG_ERROR)
35 #define LOG_ERR(msg, ...) \
36 { \
37 int err = errno; \
38 Log::PrintErr("Dart Socket ERROR: %s:%d: " msg, \
39 __FILE__, __LINE__, ##__VA_ARGS__); \
40 errno = err; \
41 }
42 #if defined(SOCKET_LOG_INFO)
43 #define LOG_INFO(msg, ...) \
44 Log::Print("Dart Socket INFO: %s:%d: " msg, __FILE__, __LINE__, ##__VA_ARGS__)
45 #else
46 #define LOG_INFO(msg, ...)
47 #endif // defined(SOCKET_LOG_INFO)
48 #else
49 #define LOG_ERR(msg, ...)
50 #define LOG_INFO(msg, ...)
51 #endif // defined(SOCKET_LOG_INFO) || defined(SOCKET_LOG_ERROR)
14 52
15 namespace dart { 53 namespace dart {
16 namespace bin { 54 namespace bin {
17 55
18 SocketAddress::SocketAddress(struct sockaddr* sa) { 56 SocketAddress::SocketAddress(struct sockaddr* sa) {
19 UNIMPLEMENTED(); 57 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
58 if (!Socket::FormatNumericAddress(
59 *reinterpret_cast<RawAddr*>(sa), as_string_, 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);
20 } 64 }
21 65
22 66
23 bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) { 67 bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) {
24 UNIMPLEMENTED(); 68 socklen_t salen = SocketAddress::GetAddrLength(addr);
25 return false; 69 LOG_INFO("Socket::FormatNumericAddress: calling getnameinfo\n");
70 return (NO_RETRY_EXPECTED(getnameinfo(
71 &addr.addr, salen, address, len, NULL, 0, NI_NUMERICHOST) == 0));
26 } 72 }
27 73
28 74
29 bool Socket::Initialize() { 75 bool Socket::Initialize() {
30 UNIMPLEMENTED(); 76 // Nothing to do on Fuchsia.
31 return true; 77 return true;
32 } 78 }
33 79
34 80
81 static intptr_t Create(const RawAddr& addr) {
82 LOG_INFO("Create: calling socket(SOCK_STREAM)\n");
83 intptr_t fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0));
84 if (fd < 0) {
85 LOG_ERR("Create: socket(SOCK_STREAM) failed\n");
86 return -1;
87 }
88 LOG_INFO("Create: socket(SOCK_STREAM) -> fd %ld\n", fd);
89 if (!FDUtils::SetCloseOnExec(fd)) {
90 LOG_ERR("Create: FDUtils::SetCloseOnExec(%ld) failed\n", fd);
91 FDUtils::SaveErrorAndClose(fd);
92 return -1;
93 }
94 return fd;
95 }
96
97
98 static intptr_t CheckConnect(intptr_t fd) {
99 int val;
100 socklen_t vallen = sizeof(val);
101 LOG_INFO("CheckConnect: calling getsockopt(%ld)\n", fd);
102 intptr_t result = getsockopt(fd, SOL_SOCKET, SO_ERROR, &val, &vallen);
103 if (result != 0) {
104 FATAL1("CheckConnect: getsockopt(%ld) failed\n", fd);
105 } else if (vallen != sizeof(val)) {
106 FATAL1("CheckConnect: getsockopt(%ld) vallen != sizeof(val)!?!?\n", fd);
107 } else if (val != 0) {
108 LOG_ERR("CheckConnect: getsockopt(%ld) val = %d\n", fd, val);
109 return val;
110 }
111 LOG_INFO("CheckConnect: getsockopt(%ld) connected\n", fd);
112 return 0;
113 }
114
115
116 static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
117 LOG_INFO("Connect: calling connect(%ld)\n", fd);
118 intptr_t result = NO_RETRY_EXPECTED(
119 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr)));
120 if ((result == 0) || (errno == EINPROGRESS)) {
121 LOG_INFO("Connect: connect(%ld) succeeded\n", fd);
122 intptr_t error = 0;
123 // TODO(US-87): When the issue is resolved this check is no longer needed.
124 while ((error = CheckConnect(fd)) != 0) {
125 if (error != EINPROGRESS) {
126 errno = error;
127 FDUtils::SaveErrorAndClose(fd);
128 return -1;
129 }
130 }
131 return fd;
132 }
133 LOG_ERR("Connect: connect(%ld) failed\n", fd);
134 FDUtils::SaveErrorAndClose(fd);
135 return -1;
136 }
137
138
35 intptr_t Socket::CreateConnect(const RawAddr& addr) { 139 intptr_t Socket::CreateConnect(const RawAddr& addr) {
36 UNIMPLEMENTED(); 140 intptr_t fd = Create(addr);
37 return -1; 141 if (fd < 0) {
142 return fd;
143 }
144 if (!FDUtils::SetNonBlocking(fd)) {
145 LOG_ERR("CreateConnect: FDUtils::SetNonBlocking(%ld) failed\n", fd);
146 FDUtils::SaveErrorAndClose(fd);
147 return -1;
148 }
149 return Connect(fd, addr);
38 } 150 }
39 151
40 152
41 intptr_t Socket::CreateBindConnect(const RawAddr& addr, 153 intptr_t Socket::CreateBindConnect(const RawAddr& addr,
42 const RawAddr& source_addr) { 154 const RawAddr& source_addr) {
155 LOG_ERR("Socket::CreateBindConnect is unimplemented\n");
43 UNIMPLEMENTED(); 156 UNIMPLEMENTED();
44 return -1; 157 return -1;
45 } 158 }
46 159
47 160
48 bool Socket::IsBindError(intptr_t error_number) { 161 bool Socket::IsBindError(intptr_t error_number) {
49 UNIMPLEMENTED(); 162 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL ||
50 return false; 163 error_number == EINVAL;
51 } 164 }
52 165
53 166
54 intptr_t Socket::Available(intptr_t fd) { 167 intptr_t Socket::Available(intptr_t fd) {
55 UNIMPLEMENTED(); 168 return FDUtils::AvailableBytes(fd);
56 return -1;
57 } 169 }
58 170
59 171
60 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { 172 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
61 UNIMPLEMENTED(); 173 ASSERT(fd >= 0);
62 return -1; 174 LOG_INFO("Socket::Read: calling read(%ld, %p, %ld)\n", fd, buffer, num_bytes);
175 ssize_t read_bytes = NO_RETRY_EXPECTED(read(fd, buffer, num_bytes));
176 ASSERT(EAGAIN == EWOULDBLOCK);
177 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) {
178 // If the read would block we need to retry and therefore return 0
179 // as the number of bytes written.
180 read_bytes = 0;
181 } else if (read_bytes == -1) {
182 LOG_ERR("Socket::Read: read(%ld, %p, %ld) failed\n", fd, buffer, num_bytes);
183 } else {
184 LOG_INFO("Socket::Read: read(%ld, %p, %ld) succeeded\n",
185 fd, buffer, num_bytes);
186 }
187 return read_bytes;
63 } 188 }
64 189
65 190
66 intptr_t Socket::RecvFrom(intptr_t fd, 191 intptr_t Socket::RecvFrom(intptr_t fd,
67 void* buffer, 192 void* buffer,
68 intptr_t num_bytes, 193 intptr_t num_bytes,
69 RawAddr* addr) { 194 RawAddr* addr) {
195 LOG_ERR("Socket::RecvFrom is unimplemented\n");
70 UNIMPLEMENTED(); 196 UNIMPLEMENTED();
71 return -1; 197 return -1;
72 } 198 }
73 199
74 200
75 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { 201 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
76 UNIMPLEMENTED(); 202 ASSERT(fd >= 0);
77 return -1; 203 LOG_INFO("Socket::Write: calling write(%ld, %p, %ld)\n",
204 fd, buffer, num_bytes);
205 ssize_t written_bytes = NO_RETRY_EXPECTED(write(fd, buffer, num_bytes));
206 ASSERT(EAGAIN == EWOULDBLOCK);
207 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) {
208 // If the would block we need to retry and therefore return 0 as
209 // the number of bytes written.
210 written_bytes = 0;
211 } else if (written_bytes == -1) {
212 LOG_ERR("Socket::Write: write(%ld, %p, %ld) failed\n",
213 fd, buffer, num_bytes);
214 } else {
215 LOG_INFO("Socket::Write: write(%ld, %p, %ld) succeeded\n",
216 fd, buffer, num_bytes);
217 }
218 return written_bytes;
78 } 219 }
79 220
80 221
81 intptr_t Socket::SendTo(intptr_t fd, 222 intptr_t Socket::SendTo(intptr_t fd,
82 const void* buffer, 223 const void* buffer,
83 intptr_t num_bytes, 224 intptr_t num_bytes,
84 const RawAddr& addr) { 225 const RawAddr& addr) {
226 LOG_ERR("Socket::SendTo is unimplemented\n");
85 UNIMPLEMENTED(); 227 UNIMPLEMENTED();
86 return -1; 228 return -1;
87 } 229 }
88 230
89 231
90 intptr_t Socket::GetPort(intptr_t fd) { 232 intptr_t Socket::GetPort(intptr_t fd) {
91 UNIMPLEMENTED(); 233 ASSERT(fd >= 0);
92 return -1; 234 RawAddr raw;
235 socklen_t size = sizeof(raw);
236 LOG_INFO("Socket::GetPort: calling getsockname(%ld)\n", fd);
237 if (NO_RETRY_EXPECTED(getsockname(fd, &raw.addr, &size))) {
238 return 0;
239 }
240 return SocketAddress::GetAddrPort(raw);
93 } 241 }
94 242
95 243
96 SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) { 244 SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) {
245 LOG_ERR("Socket::GetRemotePeer is unimplemented\n");
97 UNIMPLEMENTED(); 246 UNIMPLEMENTED();
98 return NULL; 247 return NULL;
99 } 248 }
100 249
101 250
102 void Socket::GetError(intptr_t fd, OSError* os_error) { 251 void Socket::GetError(intptr_t fd, OSError* os_error) {
252 LOG_ERR("Socket::GetError is unimplemented\n");
103 UNIMPLEMENTED(); 253 UNIMPLEMENTED();
104 } 254 }
105 255
106 256
107 int Socket::GetType(intptr_t fd) { 257 int Socket::GetType(intptr_t fd) {
258 LOG_ERR("Socket::GetType is unimplemented\n");
108 UNIMPLEMENTED(); 259 UNIMPLEMENTED();
109 return File::kOther; 260 return File::kOther;
110 } 261 }
111 262
112 263
113 intptr_t Socket::GetStdioHandle(intptr_t num) { 264 intptr_t Socket::GetStdioHandle(intptr_t num) {
265 LOG_ERR("Socket::GetStdioHandle is unimplemented\n");
114 UNIMPLEMENTED(); 266 UNIMPLEMENTED();
115 return num; 267 return num;
116 } 268 }
117 269
118 270
119 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, 271 AddressList<SocketAddress>* Socket::LookupAddress(const char* host,
120 int type, 272 int type,
121 OSError** os_error) { 273 OSError** os_error) {
122 // UNIMPLEMENTED 274 // Perform a name lookup for a host name.
123 ASSERT(*os_error == NULL); 275 struct addrinfo hints;
124 *os_error = new OSError(-1, 276 memset(&hints, 0, sizeof(hints));
125 "Socket::LookupAddress not implemented in " 277 hints.ai_family = SocketAddress::FromType(type);
126 "Fuchsia Dart VM runtime", 278 hints.ai_socktype = SOCK_STREAM;
127 OSError::kGetAddressInfo); 279 hints.ai_flags = AI_ADDRCONFIG;
128 return NULL; 280 hints.ai_protocol = IPPROTO_TCP;
281 struct addrinfo* info = NULL;
282 LOG_INFO("Socket::LookupAddress: calling getaddrinfo\n");
283 int status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info));
284 if (status != 0) {
285 // We failed, try without AI_ADDRCONFIG. This can happen when looking up
286 // e.g. '::1', when there are no global IPv6 addresses.
287 hints.ai_flags = 0;
288 LOG_INFO("Socket::LookupAddress: calling getaddrinfo again\n");
289 status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info));
290 if (status != 0) {
291 ASSERT(*os_error == NULL);
292 *os_error = new OSError(status,
293 gai_strerror(status),
294 OSError::kGetAddressInfo);
295 return NULL;
296 }
297 }
298 intptr_t count = 0;
299 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
300 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
301 count++;
302 }
303 }
304 intptr_t i = 0;
305 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count);
306 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
307 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
308 addresses->SetAt(i, new SocketAddress(c->ai_addr));
309 i++;
310 }
311 }
312 freeaddrinfo(info);
313 return addresses;
129 } 314 }
130 315
131 316
132 bool Socket::ReverseLookup(const RawAddr& addr, 317 bool Socket::ReverseLookup(const RawAddr& addr,
133 char* host, 318 char* host,
134 intptr_t host_len, 319 intptr_t host_len,
135 OSError** os_error) { 320 OSError** os_error) {
321 LOG_ERR("Socket::ReverseLookup is unimplemented\n");
136 UNIMPLEMENTED(); 322 UNIMPLEMENTED();
137 return false; 323 return false;
138 } 324 }
139 325
140 326
141 bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) { 327 bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) {
328 LOG_ERR("Socket::ParseAddress is unimplemented\n");
142 UNIMPLEMENTED(); 329 UNIMPLEMENTED();
143 return false; 330 return false;
144 } 331 }
145 332
146 333
147 intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) { 334 intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) {
335 LOG_ERR("Socket::CreateBindDatagram is unimplemented\n");
148 UNIMPLEMENTED(); 336 UNIMPLEMENTED();
149 return -1; 337 return -1;
150 } 338 }
151 339
152 340
153 bool Socket::ListInterfacesSupported() { 341 bool Socket::ListInterfacesSupported() {
154 return false; 342 return false;
155 } 343 }
156 344
157 345
158 AddressList<InterfaceSocketAddress>* Socket::ListInterfaces( 346 AddressList<InterfaceSocketAddress>* Socket::ListInterfaces(
159 int type, 347 int type,
160 OSError** os_error) { 348 OSError** os_error) {
161 UNIMPLEMENTED(); 349 UNIMPLEMENTED();
162 return NULL; 350 return NULL;
163 } 351 }
164 352
165 353
166 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr, 354 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
167 intptr_t backlog, 355 intptr_t backlog,
168 bool v6_only) { 356 bool v6_only) {
169 UNIMPLEMENTED(); 357 LOG_INFO("ServerSocket::CreateBindListen: calling socket(SOCK_STREAM)\n");
170 return -1; 358 intptr_t fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0));
359 if (fd < 0) {
360 LOG_ERR("ServerSocket::CreateBindListen: socket() failed\n");
361 return -1;
362 }
363 LOG_INFO("ServerSocket::CreateBindListen: socket(SOCK_STREAM) -> %ld\n", fd);
364
365 if (!FDUtils::SetCloseOnExec(fd)) {
366 LOG_ERR("ServerSocket::CreateBindListen: SetCloseOnExec(%ld) failed\n", fd);
367 FDUtils::SaveErrorAndClose(fd);
368 return -1;
369 }
370
371 LOG_INFO("ServerSocket::CreateBindListen: calling setsockopt(%ld)\n", fd);
372 int optval = 1;
373 VOID_NO_RETRY_EXPECTED(
374 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
375
376 if (addr.ss.ss_family == AF_INET6) {
377 optval = v6_only ? 1 : 0;
378 LOG_INFO("ServerSocket::CreateBindListen: calling setsockopt(%ld)\n", fd);
379 VOID_NO_RETRY_EXPECTED(
380 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)));
381 }
382
383 LOG_INFO("ServerSocket::CreateBindListen: calling bind(%ld)\n", fd);
384 if (NO_RETRY_EXPECTED(
385 bind(fd, &addr.addr, SocketAddress::GetAddrLength(addr))) < 0) {
386 LOG_ERR("ServerSocket::CreateBindListen: bind(%ld) failed\n", fd);
387 FDUtils::SaveErrorAndClose(fd);
388 return -1;
389 }
390 LOG_INFO("ServerSocket::CreateBindListen: bind(%ld) succeeded\n", fd);
391
392 // Test for invalid socket port 65535 (some browsers disallow it).
393 if ((SocketAddress::GetAddrPort(addr) == 0) &&
394 (Socket::GetPort(fd) == 65535)) {
395 // Don't close the socket until we have created a new socket, ensuring
396 // that we do not get the bad port number again.
397 intptr_t new_fd = CreateBindListen(addr, backlog, v6_only);
398 FDUtils::SaveErrorAndClose(fd);
399 return new_fd;
400 }
401
402 LOG_INFO("ServerSocket::CreateBindListen: calling listen(%ld)\n", fd);
403 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
404 LOG_ERR("ServerSocket::CreateBindListen: listen failed(%ld)\n", fd);
405 FDUtils::SaveErrorAndClose(fd);
406 return -1;
407 }
408 LOG_INFO("ServerSocket::CreateBindListen: listen(%ld) succeeded\n", fd);
409
410 if (!FDUtils::SetNonBlocking(fd)) {
411 LOG_ERR("CreateBindListen: FDUtils::SetNonBlocking(%ld) failed\n", fd);
412 FDUtils::SaveErrorAndClose(fd);
413 return -1;
414 }
415 return fd;
171 } 416 }
172 417
173 418
174 bool ServerSocket::StartAccept(intptr_t fd) { 419 bool ServerSocket::StartAccept(intptr_t fd) {
175 UNIMPLEMENTED(); 420 USE(fd);
176 return false; 421 return true;
422 }
423
424
425 static bool IsTemporaryAcceptError(int error) {
426 // On Linux a number of protocol errors should be treated as EAGAIN.
427 // These are the ones for TCP/IP.
428 return (error == EAGAIN) || (error == ENETDOWN) || (error == EPROTO) ||
429 (error == ENOPROTOOPT) || (error == EHOSTDOWN) || (error == ENONET) ||
430 (error == EHOSTUNREACH) || (error == EOPNOTSUPP) ||
431 (error == ENETUNREACH);
177 } 432 }
178 433
179 434
180 intptr_t ServerSocket::Accept(intptr_t fd) { 435 intptr_t ServerSocket::Accept(intptr_t fd) {
181 UNIMPLEMENTED(); 436 intptr_t socket;
182 return -1; 437 struct sockaddr clientaddr;
438 socklen_t addrlen = sizeof(clientaddr);
439 LOG_INFO("ServerSocket::Accept: calling accept(%ld)\n", fd);
440 socket = NO_RETRY_EXPECTED(accept(fd, &clientaddr, &addrlen));
441 if (socket == -1) {
442 if (IsTemporaryAcceptError(errno)) {
443 // We need to signal to the caller that this is actually not an
444 // error. We got woken up from the poll on the listening socket,
445 // but there is no connection ready to be accepted.
446 ASSERT(kTemporaryFailure != -1);
447 socket = kTemporaryFailure;
448 } else {
449 LOG_ERR("ServerSocket::Accept: accept(%ld) failed\n", fd);
450 }
451 } else {
452 LOG_INFO("ServerSocket::Accept: accept(%ld) -> socket %ld\n", fd, socket);
453 if (!FDUtils::SetCloseOnExec(socket)) {
454 LOG_ERR("FDUtils::SetCloseOnExec(%ld) failed\n", socket);
455 FDUtils::SaveErrorAndClose(socket);
456 return -1;
457 }
458 if (!FDUtils::SetNonBlocking(socket)) {
459 LOG_ERR("FDUtils::SetNonBlocking(%ld) failed\n", socket);
460 FDUtils::SaveErrorAndClose(socket);
461 return -1;
462 }
463 }
464 return socket;
183 } 465 }
184 466
185 467
186 void Socket::Close(intptr_t fd) { 468 void Socket::Close(intptr_t fd) {
187 UNIMPLEMENTED(); 469 ASSERT(fd >= 0);
470 NO_RETRY_EXPECTED(close(fd));
188 } 471 }
189 472
190 473
191 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { 474 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
475 LOG_ERR("Socket::GetNoDelay is unimplemented\n");
192 UNIMPLEMENTED(); 476 UNIMPLEMENTED();
193 return false; 477 return false;
194 } 478 }
195 479
196 480
197 bool Socket::SetNoDelay(intptr_t fd, bool enabled) { 481 bool Socket::SetNoDelay(intptr_t fd, bool enabled) {
198 UNIMPLEMENTED(); 482 int on = enabled ? 1 : 0;
199 return false; 483 return NO_RETRY_EXPECTED(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
484 reinterpret_cast<char*>(&on),
485 sizeof(on))) == 0;
200 } 486 }
201 487
202 488
203 bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) { 489 bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) {
490 LOG_ERR("Socket::GetMulticastLoop is unimplemented\n");
204 UNIMPLEMENTED(); 491 UNIMPLEMENTED();
205 return false; 492 return false;
206 } 493 }
207 494
208 495
209 bool Socket::SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled) { 496 bool Socket::SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled) {
497 LOG_ERR("Socket::SetMulticastLoop is unimplemented\n");
210 UNIMPLEMENTED(); 498 UNIMPLEMENTED();
211 return false; 499 return false;
212 } 500 }
213 501
214 502
215 bool Socket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) { 503 bool Socket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) {
504 LOG_ERR("Socket::GetMulticastHops is unimplemented\n");
216 UNIMPLEMENTED(); 505 UNIMPLEMENTED();
217 return false; 506 return false;
218 } 507 }
219 508
220 509
221 bool Socket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) { 510 bool Socket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) {
511 LOG_ERR("Socket::SetMulticastHops is unimplemented\n");
222 UNIMPLEMENTED(); 512 UNIMPLEMENTED();
223 return false; 513 return false;
224 } 514 }
225 515
226 516
227 bool Socket::GetBroadcast(intptr_t fd, bool* enabled) { 517 bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
518 LOG_ERR("Socket::GetBroadcast is unimplemented\n");
228 UNIMPLEMENTED(); 519 UNIMPLEMENTED();
229 return false; 520 return false;
230 } 521 }
231 522
232 523
233 bool Socket::SetBroadcast(intptr_t fd, bool enabled) { 524 bool Socket::SetBroadcast(intptr_t fd, bool enabled) {
525 LOG_ERR("Socket::SetBroadcast is unimplemented\n");
234 UNIMPLEMENTED(); 526 UNIMPLEMENTED();
235 return false; 527 return false;
236 } 528 }
237 529
238 530
239 bool Socket::JoinMulticast(intptr_t fd, 531 bool Socket::JoinMulticast(intptr_t fd,
240 const RawAddr& addr, 532 const RawAddr& addr,
241 const RawAddr&, 533 const RawAddr&,
242 int interfaceIndex) { 534 int interfaceIndex) {
535 LOG_ERR("Socket::JoinMulticast is unimplemented\n");
243 UNIMPLEMENTED(); 536 UNIMPLEMENTED();
244 return false; 537 return false;
245 } 538 }
246 539
247 540
248 bool Socket::LeaveMulticast(intptr_t fd, 541 bool Socket::LeaveMulticast(intptr_t fd,
249 const RawAddr& addr, 542 const RawAddr& addr,
250 const RawAddr&, 543 const RawAddr&,
251 int interfaceIndex) { 544 int interfaceIndex) {
545 LOG_ERR("Socket::LeaveMulticast is unimplemented\n");
252 UNIMPLEMENTED(); 546 UNIMPLEMENTED();
253 return false; 547 return false;
254 } 548 }
255 549
256 } // namespace bin 550 } // namespace bin
257 } // namespace dart 551 } // namespace dart
258 552
259 #endif // defined(TARGET_OS_FUCHSIA) 553 #endif // defined(TARGET_OS_FUCHSIA)
260 554
261 #endif // !defined(DART_IO_DISABLED) 555 #endif // !defined(DART_IO_DISABLED)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698