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

Side by Side Diff: mojo/dart/embedder/io/server_socket_patch.dart

Issue 1964193002: Dart: Refactors Proxies (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address comments Created 4 years, 7 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
« no previous file with comments | « mojo/dart/embedder/io/mojo_patch.dart ('k') | mojo/dart/embedder/io/socket_patch.dart » ('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 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 27 matching lines...) Expand all
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().ptr; 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);
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.ptr; 62 final boundSocket = rawServerSocket._tcpBoundSocket;
63 response = 63 response =
64 await boundSocket.startListening(rawServerSocket._tcpServerSocket); 64 await boundSocket.startListening(rawServerSocket._tcpServerSocket);
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,
(...skipping 23 matching lines...) Expand all
96 var rawSocket = new _MojoRawSocket(); 96 var rawSocket = new _MojoRawSocket();
97 rawSocket._localAddress = _boundAddress; 97 rawSocket._localAddress = _boundAddress;
98 rawSocket._localPort = _boundPort; 98 rawSocket._localPort = _boundPort;
99 rawSocket._setupIn(); 99 rawSocket._setupIn();
100 rawSocket._setupOut(); 100 rawSocket._setupOut();
101 rawSocket._tracePipeIn(); 101 rawSocket._tracePipeIn();
102 rawSocket._tracePipeOut(); 102 rawSocket._tracePipeOut();
103 var response; 103 var response;
104 try { 104 try {
105 response = await _tcpServerSocket.responseOrError( 105 response = await _tcpServerSocket.responseOrError(
106 _tcpServerSocket.ptr.accept(rawSocket._pipeOut.consumer, 106 _tcpServerSocket.accept(rawSocket._pipeOut.consumer,
107 rawSocket._pipeIn.producer, 107 rawSocket._pipeIn.producer,
108 rawSocket._tcpConnectedSocket)); 108 rawSocket._tcpConnectedSocket));
109 } on ProxyError catch (e) { 109 } on ProxyError catch (e) {
110 rawSocket.destroy(); 110 rawSocket.destroy();
111 await _destroy(); 111 await _destroy();
112 return; 112 return;
113 } catch (e) { 113 } catch (e) {
114 _controller.addError(e); 114 _controller.addError(e);
115 rawSocket.destroy(); 115 rawSocket.destroy();
116 await _destroy(); 116 await _destroy();
117 return; 117 return;
118 } 118 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « mojo/dart/embedder/io/mojo_patch.dart ('k') | mojo/dart/embedder/io/socket_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698