[nnbd] Reland backporting socket option semantics from NNBD dart:io.
The Socket class will now throw a SocketException if the socket has been destroyed or upgraded to a secure socket upon setting or getting socket options. The NNBD migration required making subtle changes to some dart:io semantics in order to provide a better API. This change backports one of these semantic changes to the unmigrated SDK so any issues can be discovered now instead of blocking the future SDK unfork. Change-Id: If7029f8b42fd4b05cfb79eb439c09dc206dd3b92 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134328 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Commit-Queue: Jonas Termansen <sortie@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
a71d60c1cf
commit
fddbc53a64
@@ -17,6 +17,11 @@ used (see Issue [39627][]).
|
||||
|
||||
#### `dart:io`
|
||||
|
||||
* The `Socket` class will now throw a `SocketException` if the socket has been
|
||||
destroyed or upgraded to a secure socket upon setting or getting socket
|
||||
options. Previously setting a socket options would be ignored and getting a
|
||||
socket option would return `null`.
|
||||
|
||||
### Dart VM
|
||||
|
||||
### Tools
|
||||
|
||||
@@ -1779,40 +1779,37 @@ class _Socket extends Stream<Uint8List> implements Socket {
|
||||
}
|
||||
|
||||
bool setOption(SocketOption option, bool enabled) {
|
||||
if (_raw == null) return false;
|
||||
if (_raw == null) throw const SocketException.closed();
|
||||
return _raw.setOption(option, enabled);
|
||||
}
|
||||
|
||||
Uint8List getRawOption(RawSocketOption option) {
|
||||
if (_raw == null) return null;
|
||||
if (_raw == null) throw const SocketException.closed();
|
||||
return _raw.getRawOption(option);
|
||||
}
|
||||
|
||||
void setRawOption(RawSocketOption option) {
|
||||
_raw?.setRawOption(option);
|
||||
if (_raw == null) throw const SocketException.closed();
|
||||
_raw.setRawOption(option);
|
||||
}
|
||||
|
||||
int get port {
|
||||
if (_raw == null) throw const SocketException.closed();
|
||||
;
|
||||
return _raw.port;
|
||||
}
|
||||
|
||||
InternetAddress get address {
|
||||
if (_raw == null) throw const SocketException.closed();
|
||||
;
|
||||
return _raw.address;
|
||||
}
|
||||
|
||||
int get remotePort {
|
||||
if (_raw == null) throw const SocketException.closed();
|
||||
;
|
||||
return _raw.remotePort;
|
||||
}
|
||||
|
||||
InternetAddress get remoteAddress {
|
||||
if (_raw == null) throw const SocketException.closed();
|
||||
;
|
||||
return _raw.remoteAddress;
|
||||
}
|
||||
|
||||
|
||||
+23
-2
@@ -652,21 +652,29 @@ abstract class RawSocket implements Stream<RawSocketEvent> {
|
||||
|
||||
/**
|
||||
* Returns the port used by this socket.
|
||||
*
|
||||
* Throws a [SocketException] if the socket is closed.
|
||||
*/
|
||||
int get port;
|
||||
|
||||
/**
|
||||
* Returns the remote port connected to by this socket.
|
||||
*
|
||||
* Throws a [SocketException] if the socket is closed.
|
||||
*/
|
||||
int get remotePort;
|
||||
|
||||
/**
|
||||
* Returns the [InternetAddress] used to connect this socket.
|
||||
*
|
||||
* Throws a [SocketException] if the socket is closed.
|
||||
*/
|
||||
InternetAddress get address;
|
||||
|
||||
/**
|
||||
* Returns the remote [InternetAddress] connected to by this socket.
|
||||
*
|
||||
* Throws a [SocketException] if the socket is closed.
|
||||
*/
|
||||
InternetAddress get remoteAddress;
|
||||
|
||||
@@ -791,6 +799,9 @@ abstract class Socket implements Stream<Uint8List>, IOSink {
|
||||
* available options.
|
||||
*
|
||||
* Returns [:true:] if the option was set successfully, false otherwise.
|
||||
*
|
||||
* Throws a [SocketException] if the socket has been destroyed or upgraded to
|
||||
* a secure socket.
|
||||
*/
|
||||
bool setOption(SocketOption option, bool enabled);
|
||||
|
||||
@@ -800,7 +811,8 @@ abstract class Socket implements Stream<Uint8List>, IOSink {
|
||||
*
|
||||
* Returns the [RawSocketOption.value] on success.
|
||||
*
|
||||
* Throws an [OSError] on failure.
|
||||
* Throws an [OSError] on failure and a [SocketException] if the socket has
|
||||
* been destroyed or upgraded to a secure socket.
|
||||
*/
|
||||
Uint8List getRawOption(RawSocketOption option);
|
||||
|
||||
@@ -808,27 +820,36 @@ abstract class Socket implements Stream<Uint8List>, IOSink {
|
||||
* Use [setRawOption] to customize the [RawSocket]. See [RawSocketOption] for
|
||||
* available options.
|
||||
*
|
||||
* Throws an [OSError] on failure.
|
||||
* Throws an [OSError] on failure and a [SocketException] if the socket has
|
||||
* been destroyed or upgraded to a secure socket.
|
||||
*/
|
||||
void setRawOption(RawSocketOption option);
|
||||
|
||||
/**
|
||||
* Returns the port used by this socket.
|
||||
*
|
||||
* Throws a [SocketException] if the socket is closed.
|
||||
*/
|
||||
int get port;
|
||||
|
||||
/**
|
||||
* Returns the remote port connected to by this socket.
|
||||
*
|
||||
* Throws a [SocketException] if the socket is closed.
|
||||
*/
|
||||
int get remotePort;
|
||||
|
||||
/**
|
||||
* Returns the [InternetAddress] used to connect this socket.
|
||||
*
|
||||
* Throws a [SocketException] if the socket is closed.
|
||||
*/
|
||||
InternetAddress get address;
|
||||
|
||||
/**
|
||||
* Returns the remote [InternetAddress] connected to by this socket.
|
||||
*
|
||||
* Throws a [SocketException] if the socket is closed.
|
||||
*/
|
||||
InternetAddress get remoteAddress;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user