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

Unified Diff: runtime/bin/socket_macos.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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/socket_macos.cc
diff --git a/runtime/bin/socket_macos.cc b/runtime/bin/socket_macos.cc
index da659ff7fe8ac3a607edab9286930cff3caad85c..239bb4536661b8c2b57dc695c9b86f0c21113009 100644
--- a/runtime/bin/socket_macos.cc
+++ b/runtime/bin/socket_macos.cc
@@ -57,7 +57,7 @@ bool Socket::Initialize() {
}
-intptr_t Socket::Create(RawAddr addr) {
+static intptr_t Create(RawAddr addr) {
intptr_t fd;
fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0));
if (fd < 0) {
@@ -68,7 +68,7 @@ intptr_t Socket::Create(RawAddr addr) {
}
-intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) {
+static intptr_t Connect(intptr_t fd, RawAddr addr, const intptr_t port) {
SocketAddress::SetAddrPort(&addr, port);
intptr_t result = TEMP_FAILURE_RETRY(
connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr)));
@@ -80,15 +80,34 @@ intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) {
}
-intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) {
- intptr_t fd = Socket::Create(addr);
+intptr_t Socket::CreateConnect(const RawAddr& addr, const intptr_t port) {
+ intptr_t fd = Create(addr);
if (fd < 0) {
return fd;
}
FDUtils::SetNonBlocking(fd);
- return Socket::Connect(fd, addr, port);
+ return Connect(fd, addr, port);
+}
+
+
+intptr_t Socket::CreateBindConnect(const RawAddr& addr,
+ const intptr_t port,
+ const RawAddr& source_addr) {
+ intptr_t fd = Create(addr);
+ if (fd < 0) {
+ return fd;
+ }
+
+ intptr_t result = TEMP_FAILURE_RETRY(
+ bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(&source_addr)));
+ if (result != 0 && errno != EINPROGRESS) {
+ VOID_TEMP_FAILURE_RETRY(close(fd));
+ return -1;
+ }
+
+ return Connect(fd, addr, port);
}

Powered by Google App Engine
This is Rietveld 408576698