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

Unified Diff: runtime/bin/socket_patch.dart

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_patch.dart
diff --git a/runtime/bin/socket_patch.dart b/runtime/bin/socket_patch.dart
index 3983f2428e3636f27e86e1a0c578630d5ba660cb..e683e206d4a52fabf5ac0bf7672bc91da5d8d805 100644
--- a/runtime/bin/socket_patch.dart
+++ b/runtime/bin/socket_patch.dart
@@ -13,8 +13,9 @@ patch class RawServerSocket {
patch class RawSocket {
- /* patch */ static Future<RawSocket> connect(host, int port) {
- return _RawSocket.connect(host, port);
+ /* patch */ static Future<RawSocket> connect(
+ host, int port, {sourceAddress}) {
+ return _RawSocket.connect(host, port, sourceAddress);
}
}
@@ -381,7 +382,12 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject {
});
}
- static Future<_NativeSocket> connect(host, int port) {
+ static Future<_NativeSocket> connect(host, int port, sourceAddress) {
+ if (sourceAddress != null && sourceAddress is! _InternetAddress) {
+ if (sourceAddress is String) {
+ sourceAddress = new InternetAddress(sourceAddress);
+ }
+ }
return new Future.value(host)
.then((host) {
if (host is _InternetAddress) return [host];
@@ -410,7 +416,14 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject {
var address = it.current;
var socket = new _NativeSocket.normal();
socket.address = address;
- var result = socket.nativeCreateConnect(address._in_addr, port);
+ var result;
+ if (sourceAddress == null) {
+ result = socket.nativeCreateConnect(address._in_addr, port);
+ } else {
+ assert(sourceAddress is _InternetAddress);
+ result = socket.nativeCreateBindConnect(
+ address._in_addr, port, sourceAddress._in_addr);
+ }
if (result is OSError) {
// Keep first error, if present.
if (error == null) {
@@ -1116,6 +1129,9 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject {
native "Socket_SendTo";
nativeCreateConnect(List<int> addr,
int port) native "Socket_CreateConnect";
+ nativeCreateBindConnect(
+ List<int> addr, int port, List<int> sourceAddr)
+ native "Socket_CreateBindConnect";
nativeCreateBindListen(List<int> addr, int port, int backlog, bool v6Only)
native "ServerSocket_CreateBindListen";
nativeCreateBindDatagram(List<int> addr, int port, bool reuseAddress)
@@ -1287,8 +1303,8 @@ class _RawSocket extends Stream<RawSocketEvent>
// Flag to handle Ctrl-D closing of stdio on Mac OS.
bool _isMacOSTerminalInput = false;
- static Future<RawSocket> connect(host, int port) {
- return _NativeSocket.connect(host, port)
+ static Future<RawSocket> connect(host, int port, sourceAddress) {
+ return _NativeSocket.connect(host, port, sourceAddress)
.then((socket) => new _RawSocket(socket));
}
@@ -1490,8 +1506,8 @@ class _ServerSocket extends Stream<Socket>
patch class Socket {
- /* patch */ static Future<Socket> connect(host, int port) {
- return RawSocket.connect(host, port).then(
+ /* patch */ static Future<Socket> connect(host, int port, {sourceAddress}) {
+ return RawSocket.connect(host, port, sourceAddress: sourceAddress).then(
(socket) => new _Socket(socket));
}
}
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | runtime/bin/socket_win.cc » ('j') | sdk/lib/io/socket.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698