Process implementation for TLS encrypted traffic.Please note that gnutls has some internal buffering, so please do not do some buffering on your own and also do not rely on flush(). Just write directly to the socket, as in PosixProcess::posixWriteDirect().
#include <fstream>
#include <iostream>
#include <poll.h>
{
int read(
char *buf,
int count)
override {
return posixRead(buf, count); }
void write(
const char *buf,
size_t count)
override {
}
std::vector<PdCom::Variable> vars ,
std::vector<std::string> ) override
{
for (const auto &v : vars)
std::cout << "Found var " << v.getPath() << "\n";
running_ = false;
}
{
std::cout << "Connected!" << std::endl;
}
public:
void waitForSocket()
{
fd_set fds;
FD_ZERO(&fds);
FD_SET(fd_, &fds);
select(fd_ + 1, &fds, NULL, NULL, NULL);
}
MyProcess(const std::string &ca_pem, const char *host = "localhost") :
{
do {
std::cerr << "Handshaking\n";
}
bool running_ = true;
};
int main(int argc, char *argv[])
{
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <hostname> <Path to CA.pem>\n";
return -1;
}
std::ifstream ca_file(argv[2]);
std::string ca;
getline(ca_file, ca, '\0');
MyProcess p(ca, argv[1]);
while (p.running_) {
p.waitForSocket();
p.asyncData();
}
p.bye();
return 0;
}