try any version on the server side
[ghsmtp.git] / SockBuffer-test.cpp
blobd9c2e18b8680508bdacf55243f8b1606dbda5f65
1 #include "SockBuffer.hpp"
3 #include <fcntl.h>
5 #include <fstream>
6 #include <iostream>
8 #include <fmt/format.h>
10 #include <glog/logging.h>
12 int main(int argc, char* argv[])
14 constexpr auto infile = "body.txt";
16 int fd_in = open(infile, O_RDONLY);
17 PCHECK(fd_in != -1) << "Can't open file " << infile;
19 char outfile[] = "/tmp/SockBuffer-test-XXXXXX";
21 int fd_out = mkstemp(outfile);
22 PCHECK(fd_out != -1);
24 auto read_hook = []() { std::cout << "read_hook\n"; };
26 boost::iostreams::stream<SockBuffer> iostream{fd_in,
27 fd_out,
28 read_hook,
29 std::chrono::seconds(10),
30 std::chrono::seconds(10),
31 std::chrono::seconds(1)};
33 std::string line;
34 while (std::getline(iostream, line)) {
35 iostream << line << '\n';
37 iostream << std::flush;
39 auto const diff_cmd{fmt::format("diff {} {}", infile, outfile)};
40 CHECK_EQ(system(diff_cmd.c_str()), 0);
42 PCHECK(!unlink(outfile)) << "unlink failed for " << outfile;
44 std::cout << "sizeof(SockBuffer) == " << sizeof(SockBuffer) << '\n';