Skip to content

Commit

Permalink
canlog: tcpserver fix for start/stop/start same port
Browse files Browse the repository at this point in the history
  • Loading branch information
markwj committed Jul 11, 2019
1 parent 1d7197c commit dab6135
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions vehicle/OVMS.V3/components/can/src/canlog_tcpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ canlog_tcpserver::canlog_tcpserver(std::string path, std::string format)
m_path.append(":3000");
}
m_isopen = false;
m_mgconn = NULL;

if (m_formatter)
{
Expand All @@ -140,7 +141,8 @@ bool canlog_tcpserver::Open()
struct mg_mgr* mgr = MyNetManager.GetMongooseMgr();
if (mgr != NULL)
{
if (mg_bind(mgr, m_path.c_str(), tsMongooseHandler))
m_mgconn = mg_bind(mgr, m_path.c_str(), tsMongooseHandler);
if (m_mgconn != NULL)
{
m_isopen = true;
return true;
Expand Down Expand Up @@ -171,6 +173,8 @@ void canlog_tcpserver::Close()
m_smap.clear();
}
ESP_LOGI(TAG, "Closed TCP server log: %s", GetStats().c_str());
m_mgconn->flags |= MG_F_CLOSE_IMMEDIATELY;
m_mgconn = NULL;
m_isopen = false;
}
}
Expand Down Expand Up @@ -236,11 +240,13 @@ void canlog_tcpserver::MongooseHandler(struct mg_connection *nc, int ev, void *p
case MG_EV_CLOSE:
{
// Network connection has gone
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr), MG_SOCK_STRINGIFY_IP);
ESP_LOGI(TAG, "Log service disconnection from %s",addr);
auto k = m_smap.find(nc);
if (k != m_smap.end())
{
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr), MG_SOCK_STRINGIFY_IP);
ESP_LOGI(TAG, "Log service disconnection from %s",addr);
m_smap.erase(k);
}
break;
}

Expand Down
1 change: 1 addition & 0 deletions vehicle/OVMS.V3/components/can/src/canlog_tcpserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class canlog_tcpserver : public canlog
typedef std::map<mg_connection*, uint8_t> ts_map_t;
ts_map_t m_smap;
bool m_isopen;
struct mg_connection *m_mgconn;

public:
std::string m_path;
Expand Down

0 comments on commit dab6135

Please sign in to comment.