Open Jeroen88 opened 2 years ago
Here also should be added: if(errorCode() != BR_ERR_OK) return 0;
This will check for (among others) the connection being dropped during SSL negotiation.
This issue is causing poor performance of a program I'm running on a MKR 1500 to communicate via MQTT: about half the time when connecting to MQTT the program hangs indefinitely. I tried implementing @Jeroen88's clientRead() and clientWrite() but then it invariably won't connect at all. Any ideas why this is?
The problem of #56 is even bigger:
::ClientRead()
and::ClientWrite()
are called in bearssl ssl_io.c. If the socket client connection (Client *c
) is lost or reset by the peer, bothc->read(buf, len)
andc->write(buf, len)
will return a 0 (at least on the ESP32 but I think this is standard behavior also on an Arduino) thus causing an infinite loop instatic int run_until(br_sslio_context *ctx, unsigned target)
in ssl_io.c.In my situation this problem occurs on a bad WiFi connection, but I think it may also occur on a bad tcp/ip connection or if the peer closes the connection.
One solution would be to add a timeout in the
run_until()
function, but I think it is better not to touch the original library. So I made adaptations to::ClientRead()
and::ClientWrite()
that involve static variables, which I think is a bad programming habit, but this is the only way to record a state between calls to these functions. I did not introduce a new timeout value, but use the value of the socket clientc->getTimeout()
.