server.cc revision 02cc483d
102cc483dSShuo Chen#include "timer.h"
202cc483dSShuo Chen
37db0aea6SShuo Chen#include "InetAddress.h"
47db0aea6SShuo Chen#include "TlsAcceptor.h"
57db0aea6SShuo Chen#include "TlsConfig.h"
67db0aea6SShuo Chen#include "TlsStream.h"
77db0aea6SShuo Chen
87db0aea6SShuo Chenint main(int argc, char* argv[])
97db0aea6SShuo Chen{
107db0aea6SShuo Chen  TlsConfig config;
117db0aea6SShuo Chen  // config.setCaFile("ca.pem");
127db0aea6SShuo Chen  config.setCertFile("server.pem");
137db0aea6SShuo Chen  config.setKeyFile("server.pem");
147db0aea6SShuo Chen
157db0aea6SShuo Chen  InetAddress listenAddr(4433);
167db0aea6SShuo Chen  TlsAcceptor acceptor(&config, listenAddr);
177db0aea6SShuo Chen
187db0aea6SShuo Chen  TlsStreamPtr stream = acceptor.accept();
197db0aea6SShuo Chen  if (stream)
207db0aea6SShuo Chen  {
217db0aea6SShuo Chen    LOG_INFO << "OK";
2202cc483dSShuo Chen    int64_t total = 0;
2302cc483dSShuo Chen    char buf[20 * 1024];
2402cc483dSShuo Chen    int nr = 0;
2502cc483dSShuo Chen    Timer t;
2602cc483dSShuo Chen    t.start();
2702cc483dSShuo Chen    while ( (nr = stream->receiveSome(buf, sizeof buf)) > 0) {
2802cc483dSShuo Chen      // LOG_INFO << "nr = " << nr;
2902cc483dSShuo Chen      total += nr;
3002cc483dSShuo Chen    }
3102cc483dSShuo Chen    // LOG_INFO << "nr = " << nr;
3202cc483dSShuo Chen    t.stop();
3302cc483dSShuo Chen    LOG_INFO << "DONE " << total
3402cc483dSShuo Chen        << " " << (total / t.seconds() / 1e6) << " MB/s";
357db0aea6SShuo Chen  }
367db0aea6SShuo Chen}
377db0aea6SShuo Chen
38