Closed Ifilehk closed 1 year ago
Thank you for pointing this out, @Ifilehk! Do you already have a potential patch ready that could be applied to address this issue?
For the client side
--- a/original
+++ b/patch
@@ -1,23 +1,30 @@
void _connectToPeer() {
final ret = _libSsl.SSL_connect(_ssl);
- _maintainOutgoing();
+ int res = _maintainOutgoing();
if (ret == 1) {
_connected = true;
_connectCompleter.complete(this);
} else if (ret == 0) {
- _connectCompleter.completeError(DtlsException('handshake shut down'));
+ _connectCompleter.completeError(DtlsException('handshake shut down'));
} else {
- _handleError(ret, _connectCompleter.completeError);
+ if (res == 0) {
+ _connectCompleter.completeError(SocketException('Network is unreachable'));
+ } else {
+ _handleError(ret, _connectCompleter.completeError);
+ }
}
}
- void _maintainOutgoing() {
+
+ int _maintainOutgoing() {
final ret = _libCrypto.BIO_read(_wbio, buffer.cast(), bufferSize);
+ int r = -1;
if (ret > 0) {
- _dtlsClient._socket.send(buffer.asTypedList(ret), _address, _port);
+ r = _dtlsClient._socket.send(buffer.asTypedList(ret), _address, _port);
}
_timer?.cancel();
if (_libSsl.SSL_ctrl(_ssl, DTLS_CTRL_GET_TIMEOUT, 0, buffer.cast()) > 0) {
_timer = Timer(buffer.cast<timeval>().ref.duration, _maintainState);
}
+ return r;
}
``
For the server side adapter off => unhandled exception and death of the process. Hope dart:io will catch it one day, or if you have a clue let me know ...
Can you have a look at #55? After merging I will release a new patch version.
This exception occurs when during an open connection the adapter is turned off. Not really annoying on Desktops but on mobiles where we often turn WIFI on and off a must. I realized that this exception cannot be catch for what ever isolates reasons but a check of number of returned written bytes from
_socket.send
can help.