Chromium Code Reviews| 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 bool shared: false}) { | 10 bool shared: false}) { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 RawReceivePort eventPort; | 296 RawReceivePort eventPort; |
| 297 bool flagsSent = false; | 297 bool flagsSent = false; |
| 298 | 298 |
| 299 // The type flags for this socket. | 299 // The type flags for this socket. |
| 300 final int typeFlags; | 300 final int typeFlags; |
| 301 | 301 |
| 302 // Holds the port of the socket, 0 if not known. | 302 // Holds the port of the socket, 0 if not known. |
| 303 int localPort = 0; | 303 int localPort = 0; |
| 304 | 304 |
| 305 // Holds the address used to connect or bind the socket. | 305 // Holds the address used to connect or bind the socket. |
| 306 InternetAddress address; | 306 InternetAddress localAddress; |
| 307 | 307 |
| 308 int available = 0; | 308 int available = 0; |
| 309 | 309 |
| 310 int tokens = 0; | 310 int tokens = 0; |
| 311 | 311 |
| 312 bool sendReadEvents = false; | 312 bool sendReadEvents = false; |
| 313 bool readEventIssued = false; | 313 bool readEventIssued = false; |
| 314 | 314 |
| 315 bool sendWriteEvents = false; | 315 bool sendWriteEvents = false; |
| 316 bool writeEventIssued = false; | 316 bool writeEventIssued = false; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 void connectNext() { | 410 void connectNext() { |
| 411 if (!it.moveNext()) { | 411 if (!it.moveNext()) { |
| 412 if (connecting.isEmpty) { | 412 if (connecting.isEmpty) { |
| 413 assert(error != null); | 413 assert(error != null); |
| 414 completer.completeError(error); | 414 completer.completeError(error); |
| 415 } | 415 } |
| 416 return; | 416 return; |
| 417 } | 417 } |
| 418 var address = it.current; | 418 var address = it.current; |
| 419 var socket = new _NativeSocket.normal(); | 419 var socket = new _NativeSocket.normal(); |
| 420 socket.address = address; | 420 socket.localAddress = address; |
| 421 var result; | 421 var result; |
| 422 if (sourceAddress == null) { | 422 if (sourceAddress == null) { |
| 423 result = socket.nativeCreateConnect(address._in_addr, port); | 423 result = socket.nativeCreateConnect(address._in_addr, port); |
| 424 } else { | 424 } else { |
| 425 assert(sourceAddress is _InternetAddress); | 425 assert(sourceAddress is _InternetAddress); |
| 426 result = socket.nativeCreateBindConnect( | 426 result = socket.nativeCreateBindConnect( |
| 427 address._in_addr, port, sourceAddress._in_addr); | 427 address._in_addr, port, sourceAddress._in_addr); |
| 428 } | 428 } |
| 429 if (result is OSError) { | 429 if (result is OSError) { |
| 430 // Keep first error, if present. | 430 // Keep first error, if present. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 return lookup(host) | 483 return lookup(host) |
| 484 .then((list) { | 484 .then((list) { |
| 485 if (list.length == 0) { | 485 if (list.length == 0) { |
| 486 throw createError(response, "Failed host lookup: '$host'"); | 486 throw createError(response, "Failed host lookup: '$host'"); |
| 487 } | 487 } |
| 488 return list[0]; | 488 return list[0]; |
| 489 }); | 489 }); |
| 490 }) | 490 }) |
| 491 .then((address) { | 491 .then((address) { |
| 492 var socket = new _NativeSocket.listen(); | 492 var socket = new _NativeSocket.listen(); |
| 493 socket.address = address; | 493 socket.localAddress = address; |
| 494 | 494 |
| 495 var result = socket.nativeCreateBindListen(address._in_addr, | 495 var result = socket.nativeCreateBindListen(address._in_addr, |
| 496 port, | 496 port, |
| 497 backlog, | 497 backlog, |
| 498 v6Only, | 498 v6Only, |
| 499 shared); | 499 shared); |
| 500 if (result is OSError) { | 500 if (result is OSError) { |
| 501 throw new SocketException("Failed to create server socket", | 501 throw new SocketException("Failed to create server socket", |
| 502 osError: result, | 502 osError: result, |
| 503 address: address, | 503 address: address, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 530 throw new SocketException("Failed to create datagram socket", | 530 throw new SocketException("Failed to create datagram socket", |
| 531 osError: result, | 531 osError: result, |
| 532 address: address, | 532 address: address, |
| 533 port: port); | 533 port: port); |
| 534 } | 534 } |
| 535 if (port != 0) socket.localPort = port; | 535 if (port != 0) socket.localPort = port; |
| 536 return socket; | 536 return socket; |
| 537 }); | 537 }); |
| 538 } | 538 } |
| 539 | 539 |
| 540 _NativeSocket.datagram(this.address) | 540 _NativeSocket.datagram(this.localAddress) |
| 541 : typeFlags = TYPE_NORMAL_SOCKET | TYPE_UDP_SOCKET; | 541 : typeFlags = TYPE_NORMAL_SOCKET | TYPE_UDP_SOCKET; |
| 542 | 542 |
| 543 _NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET | TYPE_TCP_SOCKET; | 543 _NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET | TYPE_TCP_SOCKET; |
| 544 | 544 |
| 545 _NativeSocket.listen() : typeFlags = TYPE_LISTENING_SOCKET | TYPE_TCP_SOCKET { | 545 _NativeSocket.listen() : typeFlags = TYPE_LISTENING_SOCKET | TYPE_TCP_SOCKET { |
| 546 isClosedWrite = true; | 546 isClosedWrite = true; |
| 547 } | 547 } |
| 548 | 548 |
| 549 _NativeSocket.pipe() : typeFlags = TYPE_PIPE; | 549 _NativeSocket.pipe() : typeFlags = TYPE_PIPE; |
| 550 | 550 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 _NativeSocket accept() { | 664 _NativeSocket accept() { |
| 665 // Don't issue accept if we're closing. | 665 // Don't issue accept if we're closing. |
| 666 if (isClosing || isClosed) return null; | 666 if (isClosing || isClosed) return null; |
| 667 assert(available > 0); | 667 assert(available > 0); |
| 668 available--; | 668 available--; |
| 669 tokens++; | 669 tokens++; |
| 670 returnTokens(LISTENING_TOKEN_BATCH_SIZE); | 670 returnTokens(LISTENING_TOKEN_BATCH_SIZE); |
| 671 var socket = new _NativeSocket.normal(); | 671 var socket = new _NativeSocket.normal(); |
| 672 if (nativeAccept(socket) != true) return null; | 672 if (nativeAccept(socket) != true) return null; |
| 673 socket.localPort = localPort; | 673 socket.localPort = localPort; |
| 674 socket.address = address; | 674 socket.localAddress = address; |
| 675 totalRead += 1; | 675 totalRead += 1; |
| 676 lastRead = timestamp; | 676 lastRead = timestamp; |
| 677 return socket; | 677 return socket; |
| 678 } | 678 } |
| 679 | 679 |
| 680 int get port { | 680 int get port { |
| 681 if (isClosing || isClosed) throw const SocketException.closed(); | |
| 681 if (localPort != 0) return localPort; | 682 if (localPort != 0) return localPort; |
| 682 var result = nativeGetPort(); | 683 var result = nativeGetPort(); |
| 683 if (result is OSError) throw result; | 684 if (result is OSError) throw result; |
| 684 return localPort = result; | 685 return localPort = result; |
| 685 } | 686 } |
| 686 | 687 |
| 687 int get remotePort { | 688 int get remotePort { |
| 688 return nativeGetRemotePeer()[1]; | 689 if (isClosing || isClosed) throw const SocketException.closed(); |
| 690 var result = nativeGetRemotePeer(); | |
| 691 if (result is OSError) throw result; | |
| 692 return result[1]; | |
| 693 } | |
| 694 | |
| 695 InternetAddress get address { | |
|
Anders Johnsen
2015/03/09 12:00:45
This is a breaking change. Before we allowed the u
Søren Gjesse
2015/03/09 13:33:46
Yes (I had to fix a test), it is the same for port
| |
| 696 if (isClosing || isClosed) throw const SocketException.closed(); | |
| 697 return localAddress; | |
| 689 } | 698 } |
| 690 | 699 |
| 691 InternetAddress get remoteAddress { | 700 InternetAddress get remoteAddress { |
| 692 var result = nativeGetRemotePeer()[0]; | 701 if (isClosing || isClosed) throw const SocketException.closed(); |
| 693 var type = new InternetAddressType._from(result[0]); | 702 var result = nativeGetRemotePeer(); |
| 694 return new _InternetAddress(result[1], null, result[2]); | 703 if (result is OSError) throw result; |
| 704 var addr = result[0]; | |
| 705 var type = new InternetAddressType._from(addr[0]); | |
| 706 return new _InternetAddress(addr[1], null, addr[2]); | |
| 695 } | 707 } |
| 696 | 708 |
| 697 void issueReadEvent() { | 709 void issueReadEvent() { |
| 698 if (closedReadEventSent) return; | 710 if (closedReadEventSent) return; |
| 699 if (readEventIssued) return; | 711 if (readEventIssued) return; |
| 700 readEventIssued = true; | 712 readEventIssued = true; |
| 701 void issue() { | 713 void issue() { |
| 702 readEventIssued = false; | 714 readEventIssued = false; |
| 703 if (isClosing) return; | 715 if (isClosing) return; |
| 704 if (!sendReadEvents) return; | 716 if (!sendReadEvents) return; |
| (...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1698 _closeRawSocket(); | 1710 _closeRawSocket(); |
| 1699 _controllerClosed = true; | 1711 _controllerClosed = true; |
| 1700 _controller.close(); | 1712 _controller.close(); |
| 1701 } | 1713 } |
| 1702 | 1714 |
| 1703 bool setOption(SocketOption option, bool enabled) { | 1715 bool setOption(SocketOption option, bool enabled) { |
| 1704 if (_raw == null) return false; | 1716 if (_raw == null) return false; |
| 1705 return _raw.setOption(option, enabled); | 1717 return _raw.setOption(option, enabled); |
| 1706 } | 1718 } |
| 1707 | 1719 |
| 1708 int get port => _raw.port; | 1720 int get port { |
| 1709 InternetAddress get address => _raw.address; | 1721 if (_raw == null) throw const SocketException.closed();; |
| 1710 int get remotePort => _raw.remotePort; | 1722 return _raw.port; |
| 1711 InternetAddress get remoteAddress => _raw.remoteAddress; | 1723 } |
| 1724 | |
| 1725 InternetAddress get address { | |
| 1726 if (_raw == null) throw const SocketException.closed();; | |
| 1727 return _raw.address; | |
| 1728 } | |
| 1729 | |
| 1730 int get remotePort { | |
| 1731 if (_raw == null) throw const SocketException.closed();; | |
| 1732 return _raw.remotePort; | |
| 1733 } | |
| 1734 | |
| 1735 InternetAddress get remoteAddress { | |
| 1736 if (_raw == null) throw const SocketException.closed();; | |
| 1737 return _raw.remoteAddress; | |
| 1738 } | |
| 1712 | 1739 |
| 1713 Future _detachRaw() { | 1740 Future _detachRaw() { |
| 1714 _detachReady = new Completer(); | 1741 _detachReady = new Completer(); |
| 1715 _sink.close(); | 1742 _sink.close(); |
| 1716 return _detachReady.future.then((_) { | 1743 return _detachReady.future.then((_) { |
| 1717 assert(_consumer.buffer == null); | 1744 assert(_consumer.buffer == null); |
| 1718 var raw = _raw; | 1745 var raw = _raw; |
| 1719 _raw = null; | 1746 _raw = null; |
| 1720 return [raw, _subscription]; | 1747 return [raw, _subscription]; |
| 1721 }); | 1748 }); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1968 String address, | 1995 String address, |
| 1969 List<int> in_addr, | 1996 List<int> in_addr, |
| 1970 int port) { | 1997 int port) { |
| 1971 return new Datagram( | 1998 return new Datagram( |
| 1972 data, | 1999 data, |
| 1973 new _InternetAddress(address, null, in_addr), | 2000 new _InternetAddress(address, null, in_addr), |
| 1974 port); | 2001 port); |
| 1975 } | 2002 } |
| 1976 | 2003 |
| 1977 String _socketsStats() => _SocketsObservatory.toJSON(); | 2004 String _socketsStats() => _SocketsObservatory.toJSON(); |
| OLD | NEW |