| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 static const Duration _RETRY_DURATION_LOOPBACK = | 280 static const Duration _RETRY_DURATION_LOOPBACK = |
| 281 const Duration(milliseconds: 25); | 281 const Duration(milliseconds: 25); |
| 282 | 282 |
| 283 // Use default Map so we keep order. | 283 // Use default Map so we keep order. |
| 284 static Map<int, _NativeSocket> _sockets = new Map<int, _NativeSocket>(); | 284 static Map<int, _NativeSocket> _sockets = new Map<int, _NativeSocket>(); |
| 285 | 285 |
| 286 // Socket close state | 286 // Socket close state |
| 287 bool isClosed = false; | 287 bool isClosed = false; |
| 288 bool isClosing = false; | 288 bool isClosing = false; |
| 289 bool isClosedRead = false; | 289 bool isClosedRead = false; |
| 290 bool closedReadEventSent = false; | |
| 291 bool isClosedWrite = false; | 290 bool isClosedWrite = false; |
| 292 Completer closeCompleter = new Completer.sync(); | 291 Completer closeCompleter = new Completer.sync(); |
| 293 | 292 |
| 294 // Handlers and receive port for socket events from the event handler. | 293 // Handlers and receive port for socket events from the event handler. |
| 295 final List eventHandlers = new List(EVENT_COUNT + 1); | 294 final List eventHandlers = new List(EVENT_COUNT + 1); |
| 296 RawReceivePort eventPort; | 295 RawReceivePort eventPort; |
| 297 bool flagsSent = false; | 296 bool flagsSent = false; |
| 298 | 297 |
| 299 // The type flags for this socket. | 298 // The type flags for this socket. |
| 300 final int typeFlags; | 299 final int typeFlags; |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 return nativeGetRemotePeer()[1]; | 687 return nativeGetRemotePeer()[1]; |
| 689 } | 688 } |
| 690 | 689 |
| 691 InternetAddress get remoteAddress { | 690 InternetAddress get remoteAddress { |
| 692 var result = nativeGetRemotePeer()[0]; | 691 var result = nativeGetRemotePeer()[0]; |
| 693 var type = new InternetAddressType._from(result[0]); | 692 var type = new InternetAddressType._from(result[0]); |
| 694 return new _InternetAddress(result[1], null, result[2]); | 693 return new _InternetAddress(result[1], null, result[2]); |
| 695 } | 694 } |
| 696 | 695 |
| 697 void issueReadEvent() { | 696 void issueReadEvent() { |
| 698 if (closedReadEventSent) return; | |
| 699 if (readEventIssued) return; | 697 if (readEventIssued) return; |
| 700 readEventIssued = true; | 698 readEventIssued = true; |
| 701 void issue() { | 699 void issue() { |
| 702 readEventIssued = false; | 700 readEventIssued = false; |
| 703 if (isClosing) return; | 701 if (isClosing) return; |
| 704 if (!sendReadEvents) return; | 702 if (!sendReadEvents) return; |
| 705 if (available == 0) { | 703 if (available == 0) { |
| 706 if (isClosedRead && !closedReadEventSent) { | 704 if (isClosedRead) { |
| 707 if (isClosedWrite) close(); | 705 if (isClosedWrite) close(); |
| 708 var handler = eventHandlers[CLOSED_EVENT]; | 706 var handler = eventHandlers[CLOSED_EVENT]; |
| 709 if (handler == null) return; | 707 if (handler == null) return; |
| 710 closedReadEventSent = true; | |
| 711 handler(); | 708 handler(); |
| 712 } | 709 } |
| 713 return; | 710 return; |
| 714 } | 711 } |
| 715 var handler = eventHandlers[READ_EVENT]; | 712 var handler = eventHandlers[READ_EVENT]; |
| 716 if (handler == null) return; | 713 if (handler == null) return; |
| 717 readEventIssued = true; | 714 readEventIssued = true; |
| 718 handler(); | 715 handler(); |
| 719 scheduleMicrotask(issue); | 716 scheduleMicrotask(issue); |
| 720 } | 717 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 close(); | 853 close(); |
| 857 break; | 854 break; |
| 858 default: | 855 default: |
| 859 throw new ArgumentError(direction); | 856 throw new ArgumentError(direction); |
| 860 } | 857 } |
| 861 } | 858 } |
| 862 } | 859 } |
| 863 | 860 |
| 864 void shutdownWrite() { | 861 void shutdownWrite() { |
| 865 if (!isClosing && !isClosed) { | 862 if (!isClosing && !isClosed) { |
| 866 if (closedReadEventSent) { | 863 if (isClosedRead) { |
| 867 close(); | 864 close(); |
| 868 } else { | 865 } else { |
| 869 sendToEventHandler(1 << SHUTDOWN_WRITE_COMMAND); | 866 sendToEventHandler(1 << SHUTDOWN_WRITE_COMMAND); |
| 870 } | 867 } |
| 871 isClosedWrite = true; | 868 isClosedWrite = true; |
| 872 } | 869 } |
| 873 } | 870 } |
| 874 | 871 |
| 875 void shutdownRead() { | 872 void shutdownRead() { |
| 876 if (!isClosing && !isClosed) { | 873 if (!isClosing && !isClosed) { |
| (...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1967 String address, | 1964 String address, |
| 1968 List<int> in_addr, | 1965 List<int> in_addr, |
| 1969 int port) { | 1966 int port) { |
| 1970 return new Datagram( | 1967 return new Datagram( |
| 1971 data, | 1968 data, |
| 1972 new _InternetAddress(address, null, in_addr), | 1969 new _InternetAddress(address, null, in_addr), |
| 1973 port); | 1970 port); |
| 1974 } | 1971 } |
| 1975 | 1972 |
| 1976 String _socketsStats() => _SocketsObservatory.toJSON(); | 1973 String _socketsStats() => _SocketsObservatory.toJSON(); |
| OLD | NEW |