aboutsummaryrefslogtreecommitdiffstats
path: root/fbench/src/test/httpclient.cpp
blob: 4201da68b97b213393b319a6c7b2e1057d17a313 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <httpclient/httpclient.h>
#include <iostream>
#include <thread>

int
main(int argc, char **argv)
{
  if (argc < 4) {
    printf("usage: httpclient <host> <port> <url> [keep-alive]\n");
    return 1;
  }

  HTTPClient           *client;
  ssize_t               len;

  if(argc == 4) {
    client = new HTTPClient(argv[1], atoi(argv[2]), false, true);
  } else {
    client = new HTTPClient(argv[1], atoi(argv[2]), true, true);
  }

  std::ostream * output = & std::cout;

  if ((len = client->Fetch(argv[3], output).ResultSize()) >= 0) {
    printf("SUCCESS!\n");
    printf("LENGTH: %ld\n", len);
  } else {
      printf("ERROR: could not fetch URL content.\n");
  }
  if ((len = client->Fetch(argv[3], output).ResultSize()) >= 0) {
    printf("SUCCESS!\n");
    printf("LENGTH: %ld\n", len);
  } else {
      printf("ERROR: could not fetch URL content.\n");
  }

  std::this_thread::sleep_for(std::chrono::seconds(20));

  if ((len = client->Fetch(argv[3], output).ResultSize()) >= 0) {
    printf("SUCCESS!\n");
    printf("LENGTH: %ld\n", len);
  } else {
      printf("ERROR: could not fetch URL content.\n");
  }
  if ((len = client->Fetch(argv[3], output).ResultSize()) >= 0) {
    printf("SUCCESS!\n");
    printf("LENGTH: %ld\n", len);
  } else {
      printf("ERROR: could not fetch URL content.\n");
  }
  printf("REUSE COUNT: %zu\n", client->GetReuseCount());
  return 0;
}