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

Side by Side Diff: runtime/bin/socket_patch.dart

Issue 25511002: Add reusePort argument to ServerSocket. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mac os X version. Created 7 years, 2 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
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | runtime/bin/socket_win.cc » ('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 patch class RawServerSocket { 5 patch class RawServerSocket {
6 /* patch */ static Future<RawServerSocket> bind(address, 6 /* patch */ static Future<RawServerSocket> bind(address,
7 int port, 7 int port,
8 {int backlog: 0, 8 {int backlog: 0,
9 bool v6Only: false}) { 9 bool v6Only: false,
10 return _RawServerSocket.bind(address, port, backlog, v6Only); 10 bool reusePort: false}) {
11 return _RawServerSocket.bind(address, port, backlog, v6Only, reusePort);
11 } 12 }
12 } 13 }
13 14
14 15
15 patch class RawSocket { 16 patch class RawSocket {
16 /* patch */ static Future<RawSocket> connect(host, int port) { 17 /* patch */ static Future<RawSocket> connect(host, int port) {
17 return _RawSocket.connect(host, port); 18 return _RawSocket.connect(host, port);
18 } 19 }
19 } 20 }
20 21
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 ); 313 );
313 socket.setListening(read: false, write: true); 314 socket.setListening(read: false, write: true);
314 return completer.future; 315 return completer.future;
315 } 316 }
316 }); 317 });
317 } 318 }
318 319
319 static Future<_NativeSocket> bind(host, 320 static Future<_NativeSocket> bind(host,
320 int port, 321 int port,
321 int backlog, 322 int backlog,
322 bool v6Only) { 323 bool v6Only,
324 bool reusePort) {
323 return new Future.value(host) 325 return new Future.value(host)
324 .then((host) { 326 .then((host) {
325 if (host is _InternetAddress) return host; 327 if (host is _InternetAddress) return host;
326 return lookup(host) 328 return lookup(host)
327 .then((list) { 329 .then((list) {
328 if (list.length == 0) { 330 if (list.length == 0) {
329 throw createError(response, "Failed host lookup: '$host'"); 331 throw createError(response, "Failed host lookup: '$host'");
330 } 332 }
331 return list[0]; 333 return list[0];
332 }); 334 });
333 }) 335 })
334 .then((address) { 336 .then((address) {
335 var socket = new _NativeSocket.listen(); 337 var socket = new _NativeSocket.listen();
336 socket.address = address; 338 socket.address = address;
337 var result = socket.nativeCreateBindListen(address._sockaddr_storage, 339 var result = socket.nativeCreateBindListen(address._sockaddr_storage,
338 port, 340 port,
339 backlog, 341 backlog,
340 v6Only); 342 v6Only,
343 reusePort);
341 if (result is OSError) { 344 if (result is OSError) {
342 throw new SocketException("Failed to create server socket", 345 throw new SocketException("Failed to create server socket",
343 osError: result, 346 osError: result,
344 address: address, 347 address: address,
345 port: port); 348 port: port);
346 } 349 }
347 if (port != 0) socket.localPort = port; 350 if (port != 0) socket.localPort = port;
348 return socket; 351 return socket;
349 }); 352 });
350 } 353 }
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 return nativeSetOption(option._value, enabled); 651 return nativeSetOption(option._value, enabled);
649 } 652 }
650 653
651 void nativeSetSocketId(int id) native "Socket_SetSocketId"; 654 void nativeSetSocketId(int id) native "Socket_SetSocketId";
652 nativeAvailable() native "Socket_Available"; 655 nativeAvailable() native "Socket_Available";
653 nativeRead(int len) native "Socket_Read"; 656 nativeRead(int len) native "Socket_Read";
654 nativeWrite(List<int> buffer, int offset, int bytes) 657 nativeWrite(List<int> buffer, int offset, int bytes)
655 native "Socket_WriteList"; 658 native "Socket_WriteList";
656 nativeCreateConnect(List<int> addr, 659 nativeCreateConnect(List<int> addr,
657 int port) native "Socket_CreateConnect"; 660 int port) native "Socket_CreateConnect";
658 nativeCreateBindListen(List<int> addr, int port, int backlog, bool v6Only) 661 nativeCreateBindListen(
662 List<int> addr, int port, int backlog, bool v6Only, bool reusePort)
659 native "ServerSocket_CreateBindListen"; 663 native "ServerSocket_CreateBindListen";
660 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept"; 664 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept";
661 int nativeGetPort() native "Socket_GetPort"; 665 int nativeGetPort() native "Socket_GetPort";
662 List nativeGetRemotePeer() native "Socket_GetRemotePeer"; 666 List nativeGetRemotePeer() native "Socket_GetRemotePeer";
663 OSError nativeGetError() native "Socket_GetError"; 667 OSError nativeGetError() native "Socket_GetError";
664 bool nativeSetOption(int option, bool enabled) native "Socket_SetOption"; 668 bool nativeSetOption(int option, bool enabled) native "Socket_SetOption";
665 } 669 }
666 670
667 671
668 class _RawServerSocket extends Stream<RawSocket> 672 class _RawServerSocket extends Stream<RawSocket>
669 implements RawServerSocket { 673 implements RawServerSocket {
670 final _NativeSocket _socket; 674 final _NativeSocket _socket;
671 StreamController<RawSocket> _controller; 675 StreamController<RawSocket> _controller;
672 676
673 static Future<_RawServerSocket> bind(address, 677 static Future<_RawServerSocket> bind(address,
674 int port, 678 int port,
675 int backlog, 679 int backlog,
676 bool v6Only) { 680 bool v6Only,
681 bool reusePort) {
677 if (port < 0 || port > 0xFFFF) 682 if (port < 0 || port > 0xFFFF)
678 throw new ArgumentError("Invalid port $port"); 683 throw new ArgumentError("Invalid port $port");
679 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); 684 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog");
680 return _NativeSocket.bind(address, port, backlog, v6Only) 685 return _NativeSocket.bind(address, port, backlog, v6Only, reusePort)
681 .then((socket) => new _RawServerSocket(socket)); 686 .then((socket) => new _RawServerSocket(socket));
682 } 687 }
683 688
684 _RawServerSocket(this._socket) { 689 _RawServerSocket(this._socket) {
685 _controller = new StreamController(sync: true, 690 _controller = new StreamController(sync: true,
686 onListen: _onSubscriptionStateChange, 691 onListen: _onSubscriptionStateChange,
687 onCancel: _onSubscriptionStateChange, 692 onCancel: _onSubscriptionStateChange,
688 onPause: _onPauseStateChange, 693 onPause: _onPauseStateChange,
689 onResume: _onPauseStateChange); 694 onResume: _onPauseStateChange);
690 _socket.closeFuture.then((_) => _controller.close()); 695 _socket.closeFuture.then((_) => _controller.close());
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 close(); 891 close();
887 } 892 }
888 } 893 }
889 } 894 }
890 895
891 896
892 patch class ServerSocket { 897 patch class ServerSocket {
893 /* patch */ static Future<ServerSocket> bind(address, 898 /* patch */ static Future<ServerSocket> bind(address,
894 int port, 899 int port,
895 {int backlog: 0, 900 {int backlog: 0,
896 bool v6Only: false}) { 901 bool v6Only: false,
897 return _ServerSocket.bind(address, port, backlog, v6Only); 902 bool reusePort: false}) {
903 return _ServerSocket.bind(address, port, backlog, v6Only, reusePort);
898 } 904 }
899 } 905 }
900 906
901 class _ServerSocket extends Stream<Socket> 907 class _ServerSocket extends Stream<Socket>
902 implements ServerSocket { 908 implements ServerSocket {
903 final _socket; 909 final _socket;
904 910
905 static Future<_ServerSocket> bind(address, 911 static Future<_ServerSocket> bind(address,
906 int port, 912 int port,
907 int backlog, 913 int backlog,
908 bool v6Only) { 914 bool v6Only,
909 return _RawServerSocket.bind(address, port, backlog, v6Only) 915 bool reusePort) {
916 return _RawServerSocket.bind(address, port, backlog, v6Only, reusePort)
910 .then((socket) => new _ServerSocket(socket)); 917 .then((socket) => new _ServerSocket(socket));
911 } 918 }
912 919
913 _ServerSocket(this._socket); 920 _ServerSocket(this._socket);
914 921
915 StreamSubscription<Socket> listen(void onData(Socket event), 922 StreamSubscription<Socket> listen(void onData(Socket event),
916 {void onError(error), 923 {void onError(error),
917 void onDone(), 924 void onDone(),
918 bool cancelOnError}) { 925 bool cancelOnError}) {
919 return _socket.map((rawSocket) => new _Socket(rawSocket)).listen( 926 return _socket.map((rawSocket) => new _Socket(rawSocket)).listen(
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 if (_detachReady != null) { 1222 if (_detachReady != null) {
1216 _detachReady.complete(null); 1223 _detachReady.complete(null);
1217 } else { 1224 } else {
1218 if (_raw != null) { 1225 if (_raw != null) {
1219 _raw.shutdown(SocketDirection.SEND); 1226 _raw.shutdown(SocketDirection.SEND);
1220 _disableWriteEvent(); 1227 _disableWriteEvent();
1221 } 1228 }
1222 } 1229 }
1223 } 1230 }
1224 } 1231 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698