Original project changes: Improvements of the TCP client CAN logger fix by using a semaphore instead of a wait loop.
This commit is contained in:
parent
70575cd193
commit
de5abbbace
|
@ -34,7 +34,6 @@ static const char *TAG = "canlog-tcpclient";
|
|||
#include "canformat.h"
|
||||
#include "canlog_tcpclient.h"
|
||||
#include "ovms_config.h"
|
||||
#include "ovms_peripherals.h"
|
||||
|
||||
canlog_tcpclient* MyCanLogTcpClient = NULL;
|
||||
|
||||
|
@ -165,14 +164,7 @@ bool canlog_tcpclient::Open()
|
|||
if (mg_connect_opt(mgr, m_path.c_str(), tcMongooseHandler, opts) != NULL)
|
||||
{
|
||||
// Wait 10s max for connection establishment...
|
||||
m_connecting = true;
|
||||
int timeout = 10000000;
|
||||
const int step = 10000; // check every 10 ms
|
||||
while (m_connecting && timeout > 0)
|
||||
{
|
||||
timeout -= step;
|
||||
usleep(step);
|
||||
}
|
||||
m_connecting.Take(pdMS_TO_TICKS(10*1000));
|
||||
return m_isopen;
|
||||
}
|
||||
else
|
||||
|
@ -229,7 +221,6 @@ void canlog_tcpclient::MongooseHandler(struct mg_connection *nc, int ev, void *p
|
|||
{
|
||||
int *success = (int*)p;
|
||||
ESP_LOGV(TAG, "MongooseHandler(MG_EV_CONNECT=%d)",*success);
|
||||
m_connecting = false;
|
||||
if (*success == 0)
|
||||
{ // Connection successful
|
||||
OvmsRecMutexLock lock(&m_cmmutex);
|
||||
|
@ -250,6 +241,7 @@ void canlog_tcpclient::MongooseHandler(struct mg_connection *nc, int ev, void *p
|
|||
ESP_LOGE(TAG, "Connection failed to %s", m_path.c_str());
|
||||
m_isopen = false;
|
||||
}
|
||||
m_connecting.Give();
|
||||
}
|
||||
break;
|
||||
case MG_EV_CLOSE:
|
||||
|
@ -259,7 +251,6 @@ void canlog_tcpclient::MongooseHandler(struct mg_connection *nc, int ev, void *p
|
|||
OvmsRecMutexLock lock(&m_cmmutex);
|
||||
ESP_LOGE(TAG, "Disconnected from %s", m_path.c_str());
|
||||
m_isopen = false;
|
||||
m_connecting = false;
|
||||
auto k = m_connmap.find(nc);
|
||||
if (k != m_connmap.end())
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "canlog.h"
|
||||
#include "ovms_netmanager.h"
|
||||
#include "ovms_mutex.h"
|
||||
#include "ovms_semaphore.h"
|
||||
|
||||
class canlog_tcpclient : public canlog
|
||||
{
|
||||
|
@ -48,7 +49,7 @@ class canlog_tcpclient : public canlog
|
|||
|
||||
public:
|
||||
std::string m_path;
|
||||
bool m_connecting;
|
||||
OvmsSemaphore m_connecting;
|
||||
};
|
||||
|
||||
#endif // __CANLOG_TCP_CLIENT_H__
|
||||
|
|
Loading…
Reference in a new issue