Hello @t_huang ,
It’s been a while since I wrote this code but last time I did it, I did it like the below.
Enjoy
Nuertey
std::unique_ptr<Socket> g_pHTTPAsynchSocket;
std::unique_ptr<Event<void()> > g_pHTTPAsynchHandler;
// Since this method possesses state, ensure it is declared as a lambda
// so each new instantiation retains and maintains its unique state.
// Also, because non-capturing lambdas do decay to function pointers,
// use the unary-plus 'sorcery' operator to implicitly get the function pointer.
//
// https://stackoverflow.com/questions/18889028/a-positive-lambda-what-sorcery-is-this
auto *HTTPAsynchTransaction = +[]()
{
static bool initial_run = true;
// ...
};
// And to use it:
g_pHTTPAsynchHandler = std::make_unique<Event<void()> >(Utility::gs_MasterEventQueue.event(HTTPAsynchTransaction));
// Delegation from interrupt context to the main() context. Should an
// interrupt come in for a time-sensitive event, the main thread will
// be preempted and not prevent the event from firing on the main
// thread's context. Issues with mutex claims within privileged mode
// are also sidestepped.
g_pHTTPAsynchSocket->sigio(*g_pHTTPAsynchHandler.get());
// Kick off the state machine to start connecting to the HTTP Asynchronous socket.
(*g_pHTTPAsynchHandler.get())();