#include <AsyncFw/MainThread>
#include <AsyncFw/AbstractTlsSocket>
#include <AsyncFw/TlsContext>
#include <AsyncFw/AddressInfo>
#include <AsyncFw/File>
#include <AsyncFw/HttpSocket>
#include <AsyncFw/Log>
#define SERVER_NAME "github.com"
#define SERVER_PORT 443
#define GET_FILE "/a-ucontrol/AsyncFw"
int main(int argc, char *argv[]) {
if (!context.
setDefaultVerifyPaths()) {
logError("Can't set default verify paths");
return -1;
}
context.
setVerifyName(SERVER_NAME);
socket->
setContext(context);
addressInfo.
setTimeout(30000);
addressInfo.
resolve(SERVER_NAME);
addressInfo.
completed([&socket](
int r,
const std::vector<std::string> &list) {
if (r == 0 && !list.empty()) {
for (const std::string _s : list) logNotice() << _s;
socket->
connect(list[0], SERVER_PORT);
return;
}
AsyncFw::MainThread::exit(-1);
});
socket->
stateChanged([&socket](
const AsyncFw::AbstractSocket::State state) {
if (state == AsyncFw::AbstractSocket::State::Active) {
logDebug() << "Send request";
socket->
write(
"GET " GET_FILE
" HTTP/1.1\r\nHost:" SERVER_NAME
"\r\n\r\n");
} else if (state == AsyncFw::AbstractSocket::State::Unconnected) {
if (socket->
errorString().empty()) logInfo() <<
"Unconnected";
else { logError() << socket->errorString(); }
AsyncFw::MainThread::exit(0);
}
});
logDebug() << socket->
header();
logDebug() << socket->
content();
logNotice() << answer.
view(0, 4096);
});
logNotice() << "Start Applicaiton";
int ret = AsyncFw::MainThread::exec();
logNotice() << "End Applicaiton" << ret;
return ret;
}
The AbstractSocket class provides the base functionality for socket.
Definition AbstractSocket.h:20
static AbstractThread * currentThread()
Returns a pointer to the AsyncFw::AbstractThread that manages the currently executing thread.
Definition AbstractThread.cpp:296
void start()
Create a managed thread and run exec().
Definition AbstractThread.cpp:636
The AddressInfo class.
Definition AddressInfo.h:29
FunctionConnectorProtected< AddressInfo >::Connector< int, const std::vector< std::string > & > completed
The AddressInfo::completed connector.
Definition AddressInfo.h:42
The DataArray class.
Definition DataArray.h:20
The HttpSocket class.
Definition HttpSocket.h:18
AsyncFw::Thread thread with sockets.
Definition Thread.h:16
The TlsContext class provides functionality for managing TLS certificates.
Definition TlsContext.h:24