OLD | NEW |
---|---|
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 return _RawServerSocket.bind(address, port, backlog, v6Only); |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
831 } | 831 } |
832 } | 832 } |
833 if (!isListening) { | 833 if (!isListening) { |
834 tokens++; | 834 tokens++; |
835 returnTokens(); | 835 returnTokens(); |
836 } | 836 } |
837 } | 837 } |
838 | 838 |
839 void returnTokens() { | 839 void returnTokens() { |
840 if (eventPort != null && !isClosing && !isClosed) { | 840 if (eventPort != null && !isClosing && !isClosed) { |
841 if (tokens == 8) { | 841 if (tokens == 2) { |
Søren Gjesse
2014/04/25 12:24:44
Please add a constant for this.
Anders Johnsen
2014/05/01 11:34:50
Done.
| |
842 // Return in batches of 8. | 842 // Return in batches of 2. |
843 assert(tokens < (1 << FIRST_COMMAND)); | 843 assert(tokens < (1 << FIRST_COMMAND)); |
844 sendToEventHandler((1 << RETURN_TOKEN_COMMAND) | tokens); | 844 sendToEventHandler((1 << RETURN_TOKEN_COMMAND) | tokens); |
845 tokens = 0; | 845 tokens = 0; |
846 } | 846 } |
847 } | 847 } |
848 } | 848 } |
849 | 849 |
850 void setHandlers({read, write, error, closed, destroyed}) { | 850 void setHandlers({read, write, error, closed, destroyed}) { |
851 eventHandlers[READ_EVENT] = read; | 851 eventHandlers[READ_EVENT] = read; |
852 eventHandlers[WRITE_EVENT] = write; | 852 eventHandlers[WRITE_EVENT] = write; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1046 native "Socket_SendTo"; | 1046 native "Socket_SendTo"; |
1047 nativeCreateConnect(List<int> addr, | 1047 nativeCreateConnect(List<int> addr, |
1048 int port) native "Socket_CreateConnect"; | 1048 int port) native "Socket_CreateConnect"; |
1049 nativeCreateBindListen(List<int> addr, int port, int backlog, bool v6Only) | 1049 nativeCreateBindListen(List<int> addr, int port, int backlog, bool v6Only) |
1050 native "ServerSocket_CreateBindListen"; | 1050 native "ServerSocket_CreateBindListen"; |
1051 nativeCreateBindDatagram(List<int> addr, int port, bool reuseAddress) | 1051 nativeCreateBindDatagram(List<int> addr, int port, bool reuseAddress) |
1052 native "Socket_CreateBindDatagram"; | 1052 native "Socket_CreateBindDatagram"; |
1053 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept"; | 1053 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept"; |
1054 int nativeGetPort() native "Socket_GetPort"; | 1054 int nativeGetPort() native "Socket_GetPort"; |
1055 List nativeGetRemotePeer() native "Socket_GetRemotePeer"; | 1055 List nativeGetRemotePeer() native "Socket_GetRemotePeer"; |
1056 int nativeGetSocketId() native "Socket_GetSocketId"; | |
1056 OSError nativeGetError() native "Socket_GetError"; | 1057 OSError nativeGetError() native "Socket_GetError"; |
1057 nativeGetOption(int option, int protocol) native "Socket_GetOption"; | 1058 nativeGetOption(int option, int protocol) native "Socket_GetOption"; |
1058 bool nativeSetOption(int option, int protocol, value) | 1059 bool nativeSetOption(int option, int protocol, value) |
1059 native "Socket_SetOption"; | 1060 native "Socket_SetOption"; |
1060 bool nativeJoinMulticast( | 1061 bool nativeJoinMulticast( |
1061 List<int> addr, List<int> interfaceAddr, int interfaceIndex) | 1062 List<int> addr, List<int> interfaceAddr, int interfaceIndex) |
1062 native "Socket_JoinMulticast"; | 1063 native "Socket_JoinMulticast"; |
1063 bool nativeLeaveMulticast( | 1064 bool nativeLeaveMulticast( |
1064 List<int> addr, List<int> interfaceAddr, int interfaceIndex) | 1065 List<int> addr, List<int> interfaceAddr, int interfaceIndex) |
1065 native "Socket_LeaveMulticast"; | 1066 native "Socket_LeaveMulticast"; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1140 } | 1141 } |
1141 } | 1142 } |
1142 | 1143 |
1143 void _onPauseStateChange() { | 1144 void _onPauseStateChange() { |
1144 if (_controller.isPaused) { | 1145 if (_controller.isPaused) { |
1145 _pause(); | 1146 _pause(); |
1146 } else { | 1147 } else { |
1147 _resume(); | 1148 _resume(); |
1148 } | 1149 } |
1149 } | 1150 } |
1151 | |
1152 RawServerSocketHandle clone() { | |
1153 var port = new ReceivePort(); | |
1154 port.first.then((sendPort) { | |
1155 sendPort.send( | |
1156 [_socket.nativeGetSocketId(), | |
1157 _socket.address, | |
1158 _socket.localPort]); | |
1159 port.close(); | |
1160 }); | |
1161 return new _RawServerSocketHandle(port.sendPort); | |
1162 } | |
1150 } | 1163 } |
1151 | 1164 |
1152 | 1165 |
1166 class _RawServerSocketHandle implements RawServerSocketHandle { | |
1167 final SendPort _sendPort; | |
1168 | |
1169 _RawServerSocketHandle(this._sendPort); | |
1170 | |
1171 Future<RawServerSocket> acquire() { | |
1172 var port = new ReceivePort(); | |
1173 _sendPort.send(port.sendPort); | |
1174 return port.first.then((args) { | |
1175 port.close(); | |
1176 var native = new _NativeSocket.listen(); | |
1177 native.nativeSetSocketId(args[0]); | |
1178 native.address = args[1]; | |
1179 native.localPort = args[2]; | |
1180 return new _RawServerSocket(native); | |
1181 }); | |
1182 } | |
1183 } | |
1184 | |
1185 | |
1153 class _RawSocket extends Stream<RawSocketEvent> | 1186 class _RawSocket extends Stream<RawSocketEvent> |
1154 implements RawSocket { | 1187 implements RawSocket { |
1155 final _NativeSocket _socket; | 1188 final _NativeSocket _socket; |
1156 StreamController<RawSocketEvent> _controller; | 1189 StreamController<RawSocketEvent> _controller; |
1157 bool _readEventsEnabled = true; | 1190 bool _readEventsEnabled = true; |
1158 bool _writeEventsEnabled = true; | 1191 bool _writeEventsEnabled = true; |
1159 | 1192 |
1160 // Flag to handle Ctrl-D closing of stdio on Mac OS. | 1193 // Flag to handle Ctrl-D closing of stdio on Mac OS. |
1161 bool _isMacOSTerminalInput = false; | 1194 bool _isMacOSTerminalInput = false; |
1162 | 1195 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1300 | 1333 |
1301 patch class ServerSocket { | 1334 patch class ServerSocket { |
1302 /* patch */ static Future<ServerSocket> bind(address, | 1335 /* patch */ static Future<ServerSocket> bind(address, |
1303 int port, | 1336 int port, |
1304 {int backlog: 0, | 1337 {int backlog: 0, |
1305 bool v6Only: false}) { | 1338 bool v6Only: false}) { |
1306 return _ServerSocket.bind(address, port, backlog, v6Only); | 1339 return _ServerSocket.bind(address, port, backlog, v6Only); |
1307 } | 1340 } |
1308 } | 1341 } |
1309 | 1342 |
1343 | |
1344 class _ServerSocketHandle implements ServerSocketHandle { | |
1345 final RawServerSocketHandle _rawHandle; | |
1346 | |
1347 _ServerSocketHandle(this._rawHandle); | |
1348 | |
1349 Future<ServerSocket> acquire() { | |
1350 return _rawHandle.acquire().then((raw) => new _ServerSocket(raw)); | |
1351 } | |
1352 } | |
1353 | |
1354 | |
1310 class _ServerSocket extends Stream<Socket> | 1355 class _ServerSocket extends Stream<Socket> |
1311 implements ServerSocket { | 1356 implements ServerSocket { |
1312 final _socket; | 1357 final _socket; |
1313 | 1358 |
1314 static Future<_ServerSocket> bind(address, | 1359 static Future<_ServerSocket> bind(address, |
1315 int port, | 1360 int port, |
1316 int backlog, | 1361 int backlog, |
1317 bool v6Only) { | 1362 bool v6Only) { |
1318 return _RawServerSocket.bind(address, port, backlog, v6Only) | 1363 return _RawServerSocket.bind(address, port, backlog, v6Only) |
1319 .then((socket) => new _ServerSocket(socket)); | 1364 .then((socket) => new _ServerSocket(socket)); |
(...skipping 10 matching lines...) Expand all Loading... | |
1330 onError: onError, | 1375 onError: onError, |
1331 onDone: onDone, | 1376 onDone: onDone, |
1332 cancelOnError: cancelOnError); | 1377 cancelOnError: cancelOnError); |
1333 } | 1378 } |
1334 | 1379 |
1335 int get port => _socket.port; | 1380 int get port => _socket.port; |
1336 | 1381 |
1337 InternetAddress get address => _socket.address; | 1382 InternetAddress get address => _socket.address; |
1338 | 1383 |
1339 Future close() => _socket.close().then((_) => this); | 1384 Future close() => _socket.close().then((_) => this); |
1385 | |
1386 ServerSocketHandle clone() { | |
1387 return new _ServerSocketHandle(_socket.clone()); | |
1388 } | |
1340 } | 1389 } |
1341 | 1390 |
1342 | 1391 |
1343 patch class Socket { | 1392 patch class Socket { |
1344 /* patch */ static Future<Socket> connect(host, int port) { | 1393 /* patch */ static Future<Socket> connect(host, int port) { |
1345 return RawSocket.connect(host, port).then( | 1394 return RawSocket.connect(host, port).then( |
1346 (socket) => new _Socket(socket)); | 1395 (socket) => new _Socket(socket)); |
1347 } | 1396 } |
1348 } | 1397 } |
1349 | 1398 |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1780 String address, | 1829 String address, |
1781 List<int> in_addr, | 1830 List<int> in_addr, |
1782 int port) { | 1831 int port) { |
1783 return new Datagram( | 1832 return new Datagram( |
1784 data, | 1833 data, |
1785 new _InternetAddress(address, null, in_addr), | 1834 new _InternetAddress(address, null, in_addr), |
1786 port); | 1835 port); |
1787 } | 1836 } |
1788 | 1837 |
1789 String _socketsStats() => _SocketsObservatory.toJSON(); | 1838 String _socketsStats() => _SocketsObservatory.toJSON(); |
OLD | NEW |