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

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

Issue 1293533002: DO NOT SUBMIT: Unix domain sockets. From CL 1061283003. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Added Mac OS fix Created 5 years, 4 months 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
« no previous file with comments | « runtime/bin/socket_macos.h ('k') | runtime/bin/socket_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include <errno.h> // NOLINT 8 #include <errno.h> // NOLINT
9 #include <stdio.h> // NOLINT 9 #include <stdio.h> // NOLINT
10 #include <stdlib.h> // NOLINT 10 #include <stdlib.h> // NOLINT
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr))); 102 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr)));
103 if (result != 0 && errno != EINPROGRESS) { 103 if (result != 0 && errno != EINPROGRESS) {
104 VOID_TEMP_FAILURE_RETRY(close(fd)); 104 VOID_TEMP_FAILURE_RETRY(close(fd));
105 return -1; 105 return -1;
106 } 106 }
107 107
108 return Connect(fd, addr); 108 return Connect(fd, addr);
109 } 109 }
110 110
111 111
112 intptr_t Socket::CreateConnectUnix(const RawAddr& addr) {
113 intptr_t fd = Create(addr);
114 if (fd < 0) {
115 return fd;
116 }
117
118 intptr_t result = TEMP_FAILURE_RETRY(
119 connect(fd, &addr.addr, sizeof(struct sockaddr_un)));
120 if (result == 0 || errno == EINPROGRESS) {
121 return fd;
122 }
123 VOID_TEMP_FAILURE_RETRY(close(fd));
124 return -1;
125 }
126
127
112 intptr_t Socket::Available(intptr_t fd) { 128 intptr_t Socket::Available(intptr_t fd) {
113 return FDUtils::AvailableBytes(fd); 129 return FDUtils::AvailableBytes(fd);
114 } 130 }
115 131
116 132
117 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { 133 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
118 ASSERT(fd >= 0); 134 ASSERT(fd >= 0);
119 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); 135 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
120 ASSERT(EAGAIN == EWOULDBLOCK); 136 ASSERT(EAGAIN == EWOULDBLOCK);
121 if (read_bytes == -1 && errno == EWOULDBLOCK) { 137 if (read_bytes == -1 && errno == EWOULDBLOCK) {
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { 425 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
410 VOID_TEMP_FAILURE_RETRY(close(fd)); 426 VOID_TEMP_FAILURE_RETRY(close(fd));
411 return -1; 427 return -1;
412 } 428 }
413 429
414 FDUtils::SetNonBlocking(fd); 430 FDUtils::SetNonBlocking(fd);
415 return fd; 431 return fd;
416 } 432 }
417 433
418 434
435 intptr_t ServerSocket::CreateBindListenUnix(const RawAddr& addr,
436 intptr_t backlog) {
437 intptr_t fd;
438
439 fd = NO_RETRY_EXPECTED(
440 socket(addr.ss.ss_family, SOCK_STREAM, 0));
441 if (fd < 0) return -1;
442
443 FDUtils::SetCloseOnExec(fd);
444
445 if (NO_RETRY_EXPECTED(
446 bind(fd, &addr.addr, sizeof(struct sockaddr_un))) < 0) {
447 VOID_TEMP_FAILURE_RETRY(close(fd));
448 return -1;
449 }
450
451 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
452 VOID_TEMP_FAILURE_RETRY(close(fd));
453 return -1;
454 }
455
456 FDUtils::SetNonBlocking(fd);
457 return fd;
458 }
459
460
419 bool ServerSocket::StartAccept(intptr_t fd) { 461 bool ServerSocket::StartAccept(intptr_t fd) {
420 USE(fd); 462 USE(fd);
421 return true; 463 return true;
422 } 464 }
423 465
424 466
425 intptr_t ServerSocket::Accept(intptr_t fd) { 467 intptr_t ServerSocket::Accept(intptr_t fd) {
426 intptr_t socket; 468 intptr_t socket;
427 struct sockaddr clientaddr; 469 struct sockaddr clientaddr;
428 socklen_t addrlen = sizeof(clientaddr); 470 socklen_t addrlen = sizeof(clientaddr);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 const RawAddr& addr, 653 const RawAddr& addr,
612 const RawAddr& interface, 654 const RawAddr& interface,
613 int interfaceIndex) { 655 int interfaceIndex) {
614 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); 656 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false);
615 } 657 }
616 658
617 } // namespace bin 659 } // namespace bin
618 } // namespace dart 660 } // namespace dart
619 661
620 #endif // defined(TARGET_OS_MACOS) 662 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/socket_macos.h ('k') | runtime/bin/socket_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698