#include <AsyncFw/Thread>
#include <AsyncFw/AbstractTlsSocket>
#include <AsyncFw/TlsContext>
#include <AsyncFw/LogStream>
#include <AsyncFw/AddressInfo>
#include <AsyncFw/MainThread>
public:
void stateEvent() {
logDebug() << "State event:" << static_cast<int>(state_);
if (state_ == Active) {
logDebug() << "Send request";
write("GET /a-ucontrol/AsyncFw HTTP/1.1\r\nHost:github.com\r\nConnection:close\r\n\r\n");
} else if (error() >= Closed) {
if (error() != Closed) logError() << errorString();
else {
logNotice() << "Received:" << da;
logDebug() << da.view(0, 512) << "...";
}
if (h) {
h.promise().resume_queued();
h = {};
return;
}
AsyncFw::MainThread::exit(0);
}
}
void readEvent() {
logTrace() <<
"Read event:" << _da.size() << std::endl << _da.
view(0, 256);
da += _da;
}
h = _h;
connect(address, port);
});
}
private:
AsyncFw::CoroutineHandle h;
};
int main(int argc, char *argv[]) {
if (!context.
setDefaultVerifyPaths()) {
logError("Can't set default verify paths");
return -1;
}
context.
setVerifyName(
"github.com");
TcpSocket socket;
socket.setContext(context);
AsyncFw::CoroutineHandle h =
co_await addressInfo.
coResolve(
"github.com");
AsyncFw::AddressInfo::Result list = h.promise().data<AsyncFw::AddressInfo::Result>();
if (list.empty()) {
logError("Resolve error");
AsyncFw::MainThread::exit(-1);
co_return;
}
for (const std::string _s : list) logNotice() << _s;
co_await socket.coConnect(list[0], 443);
AsyncFw::MainThread::exit(0);
}};
coroTask();
logNotice() << "Start Applicaiton";
int ret = AsyncFw::MainThread::exec();
logNotice() << "End Applicaiton" << ret;
return ret;
}
The AbstractTlsSocket class provides the base functionality for TLS encrypted socket.
Definition AbstractTlsSocket.h:17
The AddressInfo class.
Definition AddressInfo.h:29
AsyncFw::CoroutineAwait coResolve(const std::string &, Family=Inet)
The AddressInfo::coResolve coroutine awaiter.
Definition AddressInfo.cpp:129
The DataArray class.
Definition DataArray.h:20
The TlsContext class provides functionality for managing TLS certificates.
Definition TlsContext.h:24
The CoroutineAwait struct.
Definition Coroutine.h:53
The CoroutineTask struct.
Definition Coroutine.h:20