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

Side by Side Diff: runtime/bin/socket_patch.dart

Issue 975723002: Fix issues with Socket shutdown. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix copyright date Created 5 years, 9 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 | Annotate | Revision Log
OLDNEW
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
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;
290 bool isClosedWrite = false; 291 bool isClosedWrite = false;
291 Completer closeCompleter = new Completer.sync(); 292 Completer closeCompleter = new Completer.sync();
292 293
293 // Handlers and receive port for socket events from the event handler. 294 // Handlers and receive port for socket events from the event handler.
294 final List eventHandlers = new List(EVENT_COUNT + 1); 295 final List eventHandlers = new List(EVENT_COUNT + 1);
295 RawReceivePort eventPort; 296 RawReceivePort eventPort;
296 bool flagsSent = false; 297 bool flagsSent = false;
297 298
298 // The type flags for this socket. 299 // The type flags for this socket.
299 final int typeFlags; 300 final int typeFlags;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 return nativeGetRemotePeer()[1]; 688 return nativeGetRemotePeer()[1];
688 } 689 }
689 690
690 InternetAddress get remoteAddress { 691 InternetAddress get remoteAddress {
691 var result = nativeGetRemotePeer()[0]; 692 var result = nativeGetRemotePeer()[0];
692 var type = new InternetAddressType._from(result[0]); 693 var type = new InternetAddressType._from(result[0]);
693 return new _InternetAddress(result[1], null, result[2]); 694 return new _InternetAddress(result[1], null, result[2]);
694 } 695 }
695 696
696 void issueReadEvent() { 697 void issueReadEvent() {
698 if (closedReadEventSent) return;
697 if (readEventIssued) return; 699 if (readEventIssued) return;
698 readEventIssued = true; 700 readEventIssued = true;
699 void issue() { 701 void issue() {
700 readEventIssued = false; 702 readEventIssued = false;
701 if (isClosing) return; 703 if (isClosing) return;
702 if (!sendReadEvents) return; 704 if (!sendReadEvents) return;
703 if (available == 0) { 705 if (available == 0) {
704 if (isClosedRead) { 706 if (isClosedRead && !closedReadEventSent) {
705 if (isClosedWrite) close(); 707 if (isClosedWrite) close();
706 var handler = eventHandlers[CLOSED_EVENT]; 708 var handler = eventHandlers[CLOSED_EVENT];
707 if (handler == null) return; 709 if (handler == null) return;
710 closedReadEventSent = true;
708 handler(); 711 handler();
709 } 712 }
710 return; 713 return;
711 } 714 }
712 var handler = eventHandlers[READ_EVENT]; 715 var handler = eventHandlers[READ_EVENT];
713 if (handler == null) return; 716 if (handler == null) return;
714 readEventIssued = true; 717 readEventIssued = true;
715 handler(); 718 handler();
716 scheduleMicrotask(issue); 719 scheduleMicrotask(issue);
717 } 720 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 close(); 856 close();
854 break; 857 break;
855 default: 858 default:
856 throw new ArgumentError(direction); 859 throw new ArgumentError(direction);
857 } 860 }
858 } 861 }
859 } 862 }
860 863
861 void shutdownWrite() { 864 void shutdownWrite() {
862 if (!isClosing && !isClosed) { 865 if (!isClosing && !isClosed) {
863 if (isClosedRead) { 866 if (closedReadEventSent) {
864 close(); 867 close();
865 } else { 868 } else {
866 sendToEventHandler(1 << SHUTDOWN_WRITE_COMMAND); 869 sendToEventHandler(1 << SHUTDOWN_WRITE_COMMAND);
867 } 870 }
868 isClosedWrite = true; 871 isClosedWrite = true;
869 } 872 }
870 } 873 }
871 874
872 void shutdownRead() { 875 void shutdownRead() {
873 if (!isClosing && !isClosed) { 876 if (!isClosing && !isClosed) {
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 String address, 1967 String address,
1965 List<int> in_addr, 1968 List<int> in_addr,
1966 int port) { 1969 int port) {
1967 return new Datagram( 1970 return new Datagram(
1968 data, 1971 data,
1969 new _InternetAddress(address, null, in_addr), 1972 new _InternetAddress(address, null, in_addr),
1970 port); 1973 port);
1971 } 1974 }
1972 1975
1973 String _socketsStats() => _SocketsObservatory.toJSON(); 1976 String _socketsStats() => _SocketsObservatory.toJSON();
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/issue_22637_test.dart » ('j') | tests/standalone/io/issue_22637_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698