How to setup a lambda expression as sigio on BufferedSerial

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;


//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.

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.
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.

    // Kick off the state machine to start connecting to the HTTP Asynchronous socket.

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