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

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

Issue 908873002: Add support to specify the source address for socket connect (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added dart2js patch file Created 5 years, 10 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 | Annotate | Revision Log
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 return true; 45 return true;
46 } 46 }
47 47
48 48
49 bool Socket::Initialize() { 49 bool Socket::Initialize() {
50 // Nothing to do on Linux. 50 // Nothing to do on Linux.
51 return true; 51 return true;
52 } 52 }
53 53
54 54
55 intptr_t Socket::Create(RawAddr addr) { 55 static intptr_t Create(RawAddr addr) {
56 intptr_t fd; 56 intptr_t fd;
57 fd = NO_RETRY_EXPECTED( 57 fd = NO_RETRY_EXPECTED(
58 socket(addr.ss.ss_family, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0)); 58 socket(addr.ss.ss_family, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0));
59 if (fd < 0) { 59 if (fd < 0) {
60 return -1; 60 return -1;
61 } 61 }
62 return fd; 62 return fd;
63 } 63 }
64 64
65 65
66 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) { 66 static intptr_t Connect(intptr_t fd, RawAddr addr, const intptr_t port) {
67 SocketAddress::SetAddrPort(&addr, port); 67 SocketAddress::SetAddrPort(&addr, port);
68 intptr_t result = TEMP_FAILURE_RETRY( 68 intptr_t result = TEMP_FAILURE_RETRY(
69 connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr))); 69 connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr)));
70 if (result == 0 || errno == EINPROGRESS) { 70 if (result == 0 || errno == EINPROGRESS) {
71 return fd; 71 return fd;
72 } 72 }
73 VOID_TEMP_FAILURE_RETRY(close(fd)); 73 VOID_TEMP_FAILURE_RETRY(close(fd));
74 return -1; 74 return -1;
75 } 75 }
76 76
77 77
78 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) { 78 intptr_t Socket::CreateConnect(const RawAddr& addr, const intptr_t port) {
79 intptr_t fd = Socket::Create(addr); 79 intptr_t fd = Create(addr);
80 if (fd < 0) { 80 if (fd < 0) {
81 return fd; 81 return fd;
82 } 82 }
83 return Socket::Connect(fd, addr, port); 83 return Connect(fd, addr, port);
84 } 84 }
85 85
86 86
87 intptr_t Socket::CreateBindConnect(const RawAddr& addr,
88 const intptr_t port,
89 const RawAddr& source_addr) {
90 intptr_t fd = Create(addr);
91 if (fd < 0) {
92 return fd;
93 }
94
95 intptr_t result = TEMP_FAILURE_RETRY(
96 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(&source_addr)));
97 if (result != 0 && errno != EINPROGRESS) {
98 VOID_TEMP_FAILURE_RETRY(close(fd));
99 return -1;
100 }
101
102 return Connect(fd, addr, port);
103 }
104
105
87 intptr_t Socket::Available(intptr_t fd) { 106 intptr_t Socket::Available(intptr_t fd) {
88 return FDUtils::AvailableBytes(fd); 107 return FDUtils::AvailableBytes(fd);
89 } 108 }
90 109
91 110
92 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { 111 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
93 ASSERT(fd >= 0); 112 ASSERT(fd >= 0);
94 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); 113 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
95 ASSERT(EAGAIN == EWOULDBLOCK); 114 ASSERT(EAGAIN == EWOULDBLOCK);
96 if (read_bytes == -1 && errno == EWOULDBLOCK) { 115 if (read_bytes == -1 && errno == EWOULDBLOCK) {
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 mreq.gr_interface = interfaceIndex; 571 mreq.gr_interface = interfaceIndex;
553 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); 572 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr));
554 return NO_RETRY_EXPECTED( 573 return NO_RETRY_EXPECTED(
555 setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; 574 setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0;
556 } 575 }
557 576
558 } // namespace bin 577 } // namespace bin
559 } // namespace dart 578 } // namespace dart
560 579
561 #endif // defined(TARGET_OS_LINUX) 580 #endif // defined(TARGET_OS_LINUX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698