| 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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. |
| 431 if (error == null) { | 431 if (error == null) { |
| 432 error = createError(result, "Connection failed", address, port); | 432 error = createError(result, "Connection failed", address, port); |
| 433 } | 433 } |
| 434 connectNext(); | 434 connectNext(); |
| 435 } else { | 435 } else { |
| 436 socket.port; // Query the local port, for error messages. | 436 // Query the local port, for error messages. |
| 437 socket.port; |
| 437 // Set up timer for when we should retry the next address | 438 // Set up timer for when we should retry the next address |
| 438 // (if any). | 439 // (if any). |
| 439 var duration = address.isLoopback ? | 440 var duration = address.isLoopback ? |
| 440 _RETRY_DURATION_LOOPBACK : | 441 _RETRY_DURATION_LOOPBACK : |
| 441 _RETRY_DURATION; | 442 _RETRY_DURATION; |
| 442 var timer = new Timer(duration, connectNext); | 443 var timer = new Timer(duration, connectNext); |
| 443 connecting[socket] = timer; | 444 connecting[socket] = timer; |
| 444 // Setup handlers for receiving the first write event which | 445 // Setup handlers for receiving the first write event which |
| 445 // indicate that the socket is fully connected. | 446 // indicate that the socket is fully connected. |
| 446 socket.setHandlers( | 447 socket.setHandlers( |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 var socket = new _NativeSocket.normal(); | 672 var socket = new _NativeSocket.normal(); |
| 672 if (nativeAccept(socket) != true) return null; | 673 if (nativeAccept(socket) != true) return null; |
| 673 socket.localPort = localPort; | 674 socket.localPort = localPort; |
| 674 socket.localAddress = address; | 675 socket.localAddress = address; |
| 675 totalRead += 1; | 676 totalRead += 1; |
| 676 lastRead = timestamp; | 677 lastRead = timestamp; |
| 677 return socket; | 678 return socket; |
| 678 } | 679 } |
| 679 | 680 |
| 680 int get port { | 681 int get port { |
| 682 if (localPort != 0) return localPort; |
| 681 if (isClosing || isClosed) throw const SocketException.closed(); | 683 if (isClosing || isClosed) throw const SocketException.closed(); |
| 682 if (localPort != 0) return localPort; | |
| 683 var result = nativeGetPort(); | 684 var result = nativeGetPort(); |
| 684 if (result is OSError) throw result; | 685 if (result is OSError) throw result; |
| 685 return localPort = result; | 686 return localPort = result; |
| 686 } | 687 } |
| 687 | 688 |
| 688 int get remotePort { | 689 int get remotePort { |
| 689 if (isClosing || isClosed) throw const SocketException.closed(); | 690 if (isClosing || isClosed) throw const SocketException.closed(); |
| 690 var result = nativeGetRemotePeer(); | 691 var result = nativeGetRemotePeer(); |
| 691 if (result is OSError) throw result; | 692 if (result is OSError) throw result; |
| 692 return result[1]; | 693 return result[1]; |
| 693 } | 694 } |
| 694 | 695 |
| 695 InternetAddress get address { | 696 InternetAddress get address => localAddress; |
| 696 if (isClosing || isClosed) throw const SocketException.closed(); | |
| 697 return localAddress; | |
| 698 } | |
| 699 | 697 |
| 700 InternetAddress get remoteAddress { | 698 InternetAddress get remoteAddress { |
| 701 if (isClosing || isClosed) throw const SocketException.closed(); | 699 if (isClosing || isClosed) throw const SocketException.closed(); |
| 702 var result = nativeGetRemotePeer(); | 700 var result = nativeGetRemotePeer(); |
| 703 if (result is OSError) throw result; | 701 if (result is OSError) throw result; |
| 704 var addr = result[0]; | 702 var addr = result[0]; |
| 705 var type = new InternetAddressType._from(addr[0]); | 703 var type = new InternetAddressType._from(addr[0]); |
| 706 return new _InternetAddress(addr[1], null, addr[2]); | 704 return new _InternetAddress(addr[1], null, addr[2]); |
| 707 } | 705 } |
| 708 | 706 |
| (...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1995 String address, | 1993 String address, |
| 1996 List<int> in_addr, | 1994 List<int> in_addr, |
| 1997 int port) { | 1995 int port) { |
| 1998 return new Datagram( | 1996 return new Datagram( |
| 1999 data, | 1997 data, |
| 2000 new _InternetAddress(address, null, in_addr), | 1998 new _InternetAddress(address, null, in_addr), |
| 2001 port); | 1999 port); |
| 2002 } | 2000 } |
| 2003 | 2001 |
| 2004 String _socketsStats() => _SocketsObservatory.toJSON(); | 2002 String _socketsStats() => _SocketsObservatory.toJSON(); |
| OLD | NEW |