Open hitecSmartHome opened 1 month ago
This portion of the code looks unfinished in PsychicEventSource.cpp
void PsychicEventSourceClient::sendEvent(const char *event) {
if( !this->server() || !this->socket() ){
return;
}
int result;
do {
result = httpd_socket_send(this->server(), this->socket(), event, strlen(event), 0);
} while (result == HTTPD_SOCK_ERR_TIMEOUT);
//if (result < 0)
//error log here
}
httpd_socket_send
API states the following
Returns:
Bytes : The number of bytes sent successfully
- HTTPD_SOCK_ERR_INVALID : Invalid arguments
- HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket send()
- HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket send()
-
Note:
This API is not recommended to be used in any request handler.
Use this only for advanced use cases, wherein some asynchronous data is to be sent over a socket.
This internally calls the default send function, or the function registered by httpd_sess_set_send_override().
Why is there a do while loop? Can't we just do this?
void PsychicEventSourceClient::sendEvent(const char *event) {
if( !this->server() || !this->socket() ){return;}
httpd_socket_send(this->server(), this->socket(), event, strlen(event), 0);
}
or better
bool PsychicEventSourceClient::sendEvent(const char *event) {
if( !this->server() || !this->socket() ){return false;}
int result = httpd_socket_send(this->server(), this->socket(), event, strlen(event), 0);
if( result == HTTPD_SOCK_ERR_INVALID || result == HTTPD_SOCK_ERR_TIMEOUT || result == HTTPD_SOCK_ERR_FAIL ){
return false;
}
return true;
}
For sure something is fishy in here
Hi! Amazing lib. I had a crash on event.send() the last day.
I have this wrapper around
events.send()
This method called frequently. The crash clearly was in here
The esp was working great. It was up for 2 and a half days but crashed with this error.
Any idea?