How to setup a lambda expression as sigio on BufferedSerial

Hi,
How to setup a lambda expression as sigio on BufferedSerial, because I want to catch some local variable in a function? like below

static void* SioThread(void* arg)
{
RpiHandle* rpi = (RpiHandle*) arg;
int running = TRUE;

rpi->gpio.port.cts->rise(&CtsEdge);   

//err ???
rpi->fd.serial_port->sigio (Callback< void()> {
if (rpi->fd.serial_port->readable()) {evenFlags.set(SERIAL_READABLE_FLAG);}
});

while (running) {
  int flags_read = event_flags.wait_any_for(SERIAL_READABLE_FLAG | PIPE_HAVEDATA_FLAG
                                                                  | CTS_CHANGED_FLAG,TIMEOUT_IN_MICROSECONDS, true);
  if (flags_read == 0) {...}

}
}

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())();

Using an event queue, we do it like this using a lambda.