Skip to content

Commit

Permalink
tcpclient: Add a mutex lock around mongoose actions
Browse files Browse the repository at this point in the history
  • Loading branch information
markwj committed Jul 20, 2019
1 parent d148f47 commit 202cab5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vehicle/OVMS.V3/components/can/src/canlog_tcpclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ void canlog_tcpclient::OutputMsg(CAN_log_message_t& msg)
std::string result = m_formatter->get(&msg);
if (result.length()>0)
{
OvmsMutexLock lock(&m_mgmutex);
if (m_mgconn->send_mbuf.len < 4096)
{
mg_send(m_mgconn, (const char*)result.c_str(), result.length());
Expand All @@ -188,6 +189,8 @@ void canlog_tcpclient::OutputMsg(CAN_log_message_t& msg)

void canlog_tcpclient::MongooseHandler(struct mg_connection *nc, int ev, void *p)
{
OvmsMutexLock lock(&m_mgmutex);

switch (ev)
{
case MG_EV_CONNECT:
Expand Down
2 changes: 2 additions & 0 deletions vehicle/OVMS.V3/components/can/src/canlog_tcpclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "canlog.h"
#include "ovms_netmanager.h"
#include "ovms_mutex.h"

class canlog_tcpclient : public canlog
{
Expand All @@ -50,6 +51,7 @@ class canlog_tcpclient : public canlog
void MongooseHandler(struct mg_connection *nc, int ev, void *p);

public:
OvmsMutex m_mgmutex;
struct mg_connection *m_mgconn;
bool m_isopen;

Expand Down

0 comments on commit 202cab5

Please sign in to comment.