AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
Stdin/main.cpp

Stdin example

Warning
Unix-like systems only
/*
Copyright (c) 2026 Alexandr Kuzmuk
This file is part of the AsyncFw project. Licensed under the MIT License.
See {Link: LICENSE file https://mit-license.org} in the project root for full license information.
*/
/*
* This exfample for Unix-like systems only
*/
#include <iostream>
#include <AsyncFw/MainThread>
#include <AsyncFw/PollNotifier>
int main(int argc, char *argv[]) {
AsyncFw::PollNotifier notifier(STDIN_FILENO);
notifier.notify([&notifier](AsyncFw::AbstractThread::PollEvents e) {
char buf[128];
int r = read(STDIN_FILENO, buf, sizeof(buf) - 1);
buf[r] = 0;
if (r == 2 && buf[0] == 'q') AsyncFw::MainThread::exit();
(std::cout << "stdin: " << buf).flush();
});
(std::cout << "Start Applicaiton" << std::endl).flush();
int ret = AsyncFw::MainThread::exec();
return ret;
}
The PollNotifier class Example:
Definition PollNotifier.h:15
FunctionConnectorProtected< PollNotifier >::Connector< AbstractThread::PollEvents > notify
The PollNotifier::notify connector.
Definition PollNotifier.h:33