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

Side by Side Diff: runtime/bin/socket_linux.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_linux.h ('k') | runtime/bin/socket_macos.h » ('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_LINUX) 6 #if defined(TARGET_OS_LINUX)
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr))); 94 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr)));
95 if (result != 0 && errno != EINPROGRESS) { 95 if (result != 0 && errno != EINPROGRESS) {
96 VOID_TEMP_FAILURE_RETRY(close(fd)); 96 VOID_TEMP_FAILURE_RETRY(close(fd));
97 return -1; 97 return -1;
98 } 98 }
99 99
100 return Connect(fd, addr); 100 return Connect(fd, addr);
101 } 101 }
102 102
103 103
104 intptr_t Socket::CreateConnectUnix(const RawAddr& addr) {
105 intptr_t fd = Create(addr);
106 if (fd < 0) {
107 return fd;
108 }
109
110 intptr_t result = TEMP_FAILURE_RETRY(
111 connect(fd, &addr.addr, sizeof(struct sockaddr_un)));
112 if (result == 0 || errno == EINPROGRESS) {
113 return fd;
114 }
115 VOID_TEMP_FAILURE_RETRY(close(fd));
116 return -1;
117 }
118
119
104 intptr_t Socket::Available(intptr_t fd) { 120 intptr_t Socket::Available(intptr_t fd) {
105 return FDUtils::AvailableBytes(fd); 121 return FDUtils::AvailableBytes(fd);
106 } 122 }
107 123
108 124
109 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { 125 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
110 ASSERT(fd >= 0); 126 ASSERT(fd >= 0);
111 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); 127 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
112 ASSERT(EAGAIN == EWOULDBLOCK); 128 ASSERT(EAGAIN == EWOULDBLOCK);
113 if (read_bytes == -1 && errno == EWOULDBLOCK) { 129 if (read_bytes == -1 && errno == EWOULDBLOCK) {
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 419
404 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { 420 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
405 VOID_TEMP_FAILURE_RETRY(close(fd)); 421 VOID_TEMP_FAILURE_RETRY(close(fd));
406 return -1; 422 return -1;
407 } 423 }
408 424
409 return fd; 425 return fd;
410 } 426 }
411 427
412 428
429 intptr_t ServerSocket::CreateBindListenUnix(const RawAddr& addr,
430 intptr_t backlog) {
431 intptr_t fd;
432
433 fd = NO_RETRY_EXPECTED(
434 socket(addr.ss.ss_family, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
435 if (fd < 0) return -1;
436
437 if (NO_RETRY_EXPECTED(
438 bind(fd, &addr.addr, sizeof(struct sockaddr_un))) < 0) {
439 VOID_TEMP_FAILURE_RETRY(close(fd));
440 return -1;
441 }
442
443 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
444 VOID_TEMP_FAILURE_RETRY(close(fd));
445 return -1;
446 }
447
448 return fd;
449 }
450
451
413 bool ServerSocket::StartAccept(intptr_t fd) { 452 bool ServerSocket::StartAccept(intptr_t fd) {
414 USE(fd); 453 USE(fd);
415 return true; 454 return true;
416 } 455 }
417 456
418 457
419 static bool IsTemporaryAcceptError(int error) { 458 static bool IsTemporaryAcceptError(int error) {
420 // On Linux a number of protocol errors should be treated as EAGAIN. 459 // On Linux a number of protocol errors should be treated as EAGAIN.
421 // These are the ones for TCP/IP. 460 // These are the ones for TCP/IP.
422 return (error == EAGAIN) || (error == ENETDOWN) || (error == EPROTO) || 461 return (error == EAGAIN) || (error == ENETDOWN) || (error == EPROTO) ||
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 mreq.gr_interface = interfaceIndex; 604 mreq.gr_interface = interfaceIndex;
566 memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr)); 605 memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr));
567 return NO_RETRY_EXPECTED( 606 return NO_RETRY_EXPECTED(
568 setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; 607 setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0;
569 } 608 }
570 609
571 } // namespace bin 610 } // namespace bin
572 } // namespace dart 611 } // namespace dart
573 612
574 #endif // defined(TARGET_OS_LINUX) 613 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/socket_linux.h ('k') | runtime/bin/socket_macos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698