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

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

Issue 300883002: Add Proces owner of socket and fix printing of non-network sockets (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 return _RawServerSocket.bind(address, port, backlog, v6Only); 10 return _RawServerSocket.bind(address, port, backlog, v6Only);
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 if (port != 0) socket.localPort = port; 605 if (port != 0) socket.localPort = port;
606 return socket; 606 return socket;
607 }); 607 });
608 } 608 }
609 609
610 _NativeSocket.datagram(this.address) 610 _NativeSocket.datagram(this.address)
611 : typeFlags = TYPE_NORMAL_SOCKET | TYPE_UDP_SOCKET; 611 : typeFlags = TYPE_NORMAL_SOCKET | TYPE_UDP_SOCKET;
612 612
613 _NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET | TYPE_TCP_SOCKET; 613 _NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET | TYPE_TCP_SOCKET;
614 614
615 _NativeSocket.listen() : super(), typeFlags = TYPE_LISTENING_SOCKET | TYPE_TCP _SOCKET; 615 _NativeSocket.listen()
616 : super(),
Anders Johnsen 2014/05/28 06:53:32 Oh, this super call is not needed. Can you remove
Cutch 2014/05/28 07:07:41 Done.
617 typeFlags = TYPE_LISTENING_SOCKET | TYPE_TCP_SOCKET;
616 618
617 _NativeSocket.pipe() : typeFlags = TYPE_PIPE; 619 _NativeSocket.pipe() : typeFlags = TYPE_PIPE;
618 620
619 _NativeSocket.watch(int id) 621 _NativeSocket.watch(int id)
620 : typeFlags = TYPE_NORMAL_SOCKET | TYPE_INTERNAL_SOCKET { 622 : typeFlags = TYPE_NORMAL_SOCKET | TYPE_INTERNAL_SOCKET {
621 isClosedWrite = true; 623 isClosedWrite = true;
622 nativeSetSocketId(id); 624 nativeSetSocketId(id);
623 } 625 }
624 626
625 bool get isListening => (typeFlags & TYPE_LISTENING_SOCKET) != 0; 627 bool get isListening => (typeFlags & TYPE_LISTENING_SOCKET) != 0;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 if (!isClosedWrite) flags |= 1 << WRITE_EVENT; 897 if (!isClosedWrite) flags |= 1 << WRITE_EVENT;
896 sendToEventHandler(flags); 898 sendToEventHandler(flags);
897 } 899 }
898 } 900 }
899 901
900 Future close() { 902 Future close() {
901 if (!isClosing && !isClosed) { 903 if (!isClosing && !isClosed) {
902 sendToEventHandler(1 << CLOSE_COMMAND); 904 sendToEventHandler(1 << CLOSE_COMMAND);
903 isClosing = true; 905 isClosing = true;
904 } 906 }
907 _sockets.remove(_serviceId);
Anders Johnsen 2014/05/28 06:53:32 This should not be done here. If you have a case w
Cutch 2014/05/28 07:07:41 No, it was left over debugging stuff from yesterda
905 return closeCompleter.future; 908 return closeCompleter.future;
906 } 909 }
907 910
908 void shutdown(SocketDirection direction) { 911 void shutdown(SocketDirection direction) {
909 if (!isClosing && !isClosed) { 912 if (!isClosing && !isClosed) {
910 switch (direction) { 913 switch (direction) {
911 case SocketDirection.RECEIVE: 914 case SocketDirection.RECEIVE:
912 shutdownRead(); 915 shutdownRead();
913 break; 916 break;
914 case SocketDirection.SEND: 917 case SocketDirection.SEND:
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 var result = nativeLeaveMulticast( 1067 var result = nativeLeaveMulticast(
1065 addr._in_addr, 1068 addr._in_addr,
1066 interfaceAddr == null ? null : interfaceAddr._in_addr, 1069 interfaceAddr == null ? null : interfaceAddr._in_addr,
1067 interfaceIndex); 1070 interfaceIndex);
1068 if (result is OSError) throw result; 1071 if (result is OSError) throw result;
1069 } 1072 }
1070 1073
1071 String get _serviceTypePath => 'io/sockets'; 1074 String get _serviceTypePath => 'io/sockets';
1072 String get _serviceTypeName => 'Socket'; 1075 String get _serviceTypeName => 'Socket';
1073 1076
1074 Map _toJSON(bool ref) { 1077 String _JSONKind() {
1078 return isListening ? "LISTENING" :
1079 isPipe ? "PIPE" :
1080 isInternal ? "INTERNAL" : "NORMAL";
1081 }
1082
1083 Map _toJSONPipe(bool ref) {
1084 var name;
1085 if (isClosed) {
1086 name = 'CLOSED PIPE';
1087 } else if (isClosedWrite) {
1088 name = 'READ PIPE';
1089 } else if (isClosedRead) {
1090 name = 'WRITE PIPE';
1091 } else {
1092 name = 'R/W PIPE';
1093 }
1094 var r = {
1095 'id': _servicePath,
1096 'type': _serviceType(ref),
1097 'name': name,
1098 'user_name': name,
1099 'kind': _JSONKind(),
1100 };
1101 if (ref) {
1102 return r;
1103 }
1104 r['fd'] = nativeGetSocketId();
1105 if (owner != null) {
1106 r['owner'] = owner._toJSON(true);
1107 }
1108 return r;
1109 }
1110
1111 Map _toJSONNetwork(bool ref) {
1075 var name = '${address.host}:$port'; 1112 var name = '${address.host}:$port';
1076 if (isTcp && !isListening) name += " <-> ${remoteAddress.host}:$remotePort"; 1113 if (isTcp && !isListening) name += " <-> ${remoteAddress.host}:$remotePort";
1077 var r = { 1114 var r = {
1078 'id': _servicePath, 1115 'id': _servicePath,
1079 'type': _serviceType(ref), 1116 'type': _serviceType(ref),
1080 'name': name, 1117 'name': name,
1081 'user_name': name, 1118 'user_name': name,
1119 'kind': _JSONKind(),
1082 }; 1120 };
1083 if (ref) { 1121 if (ref) {
1084 return r; 1122 return r;
1085 } 1123 }
1086 r['port'] = port; 1124 r['port'] = port;
1087 r['address'] = address.host; 1125 r['address'] = address.host;
1088 r['fd'] = nativeGetSocketId(); 1126 r['fd'] = nativeGetSocketId();
1089 if (owner != null) { 1127 if (owner != null) {
1090 r['owner'] = owner._toJSON(true); 1128 r['owner'] = owner._toJSON(true);
1091 } 1129 }
1092 return r; 1130 return r;
1093 } 1131 }
1094 1132
1133 Map _toJSON(bool ref) {
1134 if (isPipe) {
1135 return _toJSONPipe(ref);
1136 }
1137 return _toJSONNetwork(ref);
1138 }
1139
1095 void nativeSetSocketId(int id) native "Socket_SetSocketId"; 1140 void nativeSetSocketId(int id) native "Socket_SetSocketId";
1096 nativeAvailable() native "Socket_Available"; 1141 nativeAvailable() native "Socket_Available";
1097 nativeRead(int len) native "Socket_Read"; 1142 nativeRead(int len) native "Socket_Read";
1098 nativeRecvFrom() native "Socket_RecvFrom"; 1143 nativeRecvFrom() native "Socket_RecvFrom";
1099 nativeWrite(List<int> buffer, int offset, int bytes) 1144 nativeWrite(List<int> buffer, int offset, int bytes)
1100 native "Socket_WriteList"; 1145 native "Socket_WriteList";
1101 nativeSendTo(List<int> buffer, int offset, int bytes, 1146 nativeSendTo(List<int> buffer, int offset, int bytes,
1102 List<int> address, int port) 1147 List<int> address, int port)
1103 native "Socket_SendTo"; 1148 native "Socket_SendTo";
1104 nativeCreateConnect(List<int> addr, 1149 nativeCreateConnect(List<int> addr,
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 String address, 1956 String address,
1912 List<int> in_addr, 1957 List<int> in_addr,
1913 int port) { 1958 int port) {
1914 return new Datagram( 1959 return new Datagram(
1915 data, 1960 data,
1916 new _InternetAddress(address, null, in_addr), 1961 new _InternetAddress(address, null, in_addr),
1917 port); 1962 port);
1918 } 1963 }
1919 1964
1920 String _socketsStats() => _SocketsObservatory.toJSON(); 1965 String _socketsStats() => _SocketsObservatory.toJSON();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698