| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // | 5 // |
| 6 // Implementation of ServerSocket and RawServerSocket for Mojo. | 6 // Implementation of ServerSocket and RawServerSocket for Mojo. |
| 7 // | 7 // |
| 8 | 8 |
| 9 patch class RawServerSocket { | 9 patch class RawServerSocket { |
| 10 /* patch */ static Future<RawServerSocket> bind(address, | 10 /* patch */ static Future<RawServerSocket> bind(address, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 int port, | 21 int port, |
| 22 {int backlog: 0, | 22 {int backlog: 0, |
| 23 bool v6Only: false, | 23 bool v6Only: false, |
| 24 bool shared: false}) { | 24 bool shared: false}) { |
| 25 return _MojoServerSocket.bind(address, port, backlog, v6Only, shared); | 25 return _MojoServerSocket.bind(address, port, backlog, v6Only, shared); |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 class _MojoRawServerSocket extends Stream<RawSocket> | 29 class _MojoRawServerSocket extends Stream<RawSocket> |
| 30 implements RawServerSocket { | 30 implements RawServerSocket { |
| 31 final _tcpBoundSocket = new TcpBoundSocketProxy.unbound(); | 31 final _tcpBoundSocket = new _TcpBoundSocketProxy.unbound(); |
| 32 final _tcpServerSocket = new TcpServerSocketProxy.unbound(); | 32 final _tcpServerSocket = new _TcpServerSocketProxy.unbound(); |
| 33 final bool _v6Only; | 33 final bool _v6Only; |
| 34 InternetAddress _boundAddress; | 34 InternetAddress _boundAddress; |
| 35 int _boundPort; | 35 int _boundPort; |
| 36 StreamController<RawSocket> _controller; | 36 StreamController<RawSocket> _controller; |
| 37 ReceivePort _referencePort; | 37 ReceivePort _referencePort; |
| 38 Future _scheduledAccept; | 38 Future _scheduledAccept; |
| 39 bool _paused = false; | 39 bool _paused = false; |
| 40 bool _closed = false; | 40 bool _closed = false; |
| 41 var _owner; | 41 var _owner; |
| 42 | 42 |
| 43 static Future<_MojoRawServerSocket> _bind(NetAddress bindAddress, | 43 static Future<_MojoRawServerSocket> _bind(NetAddress bindAddress, |
| 44 int backlog, | 44 int backlog, |
| 45 bool v6Only, | 45 bool v6Only, |
| 46 bool shared) async { | 46 bool shared) async { |
| 47 final rawServerSocket = new _MojoRawServerSocket(v6Only); | 47 final rawServerSocket = new _MojoRawServerSocket(v6Only); |
| 48 final networkService = _getNetworkService(); | 48 final networkService = _getNetworkService(); |
| 49 assert(networkService != null); | 49 assert(networkService != null); |
| 50 var response = | 50 var response = |
| 51 await networkService.createTcpBoundSocket( | 51 await networkService.createTcpBoundSocket( |
| 52 bindAddress, | 52 bindAddress, |
| 53 rawServerSocket._tcpBoundSocket); | 53 rawServerSocket._tcpBoundSocket.proxy); |
| 54 if (!_NetworkService._okay(response.result)) { | 54 if (!_NetworkService._okay(response.result)) { |
| 55 rawServerSocket.close(); | 55 rawServerSocket.close(); |
| 56 _NetworkService._throwOnError(response.result); | 56 _NetworkService._throwOnError(response.result); |
| 57 } | 57 } |
| 58 rawServerSocket._boundAddress = | 58 rawServerSocket._boundAddress = |
| 59 _NetworkServiceCodec._fromNetAddress(response.boundTo); | 59 _NetworkServiceCodec._fromNetAddress(response.boundTo); |
| 60 rawServerSocket._boundPort = | 60 rawServerSocket._boundPort = |
| 61 _NetworkServiceCodec._portFromNetAddress(response.boundTo); | 61 _NetworkServiceCodec._portFromNetAddress(response.boundTo); |
| 62 final boundSocket = rawServerSocket._tcpBoundSocket; | 62 final boundSocket = rawServerSocket._tcpBoundSocket; |
| 63 response = | 63 response = await boundSocket.startListening( |
| 64 await boundSocket.startListening(rawServerSocket._tcpServerSocket); | 64 rawServerSocket._tcpServerSocket.proxy); |
| 65 if (!_NetworkService._okay(response.result)) { | 65 if (!_NetworkService._okay(response.result)) { |
| 66 rawServerSocket.close(); | 66 rawServerSocket.close(); |
| 67 _NetworkService._throwOnError(response.result); | 67 _NetworkService._throwOnError(response.result); |
| 68 } | 68 } |
| 69 return rawServerSocket; | 69 return rawServerSocket; |
| 70 } | 70 } |
| 71 | 71 |
| 72 static Future<_MojoRawServerSocket> bind(address, | 72 static Future<_MojoRawServerSocket> bind(address, |
| 73 int port, | 73 int port, |
| 74 int backlog, | 74 int backlog, |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 int get port => _socket.port; | 280 int get port => _socket.port; |
| 281 | 281 |
| 282 InternetAddress get address => _socket.address; | 282 InternetAddress get address => _socket.address; |
| 283 | 283 |
| 284 Future close() => _socket.close().then((_) => this); | 284 Future close() => _socket.close().then((_) => this); |
| 285 | 285 |
| 286 Map _toJSON(bool ref) => _socket._toJSON(ref); | 286 Map _toJSON(bool ref) => _socket._toJSON(ref); |
| 287 | 287 |
| 288 void set _owner(owner) { _socket._owner = owner; } | 288 void set _owner(owner) { _socket._owner = owner; } |
| 289 } | 289 } |
| OLD | NEW |