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

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

Issue 113923004: Only store the address bytes for an internet address in Dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
« no previous file with comments | « runtime/bin/socket.cc ('k') | sdk/lib/io/secure_socket.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 includeLinkLocal: includeLinkLocal, 55 includeLinkLocal: includeLinkLocal,
56 type: type); 56 type: type);
57 } 57 }
58 } 58 }
59 59
60 class _InternetAddress implements InternetAddress { 60 class _InternetAddress implements InternetAddress {
61 static const int _ADDRESS_LOOPBACK_IP_V4 = 0; 61 static const int _ADDRESS_LOOPBACK_IP_V4 = 0;
62 static const int _ADDRESS_LOOPBACK_IP_V6 = 1; 62 static const int _ADDRESS_LOOPBACK_IP_V6 = 1;
63 static const int _ADDRESS_ANY_IP_V4 = 2; 63 static const int _ADDRESS_ANY_IP_V4 = 2;
64 static const int _ADDRESS_ANY_IP_V6 = 3; 64 static const int _ADDRESS_ANY_IP_V6 = 3;
65 static const int _IPV4_ADDR_OFFSET = 4; 65 static const int _IPV4_ADDR_LENGTH = 4;
66 static const int _IPV6_ADDR_OFFSET = 8;
67 static const int _IPV6_ADDR_LENGTH = 16; 66 static const int _IPV6_ADDR_LENGTH = 16;
68 67
69 static _InternetAddress LOOPBACK_IP_V4 = 68 static _InternetAddress LOOPBACK_IP_V4 =
70 new _InternetAddress.fixed(_ADDRESS_LOOPBACK_IP_V4); 69 new _InternetAddress.fixed(_ADDRESS_LOOPBACK_IP_V4);
71 static _InternetAddress LOOPBACK_IP_V6 = 70 static _InternetAddress LOOPBACK_IP_V6 =
72 new _InternetAddress.fixed(_ADDRESS_LOOPBACK_IP_V6); 71 new _InternetAddress.fixed(_ADDRESS_LOOPBACK_IP_V6);
73 static _InternetAddress ANY_IP_V4 = 72 static _InternetAddress ANY_IP_V4 =
74 new _InternetAddress.fixed(_ADDRESS_ANY_IP_V4); 73 new _InternetAddress.fixed(_ADDRESS_ANY_IP_V4);
75 static _InternetAddress ANY_IP_V6 = 74 static _InternetAddress ANY_IP_V6 =
76 new _InternetAddress.fixed(_ADDRESS_ANY_IP_V6); 75 new _InternetAddress.fixed(_ADDRESS_ANY_IP_V6);
77 76
78 final InternetAddressType type;
79 final String address; 77 final String address;
80 final String _host; 78 final String _host;
81 final Uint8List _sockaddr_storage; 79 final Uint8List _in_addr;
80
81 InternetAddressType get type =>
82 _in_addr.length == _IPV4_ADDR_LENGTH ? InternetAddressType.IP_V4
83 : InternetAddressType.IP_V6;
82 84
83 String get host => _host != null ? _host : address; 85 String get host => _host != null ? _host : address;
84 86
85 bool get isLoopback { 87 bool get isLoopback {
86 switch (type) { 88 switch (type) {
87 case InternetAddressType.IP_V4: 89 case InternetAddressType.IP_V4:
88 return _sockaddr_storage[_IPV4_ADDR_OFFSET] == 127; 90 return _in_addr[0] == 127;
89 91
90 case InternetAddressType.IP_V6: 92 case InternetAddressType.IP_V6:
91 for (int i = 0; i < _IPV6_ADDR_LENGTH - 1; i++) { 93 for (int i = 0; i < _IPV6_ADDR_LENGTH - 1; i++) {
92 if (_sockaddr_storage[_IPV6_ADDR_OFFSET + i] != 0) return false; 94 if (_in_addr[i] != 0) return false;
93 } 95 }
94 int lastByteIndex = _IPV6_ADDR_OFFSET + _IPV6_ADDR_LENGTH - 1; 96 return _in_addr[_IPV6_ADDR_LENGTH - 1] == 1;
95 return _sockaddr_storage[lastByteIndex] == 1;
96 } 97 }
97 } 98 }
98 99
99 bool get isLinkLocal { 100 bool get isLinkLocal {
100 switch (type) { 101 switch (type) {
101 case InternetAddressType.IP_V4: 102 case InternetAddressType.IP_V4:
102 // Checking for 169.254.0.0/16. 103 // Checking for 169.254.0.0/16.
103 return _sockaddr_storage[_IPV4_ADDR_OFFSET] == 169 && 104 return _in_addr[0] == 169 && _in_addr[1] == 254;
104 _sockaddr_storage[_IPV4_ADDR_OFFSET + 1] == 254;
105 105
106 case InternetAddressType.IP_V6: 106 case InternetAddressType.IP_V6:
107 // Checking for fe80::/10. 107 // Checking for fe80::/10.
108 return _sockaddr_storage[_IPV6_ADDR_OFFSET] == 0xFE && 108 return _in_addr[0] == 0xFE && (_in_addr[1] & 0xB0) == 0x80;
109 (_sockaddr_storage[_IPV6_ADDR_OFFSET + 1] & 0xB0) == 0x80;
110 } 109 }
111 } 110 }
112 111
113 bool get isMulticast { 112 bool get isMulticast {
114 switch (type) { 113 switch (type) {
115 case InternetAddressType.IP_V4: 114 case InternetAddressType.IP_V4:
116 // Checking for 224.0.0.0 through 239.255.255.255. 115 // Checking for 224.0.0.0 through 239.255.255.255.
117 return _sockaddr_storage[_IPV4_ADDR_OFFSET] >= 224 && 116 return _in_addr[0] >= 224 && _in_addr[0] < 240;
118 _sockaddr_storage[_IPV4_ADDR_OFFSET] < 240;
119 117
120 case InternetAddressType.IP_V6: 118 case InternetAddressType.IP_V6:
121 // Checking for ff00::/8. 119 // Checking for ff00::/8.
122 return _sockaddr_storage[_IPV6_ADDR_OFFSET] == 0xFF; 120 return _in_addr[0] == 0xFF;
123 } 121 }
124 } 122 }
125 123
126 Future<InternetAddress> reverse() => _NativeSocket.reverseLookup(this); 124 Future<InternetAddress> reverse() => _NativeSocket.reverseLookup(this);
127 125
128 _InternetAddress(InternetAddressType this.type, 126 _InternetAddress(String this.address,
129 String this.address,
130 String this._host, 127 String this._host,
131 List<int> this._sockaddr_storage); 128 List<int> this._in_addr);
132 129
133 factory _InternetAddress.parse(String address) { 130 factory _InternetAddress.parse(String address) {
134 var type = address.indexOf(':') == -1 131 var in_addr = _parse(address);
135 ? InternetAddressType.IP_V4 132 if (in_addr == null) {
136 : InternetAddressType.IP_V6;
137 var raw = _parse(type._value, address);
138 if (raw == null) {
139 throw new ArgumentError("Invalid internet address $address"); 133 throw new ArgumentError("Invalid internet address $address");
140 } 134 }
141 return new _InternetAddress(type, address, null, raw); 135 return new _InternetAddress(address, null, in_addr);
142 } 136 }
143 137
144 factory _InternetAddress.fixed(int id) { 138 factory _InternetAddress.fixed(int id) {
145 var sockaddr = _fixed(id);
146 switch (id) { 139 switch (id) {
147 case _ADDRESS_LOOPBACK_IP_V4: 140 case _ADDRESS_LOOPBACK_IP_V4:
148 return new _InternetAddress( 141 var in_addr = new Uint8List(_IPV4_ADDR_LENGTH);
149 InternetAddressType.IP_V4, "127.0.0.1", null, sockaddr); 142 in_addr[0] = 127;
143 in_addr[_IPV4_ADDR_LENGTH - 1] = 1;
144 return new _InternetAddress("127.0.0.1", null, in_addr);
150 case _ADDRESS_LOOPBACK_IP_V6: 145 case _ADDRESS_LOOPBACK_IP_V6:
151 return new _InternetAddress( 146 var in_addr = new Uint8List(_IPV6_ADDR_LENGTH);
152 InternetAddressType.IP_V6, "::1", null, sockaddr); 147 in_addr[_IPV6_ADDR_LENGTH - 1] = 1;
148 return new _InternetAddress("::1", null, in_addr);
153 case _ADDRESS_ANY_IP_V4: 149 case _ADDRESS_ANY_IP_V4:
154 return new _InternetAddress( 150 var in_addr = new Uint8List(_IPV4_ADDR_LENGTH);
155 InternetAddressType.IP_V4, "0.0.0.0", "0.0.0.0", sockaddr); 151 return new _InternetAddress("0.0.0.0", "0.0.0.0", in_addr);
156 case _ADDRESS_ANY_IP_V6: 152 case _ADDRESS_ANY_IP_V6:
157 return new _InternetAddress( 153 var in_addr = new Uint8List(_IPV6_ADDR_LENGTH);
158 InternetAddressType.IP_V6, "::", "::", sockaddr); 154 return new _InternetAddress("::", "::", in_addr);
159 default: 155 default:
160 assert(false); 156 assert(false);
161 throw new ArgumentError(); 157 throw new ArgumentError();
162 } 158 }
163 } 159 }
164 160
165 // Create a clone of this _InternetAddress replacing the host. 161 // Create a clone of this _InternetAddress replacing the host.
166 _InternetAddress _cloneWithNewHost(String host) { 162 _InternetAddress _cloneWithNewHost(String host) {
167 return new _InternetAddress( 163 return new _InternetAddress(
168 type, address, host, new Uint8List.fromList(_sockaddr_storage)); 164 address, host, new Uint8List.fromList(_in_addr));
169 } 165 }
170 166
171 bool operator ==(other) { 167 bool operator ==(other) {
172 if (!(other is _InternetAddress)) return false; 168 if (!(other is _InternetAddress)) return false;
173 if (other.type != type) return false; 169 if (other.type != type) return false;
174 bool equals = true; 170 bool equals = true;
175 for (int i = 0; i < _sockaddr_storage.length && equals; i++) { 171 for (int i = 0; i < _in_addr.length && equals; i++) {
176 equals = other._sockaddr_storage[i] == _sockaddr_storage[i]; 172 equals = other._in_addr[i] == _in_addr[i];
177 } 173 }
178 return equals; 174 return equals;
179 } 175 }
180 176
181 int get hashCode { 177 int get hashCode {
182 int result = 1; 178 int result = 1;
183 for (int i = 0; i < _sockaddr_storage.length; i++) { 179 for (int i = 0; i < _in_addr.length; i++) {
184 result = (result * 31 + _sockaddr_storage[i]) & 0x3FFFFFFF; 180 result = (result * 31 + _in_addr[i]) & 0x3FFFFFFF;
185 } 181 }
186 return result; 182 return result;
187 } 183 }
188 184
189 String toString() { 185 String toString() {
190 return "InternetAddress('$address', ${type.name})"; 186 return "InternetAddress('$address', ${type.name})";
191 } 187 }
192 188
193 static Uint8List _fixed(int id) native "InternetAddress_Fixed"; 189 static Uint8List _parse(String address) native "InternetAddress_Parse";
194 static Uint8List _parse(int type, String address)
195 native "InternetAddress_Parse";
196 } 190 }
197 191
198 class _NetworkInterface implements NetworkInterface { 192 class _NetworkInterface implements NetworkInterface {
199 final String name; 193 final String name;
200 final int index; 194 final int index;
201 final List<InternetAddress> addresses = []; 195 final List<InternetAddress> addresses = [];
202 196
203 _NetworkInterface(this.name, this.index); 197 _NetworkInterface(this.name, this.index);
204 198
205 String toString() { 199 String toString() {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 271
278 static Future<List<InternetAddress>> lookup( 272 static Future<List<InternetAddress>> lookup(
279 String host, {InternetAddressType type: InternetAddressType.ANY}) { 273 String host, {InternetAddressType type: InternetAddressType.ANY}) {
280 return _IOService.dispatch(_SOCKET_LOOKUP, [host, type._value]) 274 return _IOService.dispatch(_SOCKET_LOOKUP, [host, type._value])
281 .then((response) { 275 .then((response) {
282 if (isErrorResponse(response)) { 276 if (isErrorResponse(response)) {
283 throw createError(response, "Failed host lookup: '$host'"); 277 throw createError(response, "Failed host lookup: '$host'");
284 } else { 278 } else {
285 return response.skip(1).map((result) { 279 return response.skip(1).map((result) {
286 var type = new InternetAddressType._from(result[0]); 280 var type = new InternetAddressType._from(result[0]);
287 return new _InternetAddress(type, result[1], host, result[2]); 281 return new _InternetAddress(result[1], host, result[2]);
288 }).toList(); 282 }).toList();
289 } 283 }
290 }); 284 });
291 } 285 }
292 286
293 static Future<InternetAddress> reverseLookup(InternetAddress addr) { 287 static Future<InternetAddress> reverseLookup(InternetAddress addr) {
294 return _IOService.dispatch(_SOCKET_REVERSE_LOOKUP, [addr._sockaddr_storage]) 288 return _IOService.dispatch(_SOCKET_REVERSE_LOOKUP, [addr._in_addr])
295 .then((response) { 289 .then((response) {
296 if (isErrorResponse(response)) { 290 if (isErrorResponse(response)) {
297 throw createError(response, "Failed reverse host lookup", addr); 291 throw createError(response, "Failed reverse host lookup", addr);
298 } else { 292 } else {
299 return addr._cloneWithNewHost(response); 293 return addr._cloneWithNewHost(response);
300 } 294 }
301 }); 295 });
302 } 296 }
303 297
304 static Future<List<NetworkInterface>> listInterfaces({ 298 static Future<List<NetworkInterface>> listInterfaces({
305 bool includeLoopback: false, 299 bool includeLoopback: false,
306 bool includeLinkLocal: false, 300 bool includeLinkLocal: false,
307 InternetAddressType type: InternetAddressType.ANY}) { 301 InternetAddressType type: InternetAddressType.ANY}) {
308 return _IOService.dispatch(_SOCKET_LIST_INTERFACES, [type._value]) 302 return _IOService.dispatch(_SOCKET_LIST_INTERFACES, [type._value])
309 .then((response) { 303 .then((response) {
310 if (isErrorResponse(response)) { 304 if (isErrorResponse(response)) {
311 throw createError(response, "Failed listing interfaces"); 305 throw createError(response, "Failed listing interfaces");
312 } else { 306 } else {
313 var map = response.skip(1) 307 var map = response.skip(1)
314 .fold(new Map<String, NetworkInterface>(), (map, result) { 308 .fold(new Map<String, NetworkInterface>(), (map, result) {
315 var type = new InternetAddressType._from(result[0]); 309 var type = new InternetAddressType._from(result[0]);
316 var name = result[3]; 310 var name = result[3];
317 var index = result[4]; 311 var index = result[4];
318 var address = new _InternetAddress( 312 var address = new _InternetAddress(result[1], "", result[2]);
319 type, result[1], "", result[2]);
320 if (!includeLinkLocal && address.isLinkLocal) return map; 313 if (!includeLinkLocal && address.isLinkLocal) return map;
321 if (!includeLoopback && address.isLoopback) return map; 314 if (!includeLoopback && address.isLoopback) return map;
322 map.putIfAbsent( 315 map.putIfAbsent(
323 name, () => new _NetworkInterface(name, index)); 316 name, () => new _NetworkInterface(name, index));
324 map[name].addresses.add(address); 317 map[name].addresses.add(address);
325 return map; 318 return map;
326 }); 319 });
327 return map.values.toList(); 320 return map.values.toList();
328 } 321 }
329 }); 322 });
330 } 323 }
331 324
332 static Future<_NativeSocket> connect(host, int port) { 325 static Future<_NativeSocket> connect(host, int port) {
333 return new Future.value(host) 326 return new Future.value(host)
334 .then((host) { 327 .then((host) {
335 if (host is _InternetAddress) return host; 328 if (host is _InternetAddress) return host;
336 return lookup(host) 329 return lookup(host)
337 .then((list) { 330 .then((list) {
338 if (list.length == 0) { 331 if (list.length == 0) {
339 throw createError(response, "Failed host lookup: '$host'"); 332 throw createError(response, "Failed host lookup: '$host'");
340 } 333 }
341 return list[0]; 334 return list[0];
342 }); 335 });
343 }) 336 })
344 .then((address) { 337 .then((address) {
345 var socket = new _NativeSocket.normal(); 338 var socket = new _NativeSocket.normal();
346 socket.address = address; 339 socket.address = address;
347 var result = socket.nativeCreateConnect( 340 var result = socket.nativeCreateConnect(
348 address._sockaddr_storage, port); 341 address._in_addr, port);
349 if (result is OSError) { 342 if (result is OSError) {
350 throw createError(result, "Connection failed", address, port); 343 throw createError(result, "Connection failed", address, port);
351 } else { 344 } else {
352 socket.port; // Query the local port, for error messages. 345 socket.port; // Query the local port, for error messages.
353 var completer = new Completer(); 346 var completer = new Completer();
354 // Setup handlers for receiving the first write event which 347 // Setup handlers for receiving the first write event which
355 // indicate that the socket is fully connected. 348 // indicate that the socket is fully connected.
356 socket.setHandlers( 349 socket.setHandlers(
357 write: () { 350 write: () {
358 socket.setListening(read: false, write: false); 351 socket.setListening(read: false, write: false);
(...skipping 21 matching lines...) Expand all
380 .then((list) { 373 .then((list) {
381 if (list.length == 0) { 374 if (list.length == 0) {
382 throw createError(response, "Failed host lookup: '$host'"); 375 throw createError(response, "Failed host lookup: '$host'");
383 } 376 }
384 return list[0]; 377 return list[0];
385 }); 378 });
386 }) 379 })
387 .then((address) { 380 .then((address) {
388 var socket = new _NativeSocket.listen(); 381 var socket = new _NativeSocket.listen();
389 socket.address = address; 382 socket.address = address;
390 var result = socket.nativeCreateBindListen(address._sockaddr_storage, 383 var result = socket.nativeCreateBindListen(address._in_addr,
391 port, 384 port,
392 backlog, 385 backlog,
393 v6Only); 386 v6Only);
394 if (result is OSError) { 387 if (result is OSError) {
395 throw new SocketException("Failed to create server socket", 388 throw new SocketException("Failed to create server socket",
396 osError: result, 389 osError: result,
397 address: address, 390 address: address,
398 port: port); 391 port: port);
399 } 392 }
400 if (port != 0) socket.localPort = port; 393 if (port != 0) socket.localPort = port;
(...skipping 10 matching lines...) Expand all
411 .then((list) { 404 .then((list) {
412 if (list.length == 0) { 405 if (list.length == 0) {
413 throw createError(response, "Failed host lookup: '$host'"); 406 throw createError(response, "Failed host lookup: '$host'");
414 } 407 }
415 return list[0]; 408 return list[0];
416 }); 409 });
417 }) 410 })
418 .then((address) { 411 .then((address) {
419 var socket = new _NativeSocket.datagram(address); 412 var socket = new _NativeSocket.datagram(address);
420 var result = socket.nativeCreateBindDatagram( 413 var result = socket.nativeCreateBindDatagram(
421 address._sockaddr_storage, port, reuseAddress); 414 address._in_addr, port, reuseAddress);
422 if (result is OSError) { 415 if (result is OSError) {
423 throw new SocketException("Failed to create datagram socket", 416 throw new SocketException("Failed to create datagram socket",
424 osError: result, 417 osError: result,
425 address: address, 418 address: address,
426 port: port); 419 port: port);
427 } 420 }
428 if (port != 0) socket.localPort = port; 421 if (port != 0) socket.localPort = port;
429 return socket; 422 return socket;
430 }); 423 });
431 } 424 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } 511 }
519 512
520 int send(List<int> buffer, int offset, int bytes, 513 int send(List<int> buffer, int offset, int bytes,
521 InternetAddress address, int port) { 514 InternetAddress address, int port) {
522 if (isClosing || isClosed) return 0; 515 if (isClosing || isClosed) return 0;
523 _BufferAndStart bufferAndStart = 516 _BufferAndStart bufferAndStart =
524 _ensureFastAndSerializableByteData( 517 _ensureFastAndSerializableByteData(
525 buffer, offset, bytes); 518 buffer, offset, bytes);
526 var result = nativeSendTo( 519 var result = nativeSendTo(
527 bufferAndStart.buffer, bufferAndStart.start, bytes, 520 bufferAndStart.buffer, bufferAndStart.start, bytes,
528 address._sockaddr_storage, port); 521 address._in_addr, port);
529 if (result is OSError) { 522 if (result is OSError) {
530 scheduleMicrotask(() => reportError(result, "Send failed")); 523 scheduleMicrotask(() => reportError(result, "Send failed"));
531 result = 0; 524 result = 0;
532 } 525 }
533 return result; 526 return result;
534 } 527 }
535 528
536 _NativeSocket accept() { 529 _NativeSocket accept() {
537 // Don't issue accept if we're closing. 530 // Don't issue accept if we're closing.
538 if (isClosing || isClosed) return null; 531 if (isClosing || isClosed) return null;
539 var socket = new _NativeSocket.normal(); 532 var socket = new _NativeSocket.normal();
540 if (nativeAccept(socket) != true) return null; 533 if (nativeAccept(socket) != true) return null;
541 socket.localPort = localPort; 534 socket.localPort = localPort;
542 socket.address = address; 535 socket.address = address;
543 return socket; 536 return socket;
544 } 537 }
545 538
546 int get port { 539 int get port {
547 if (localPort != 0) return localPort; 540 if (localPort != 0) return localPort;
548 return localPort = nativeGetPort(); 541 return localPort = nativeGetPort();
549 } 542 }
550 543
551 int get remotePort { 544 int get remotePort {
552 return nativeGetRemotePeer()[1]; 545 return nativeGetRemotePeer()[1];
553 } 546 }
554 547
555 InternetAddress get remoteAddress { 548 InternetAddress get remoteAddress {
556 var result = nativeGetRemotePeer()[0]; 549 var result = nativeGetRemotePeer()[0];
557 var type = new InternetAddressType._from(result[0]); 550 var type = new InternetAddressType._from(result[0]);
558 return new _InternetAddress(type, result[1], null, result[2]); 551 return new _InternetAddress(result[1], null, result[2]);
559 } 552 }
560 553
561 // Multiplexes socket events to the socket handlers. 554 // Multiplexes socket events to the socket handlers.
562 void multiplex(int events) { 555 void multiplex(int events) {
563 canActivateEvents = false; 556 canActivateEvents = false;
564 for (int i = FIRST_EVENT; i <= LAST_EVENT; i++) { 557 for (int i = FIRST_EVENT; i <= LAST_EVENT; i++) {
565 if (((events & (1 << i)) != 0)) { 558 if (((events & (1 << i)) != 0)) {
566 if ((i == CLOSED_EVENT || i == READ_EVENT) && isClosedRead) continue; 559 if ((i == CLOSED_EVENT || i == READ_EVENT) && isClosedRead) continue;
567 if (i == CLOSED_EVENT && 560 if (i == CLOSED_EVENT &&
568 typeFlags != TYPE_LISTENING_SOCKET && 561 typeFlags != TYPE_LISTENING_SOCKET &&
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 } 787 }
795 } else { 788 } else {
796 return null; 789 return null;
797 } 790 }
798 } 791 }
799 792
800 void joinMulticast(InternetAddress addr, NetworkInterface interface) { 793 void joinMulticast(InternetAddress addr, NetworkInterface interface) {
801 var interfaceAddr = multicastAddress(addr, interface); 794 var interfaceAddr = multicastAddress(addr, interface);
802 var interfaceIndex = interface == null ? 0 : interface.index; 795 var interfaceIndex = interface == null ? 0 : interface.index;
803 var result = nativeJoinMulticast( 796 var result = nativeJoinMulticast(
804 addr._sockaddr_storage, 797 addr._in_addr,
805 interfaceAddr == null ? null : interfaceAddr._sockaddr_storage, 798 interfaceAddr == null ? null : interfaceAddr._in_addr,
806 interfaceIndex); 799 interfaceIndex);
807 if (result is OSError) throw result; 800 if (result is OSError) throw result;
808 } 801 }
809 802
810 void leaveMulticast(InternetAddress addr, NetworkInterface interface) { 803 void leaveMulticast(InternetAddress addr, NetworkInterface interface) {
811 var interfaceAddr = multicastAddress(addr, interface); 804 var interfaceAddr = multicastAddress(addr, interface);
812 var interfaceIndex = interface == null ? 0 : interface.index; 805 var interfaceIndex = interface == null ? 0 : interface.index;
813 var result = nativeLeaveMulticast( 806 var result = nativeLeaveMulticast(
814 addr._sockaddr_storage, 807 addr._in_addr,
815 interfaceAddr == null ? null : interfaceAddr._sockaddr_storage, 808 interfaceAddr == null ? null : interfaceAddr._in_addr,
816 interfaceIndex); 809 interfaceIndex);
817 if (result is OSError) throw result; 810 if (result is OSError) throw result;
818 } 811 }
819 812
820 void nativeSetSocketId(int id) native "Socket_SetSocketId"; 813 void nativeSetSocketId(int id) native "Socket_SetSocketId";
821 nativeAvailable() native "Socket_Available"; 814 nativeAvailable() native "Socket_Available";
822 nativeRead(int len) native "Socket_Read"; 815 nativeRead(int len) native "Socket_Read";
823 nativeRecvFrom() native "Socket_RecvFrom"; 816 nativeRecvFrom() native "Socket_RecvFrom";
824 nativeWrite(List<int> buffer, int offset, int bytes) 817 nativeWrite(List<int> buffer, int offset, int bytes)
825 native "Socket_WriteList"; 818 native "Socket_WriteList";
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 void _onSubscriptionStateChange() { 1537 void _onSubscriptionStateChange() {
1545 if (_controller.hasListener) { 1538 if (_controller.hasListener) {
1546 _resume(); 1539 _resume();
1547 } else { 1540 } else {
1548 close(); 1541 close();
1549 } 1542 }
1550 } 1543 }
1551 } 1544 }
1552 1545
1553 Datagram _makeDatagram(List<int> data, 1546 Datagram _makeDatagram(List<int> data,
1554 bool ipV6,
1555 String address, 1547 String address,
1556 List<int> sockaddr_storage, 1548 List<int> in_addr,
1557 int port) { 1549 int port) {
1558 var addressType =
1559 ipV6 ? InternetAddressType.IP_V6 : InternetAddressType.IP_V4;
1560 return new Datagram( 1550 return new Datagram(
1561 data, 1551 data,
1562 new _InternetAddress(addressType, address, null, sockaddr_storage), 1552 new _InternetAddress(address, null, in_addr),
1563 port); 1553 port);
1564 } 1554 }
OLDNEW
« no previous file with comments | « runtime/bin/socket.cc ('k') | sdk/lib/io/secure_socket.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698