Skip to content

Commit

Permalink
Switches the mdns and uplink connect requests to a separate executor. (
Browse files Browse the repository at this point in the history
…#529)

Using the default executor in this place causes blockage of packet processing.
  • Loading branch information
balazsracz authored Apr 5, 2021
1 parent 2d1dd2d commit 962989e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/freertos_drivers/esp32/Esp32WiFiManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,16 @@ namespace openmrn_arduino
/// Esp32WiFiManager::apply_configuration.
static constexpr UBaseType_t WIFI_TASK_PRIORITY = 2;

/// Priority for the task performing the mdns lookups and connections for the
/// wifi uplink.
static constexpr UBaseType_t CONNECT_TASK_PRIORITY = 3;

/// Stack size for the wifi_manager_task.
static constexpr uint32_t WIFI_TASK_STACK_SIZE = 2560L;

/// Stack size for the connect_executor.
static constexpr uint32_t CONNECT_TASK_STACK_SIZE = 2560L;

/// Interval at which to check the WiFi connection status.
static constexpr TickType_t WIFI_CONNECT_CHECK_INTERVAL = pdMS_TO_TICKS(5000);

Expand Down Expand Up @@ -1058,10 +1065,15 @@ void Esp32WiFiManager::start_uplink()
{
unique_ptr<SocketClientParams> params(
new Esp32SocketParams(configFd_, cfg_.uplink()));
uplink_.reset(new SocketClient(stack_->service(), stack_->executor(),
stack_->executor(), std::move(params),
uplink_.reset(new SocketClient(stack_->service(), &connectExecutor_,
&connectExecutor_, std::move(params),
std::bind(&Esp32WiFiManager::on_uplink_created, this,
std::placeholders::_1, std::placeholders::_2)));
if (!connectExecutorStarted_) {
connectExecutorStarted_ = true;
connectExecutor_.start_thread(
"Esp32WiFiConn", CONNECT_TASK_PRIORITY, CONNECT_TASK_STACK_SIZE);
}
}

// Converts the passed fd into a GridConnect port and adds it to the stack.
Expand Down
6 changes: 6 additions & 0 deletions src/freertos_drivers/esp32/Esp32WiFiManager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ private:
/// Internal flag for tracking that the mDNS system has been initialized.
bool mdnsInitialized_{false};

/// True if we have started the connect executor thread.
bool connectExecutorStarted_{false};

/// Executor to use for the uplink connections.
Executor<1> connectExecutor_{NO_THREAD()};

/// Internal holder for mDNS entries which could not be published due to
/// mDNS not being initialized yet.
std::map<std::string, uint16_t> mdnsDeferredPublish_;
Expand Down

0 comments on commit 962989e

Please sign in to comment.