examples/protocols/asio: use common network component

* Original commit: espressif/esp-idf@aa4a7804ec
This commit is contained in:
Ivan Grokhotkov
2018-11-21 00:44:31 +08:00
committed by gabsuren
parent de830e51d4
commit 3e7591e92a
36 changed files with 161 additions and 850 deletions

View File

@ -1,6 +1,10 @@
#include "asio.hpp"
#include <string>
#include <iostream>
#include "protocol_examples_common.h"
#include "esp_event.h"
#include "tcpip_adapter.h"
#include "nvs_flash.h"
using asio::ip::tcp;
@ -27,6 +31,7 @@ private:
{
if (!ec)
{
data_[length] = 0;
std::cout << data_ << std::endl;
do_write(length);
}
@ -79,13 +84,24 @@ private:
};
void asio_main()
extern "C" void app_main()
{
ESP_ERROR_CHECK(nvs_flash_init());
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
* Read "Establishing Wi-Fi or Ethernet Connection" section in
* examples/protocols/README.md for more information about this function.
*/
ESP_ERROR_CHECK(example_connect());
/* This helper function configures blocking UART I/O */
ESP_ERROR_CHECK(example_configure_stdin_stdout());
asio::io_context io_context;
server s(io_context, std::atoi(CONFIG_EXAMPLE_PORT));
io_context.run();
}