You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zy...@apache.org on 2017/05/14 09:26:29 UTC

[trafficserver] branch master updated: Improve Jtest codes readability

This is an automated email from the ASF dual-hosted git repository.

zym pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  ba1be1d   Improve Jtest codes readability
ba1be1d is described below

commit ba1be1d9bf026dc5d1a6d2a6ad37913dcd65c402
Author: scw00 <61...@qq.com>
AuthorDate: Sat May 13 09:11:44 2017 +0800

    Improve Jtest codes readability
---
 tools/jtest/jtest.cc | 704 ++++++++++++++++++++++++++++-----------------------
 1 file changed, 385 insertions(+), 319 deletions(-)

diff --git a/tools/jtest/jtest.cc b/tools/jtest/jtest.cc
index 693c2be..ba33890 100644
--- a/tools/jtest/jtest.cc
+++ b/tools/jtest/jtest.cc
@@ -101,6 +101,10 @@
 #define MAX_DEFERED_URLS 10000
 #define DEFERED_URLS_BLOCK 2000
 
+#define JTEST_DONE 0
+#define JTEST_CONT 1
+#define JTEST_ERR -1
+
 static AppVersionInfo appVersionInfo;
 
 static const char *hexdigits      = "0123456789ABCDEFabcdef";
@@ -665,81 +669,93 @@ get_path_from_req(char *buf, char **purl_start, char **purl_end)
 }
 
 static int
-send_response(int sock)
+make_response_header(int sock, char *url_start, char *url_end, int *url_len, char *header, int header_limit)
 {
-  int err = 0, towrite;
-
-  if (fd[sock].req_pos >= 0) {
-    char header[1024], *url_end = nullptr, *url_start = nullptr;
-    int url_len = 0;
-    const char *content_type;
-    switch (server_content_type) {
-    case 1:
-      content_type = "text/html";
-      break;
-    case 2:
+  const char *content_type;
+  switch (server_content_type) {
+  case 1:
+    content_type = "text/html";
+    break;
+  case 2:
+    content_type = "image/jpeg";
+    break;
+  default:
+    content_type = ((compd_suite || alternates) ? "image/jpeg" : "text/html");
+    if (only_server && strstr(fd[sock].req_header, "Cookie:")) {
       content_type = "image/jpeg";
-      break;
-    default:
-      content_type = ((compd_suite || alternates) ? "image/jpeg" : "text/html");
-      if (only_server && strstr(fd[sock].req_header, "Cookie:")) {
-        content_type = "image/jpeg";
-      }
     }
-    if (!ftp && embed_url && fd[sock].response_length > 16) {
-      get_path_from_req(fd[sock].req_header, &url_start, &url_end);
-      *url_end = 0;
-      url_len  = url_end - url_start;
-    }
-    int print_len = 0;
-    if (!ftp) {
-      if (fd[sock].range) {
-        char buff[1024];
-        memset(buff, 0, 1024);
-        if (fd[sock].range_end > fd[sock].range_start) {
-          snprintf(buff, 1024, "Content-Range: bytes %lu-%lu/%d", fd[sock].range_start, fd[sock].range_end, fd[sock].total_length);
-        } else {
-          snprintf(buff, 1024, "Content-Range: bytes %lu-%d/%d", fd[sock].range_start, fd[sock].total_length,
-                   fd[sock].total_length);
-        }
-        print_len = sprintf(header, "HTTP/1.1 206 Partial-Content\r\n"
-                                    "Content-Type: %s\r\n"
-                                    "Cache-Control: max-age=630720000\r\n"
-                                    "Last-Modified: Mon, 05 Oct 2010 01:00:00 GMT\r\n"
-                                    "%s"
-                                    "Content-Length: %d\r\n"
-                                    "%s\r\n"
-                                    "%s"
-                                    "\r\n%s",
-                            content_type, fd[sock].keepalive > 0 ? "Connection: Keep-Alive\r\n" : "Connection: close\r\n",
-                            fd[sock].response_length, buff, no_cache ? "Pragma: no-cache\r\nCache-Control: no-cache\r\n" : "",
-                            url_start ? url_start : "");
-      } else if (fd[sock].ims) {
-        print_len = sprintf(header, "HTTP/1.0 304 Not-Modified\r\n"
-                                    "Content-Type: %s\r\n"
-                                    "Last-Modified: Mon, 05 Oct 2010 01:00:00 GMT\r\n"
-                                    "%s"
-                                    "\r\n",
-                            content_type, fd[sock].keepalive > 0 ? "Connection: Keep-Alive\r\n" : "");
-        url_len = 0;
+  }
+  if (!ftp && embed_url && fd[sock].response_length > 16) {
+    get_path_from_req(fd[sock].req_header, &url_start, &url_end);
+    *url_end = 0;
+    *url_len = url_end - url_start;
+  }
+  int print_len = 0;
+  if (!ftp) {
+    if (fd[sock].range) {
+      char buff[1024];
+      memset(buff, 0, 1024);
+      if (fd[sock].range_end > fd[sock].range_start) {
+        snprintf(buff, 1024, "Content-Range: bytes %lu-%lu/%d", fd[sock].range_start, fd[sock].range_end, fd[sock].total_length);
       } else {
-        print_len = sprintf(header, "HTTP/1.0 200 OK\r\n"
-                                    "Content-Type: %s\r\n"
-                                    "Cache-Control: max-age=630720000\r\n"
-                                    "Last-Modified: Mon, 05 Oct 2010 01:00:00 GMT\r\n"
-                                    "%s"
-                                    "Content-Length: %d\r\n"
-                                    "%s"
-                                    "\r\n%s",
-                            content_type, fd[sock].keepalive > 0 ? "Connection: Keep-Alive\r\n" : "", fd[sock].response_length,
-                            no_cache ? "Pragma: no-cache\r\nCache-Control: no-cache\r\n" : "", url_start ? url_start : "");
+        snprintf(buff, 1024, "Content-Range: bytes %lu-%d/%d", fd[sock].range_start, fd[sock].total_length, fd[sock].total_length);
       }
+      print_len = sprintf(header, "HTTP/1.1 206 Partial-Content\r\n"
+                                  "Content-Type: %s\r\n"
+                                  "Cache-Control: max-age=630720000\r\n"
+                                  "Last-Modified: Mon, 05 Oct 2010 01:00:00 GMT\r\n"
+                                  "%s"
+                                  "Content-Length: %d\r\n"
+                                  "%s\r\n"
+                                  "%s"
+                                  "\r\n%s",
+                          content_type, fd[sock].keepalive > 0 ? "Connection: Keep-Alive\r\n" : "Connection: close\r\n",
+                          fd[sock].response_length, buff, no_cache ? "Pragma: no-cache\r\nCache-Control: no-cache\r\n" : "",
+                          url_start ? url_start : "");
+    } else if (fd[sock].ims) {
+      print_len = sprintf(header, "HTTP/1.0 304 Not-Modified\r\n"
+                                  "Content-Type: %s\r\n"
+                                  "Last-Modified: Mon, 05 Oct 2010 01:00:00 GMT\r\n"
+                                  "%s"
+                                  "\r\n",
+                          content_type, fd[sock].keepalive > 0 ? "Connection: Keep-Alive\r\n" : "");
+      *url_len = 0;
     } else {
-      url_len = print_len = sprintf(header, "ftp://%s:%d/%12.10f/%d", local_host, server_port, fd[sock].doc, fd[sock].length);
-    }
-    if (show_headers) {
-      printf("Response to Proxy: {\n%s}\n", header);
+      print_len = sprintf(header, "HTTP/1.0 200 OK\r\n"
+                                  "Content-Type: %s\r\n"
+                                  "Cache-Control: max-age=630720000\r\n"
+                                  "Last-Modified: Mon, 05 Oct 2010 01:00:00 GMT\r\n"
+                                  "%s"
+                                  "Content-Length: %d\r\n"
+                                  "%s"
+                                  "\r\n%s",
+                          content_type, fd[sock].keepalive > 0 ? "Connection: Keep-Alive\r\n" : "", fd[sock].response_length,
+                          no_cache ? "Pragma: no-cache\r\nCache-Control: no-cache\r\n" : "", url_start ? url_start : "");
     }
+  } else {
+    *url_len = print_len = sprintf(header, "ftp://%s:%d/%12.10f/%d", local_host, server_port, fd[sock].doc, fd[sock].length);
+  }
+
+  if (show_headers) {
+    printf("Response to Proxy: {\n%s}\n", header);
+  }
+
+  return print_len;
+}
+
+static int
+send_response(int sock)
+{
+  char *url_start = nullptr;
+  char *url_end   = nullptr;
+  int err         = 0, towrite;
+  int url_len;
+
+  if (fd[sock].req_pos >= 0) {
+    char header[1024];
+
+    int print_len = make_response_header(sock, url_start, url_end, &url_len, header, 1024);
+
     int len = print_len - fd[sock].req_pos;
     ink_assert(len > 0);
     do {
@@ -965,6 +981,138 @@ send_ftp_data(int sock, char *start /*, char * end */)
   return 0;
 }
 
+static void
+process_header(int sock, char *buffer, int offset)
+{
+  char host[80];
+  int port, length;
+  float r;
+  if (sscanf(buffer, "GET http://%[^:]:%d/%f/%d", host, &port, &r, &length) == 4) {
+  } else if (sscanf(buffer, "GET /%f/%d", &r, &length) == 2) {
+  } else {
+    if (verbose) {
+      printf("misscan: %s\n", buffer);
+    }
+    fd[sock].close();
+    return;
+  }
+
+  if (verbose) {
+    printf("read_request %d got request %d\n", sock, length);
+  }
+  char *ims   = strncasestr(buffer, "If-Modified-Since:", offset);
+  char *range = strncasestr(buffer, "Range:", offset);
+  // coverity[dont_call]
+  if (drand48() > ims_rate) {
+    ims = nullptr;
+  }
+  if (range) {
+    fd[sock].range = 1;
+    if (sscanf(range, "Range: bytes=%lu-%lu", &fd[sock].range_start, &fd[sock].range_end) == 2) {
+      fd[sock].range_bytes = fd[sock].range_end - fd[sock].range_start + 1;
+    } else if (sscanf(range, "Range: bytes=%lu-", &fd[sock].range_start) == 1) {
+      fd[sock].range_bytes = length - fd[sock].range_start + 1;
+    } else {
+      if (verbose)
+        printf("unvalid 206");
+    }
+    ims = nullptr;
+    if (verbose) {
+      printf("sending Range: 206 Partial %lu-%lu\n", fd[sock].range_start, fd[sock].range_end);
+    }
+  }
+
+  fd[sock].ims = ims ? 1 : 0;
+  if (!ims) {
+    if (range) {
+      fd[sock].total_length    = length;
+      fd[sock].response_length = fd[sock].length = fd[sock].range_bytes;
+    } else {
+      fd[sock].response_length = fd[sock].length = length;
+    }
+    fd[sock].nalternate = check_alt(fd[sock].req_header, strlen(fd[sock].req_header));
+    fd[sock].response   = response_buffer + length % 256 + fd[sock].nalternate;
+  } else {
+    fd[sock].nalternate = 0;
+    if (verbose) {
+      printf("sending IMS 304: Not-Modified\n");
+    }
+    fd[sock].response        = nullptr;
+    fd[sock].response_length = fd[sock].length = 0;
+  }
+}
+
+static int
+parse_header(int sock, int err)
+{
+  int i;
+
+  if (verbose) {
+    printf("read %d got %d\n", sock, err);
+  }
+  total_proxy_request_bytes += err;
+  new_tbytes += err;
+  fd[sock].req_pos += err;
+  fd[sock].req_header[fd[sock].req_pos] = 0;
+  char *buffer                          = fd[sock].req_header;
+  for (i = fd[sock].req_pos - err; i < fd[sock].req_pos; i++) {
+    switch (fd[sock].state) {
+    case 0:
+      if (buffer[i] == '\r') {
+        fd[sock].state = 1;
+      } else if (buffer[i] == '\n') {
+        fd[sock].state = 2;
+      }
+      break;
+    case 1:
+      if (buffer[i] == '\n') {
+        fd[sock].state = 2;
+      } else {
+        fd[sock].state = 0;
+      }
+      break;
+    case 2:
+      if (buffer[i] == '\r') {
+        fd[sock].state = 3;
+      } else if (buffer[i] == '\n') {
+        fd[sock].state = 3;
+        goto L3;
+      } else {
+        fd[sock].state = 0;
+      }
+      break;
+    L3:
+    case 3:
+      if (buffer[i] == '\n') {
+        if (show_headers) {
+          printf("Request from Proxy: {\n%s}\n", buffer);
+        }
+
+        process_header(sock, buffer, i);
+
+        fd[sock].req_pos = 0;
+        if (!check_keepalive(fd[sock].req_header, strlen(fd[sock].req_header))) {
+          fd[sock].keepalive = 0;
+        } else {
+          fd[sock].keepalive--;
+        }
+        // coverity[dont_call]
+        if (fd[sock].length && drand48() < server_abort_rate) {
+          // coverity[dont_call]
+          fd[sock].length    = (int)(drand48() * (fd[sock].length - 1));
+          fd[sock].keepalive = 0;
+        }
+        poll_set(sock, nullptr, send_response);
+        return JTEST_DONE;
+      } else {
+        fd[sock].state = 0;
+      }
+      break;
+    }
+  }
+  return JTEST_CONT;
+}
+
 static int
 read_request(int sock)
 {
@@ -972,7 +1120,6 @@ read_request(int sock)
     printf("read_request %d\n", sock);
   }
   int err = 0;
-  int i;
 
   int maxleft = HEADER_SIZE - fd[sock].req_pos - 1;
 
@@ -997,118 +1144,8 @@ read_request(int sock)
     if (verbose) {
       printf("read %d got %d\n", sock, err);
     }
-    total_proxy_request_bytes += err;
-    new_tbytes += err;
-    fd[sock].req_pos += err;
-    fd[sock].req_header[fd[sock].req_pos] = 0;
-    char *buffer                          = fd[sock].req_header;
-    for (i = fd[sock].req_pos - err; i < fd[sock].req_pos; i++) {
-      switch (fd[sock].state) {
-      case 0:
-        if (buffer[i] == '\r') {
-          fd[sock].state = 1;
-        } else if (buffer[i] == '\n') {
-          fd[sock].state = 2;
-        }
-        break;
-      case 1:
-        if (buffer[i] == '\n') {
-          fd[sock].state = 2;
-        } else {
-          fd[sock].state = 0;
-        }
-        break;
-      case 2:
-        if (buffer[i] == '\r') {
-          fd[sock].state = 3;
-        } else if (buffer[i] == '\n') {
-          fd[sock].state = 3;
-          goto L3;
-        } else {
-          fd[sock].state = 0;
-        }
-        break;
-      L3:
-      case 3:
-        if (buffer[i] == '\n') {
-          if (show_headers) {
-            printf("Request from Proxy: {\n%s}\n", buffer);
-          }
-          char host[80];
-          int port, length;
-          float r;
-          if (sscanf(buffer, "GET http://%[^:]:%d/%f/%d", host, &port, &r, &length) == 4) {
-          } else if (sscanf(buffer, "GET /%f/%d", &r, &length) == 2) {
-          } else {
-            if (verbose) {
-              printf("misscan: %s\n", buffer);
-            }
-            fd[sock].close();
-            return 0;
-          }
-          if (verbose) {
-            printf("read_request %d got request %d\n", sock, length);
-          }
-          char *ims   = strncasestr(buffer, "If-Modified-Since:", i);
-          char *range = strncasestr(buffer, "Range:", i);
-          // coverity[dont_call]
-          if (drand48() > ims_rate) {
-            ims = nullptr;
-          }
-          if (range) {
-            fd[sock].range = 1;
-            if (sscanf(range, "Range: bytes=%lu-%lu", &fd[sock].range_start, &fd[sock].range_end) == 2) {
-              fd[sock].range_bytes = fd[sock].range_end - fd[sock].range_start + 1;
-            } else if (sscanf(range, "Range: bytes=%lu-", &fd[sock].range_start) == 1) {
-              fd[sock].range_bytes = length - fd[sock].range_start + 1;
-            } else {
-              if (verbose)
-                printf("unvalid 206");
-            }
-            ims = nullptr;
-            if (verbose) {
-              printf("sending Range: 206 Partial %lu-%lu\n", fd[sock].range_start, fd[sock].range_end);
-            }
-          }
 
-          fd[sock].ims = ims ? 1 : 0;
-          if (!ims) {
-            if (range) {
-              fd[sock].total_length    = length;
-              fd[sock].response_length = fd[sock].length = fd[sock].range_bytes;
-            } else {
-              fd[sock].response_length = fd[sock].length = length;
-            }
-            fd[sock].nalternate = check_alt(fd[sock].req_header, strlen(fd[sock].req_header));
-            fd[sock].response   = response_buffer + length % 256 + fd[sock].nalternate;
-          } else {
-            fd[sock].nalternate = 0;
-            if (verbose) {
-              printf("sending IMS 304: Not-Modified\n");
-            }
-            fd[sock].response        = nullptr;
-            fd[sock].response_length = fd[sock].length = 0;
-          }
-          fd[sock].req_pos = 0;
-          if (!check_keepalive(fd[sock].req_header, strlen(fd[sock].req_header))) {
-            fd[sock].keepalive = 0;
-          } else {
-            fd[sock].keepalive--;
-          }
-          // coverity[dont_call]
-          if (fd[sock].length && drand48() < server_abort_rate) {
-            // coverity[dont_call]
-            fd[sock].length    = (int)(drand48() * (fd[sock].length - 1));
-            fd[sock].keepalive = 0;
-          }
-          poll_set(sock, nullptr, send_response);
-          return 0;
-        } else {
-          fd[sock].state = 0;
-        }
-        break;
-      }
-    }
+    parse_header(sock, err);
   }
   return 0;
 }
@@ -2049,7 +2086,7 @@ compose_all_urls(const char *tag, char *buf, char *start, char *end, int buflen,
   } // while
 }
 //
-// Input is a NULL-terminated string (buf of buflen)
+// Input is a nullptr-terminated string (buf of buflen)
 //       also, a read-write base_url
 //
 static void
@@ -2714,106 +2751,148 @@ make_client(unsigned int addr, int port)
 }
 
 static void
-make_bfc_client(unsigned int addr, int port)
+make_range_header(int sock, double dr, char *rbuf, int size_limit)
 {
-  int sock = -1;
-  char rbuf[1024];
-  memset(rbuf, 0, 1024);
+  int tmp[3];
 
-  if (bandwidth_test && bandwidth_test_to_go-- <= 0) {
+  if (!rbuf || !size_limit)
     return;
-  }
-  if (keepalive) {
-    sock = get_ka(addr);
-  }
-  if (sock < 0) {
-    sock               = make_client(addr, port);
-    fd[sock].keepalive = keepalive;
+
+  tmp[0] = gen_bfc_dist(dr - 1.0);
+  tmp[1] = ((int)(drand48() * 1000000)) % (tmp[0] - 1 - 0 + 1);
+  tmp[2] = ((int)(drand48() * 1000000)) % (tmp[0] - 1 - 0 + 1) + tmp[1] + 100;
+
+  if (tmp[0] > 100) {
+    if (tmp[0] <= tmp[2]) {
+      tmp[2] = tmp[0] - 1;
+    }
+
+    if (tmp[2] - tmp[1] < 100) {
+      tmp[1] = tmp[2] - 100;
+    }
   } else {
-    init_client(sock);
-    current_clients++;
-    fd[sock].keepalive--;
-  }
-  if (sock < 0) {
-    panic("unable to open client connection\n");
+    tmp[1] = 0;
+    tmp[2] = 99;
   }
-  // coverity[dont_call]
-  double h = drand48();
-  // coverity[dont_call]
-  double dr = drand48();
-  if (zipf == 0.0) {
-    if (h < hitrate) {
-      if (!range_mode) {
-        dr                       = 1.0 + (floor(dr * hotset) / hotset);
-        fd[sock].response_length = gen_bfc_dist(dr - 1.0);
-      } else {
-        int tmp[3];
-        dr     = 1.0 + (floor(dr * hotset) / hotset);
-        tmp[0] = gen_bfc_dist(dr - 1.0);
-        tmp[1] = ((int)(drand48() * 1000000)) % (tmp[0] - 1 - 0 + 1);
-        tmp[2] = ((int)(drand48() * 1000000)) % (tmp[0] - 1 - 0 + 1) + tmp[1] + 100;
-        if (tmp[0] > 100) {
-          if (tmp[0] <= tmp[2]) {
-            tmp[2] = tmp[0] - 1;
-          }
 
-          if (tmp[2] - tmp[1] < 100) {
-            tmp[1] = tmp[2] - 100;
-          }
-        } else {
-          tmp[1] = 0;
-          tmp[2] = 99;
-        }
+  fd[sock].response_length = tmp[0];
+  fd[sock].range_start     = tmp[1] > tmp[2] ? tmp[2] : tmp[1];
+  fd[sock].range_end       = tmp[1] < tmp[2] ? tmp[2] : tmp[1];
 
-        fd[sock].response_length = tmp[0];
-        fd[sock].range_start     = tmp[1] > tmp[2] ? tmp[2] : tmp[1];
-        fd[sock].range_end       = tmp[1] < tmp[2] ? tmp[2] : tmp[1];
-        ink_assert((int)(fd[sock].range_end - fd[sock].range_start + 1) >= 100);
-        snprintf(rbuf, 1024, "Range: bytes=%lu-%lu\r\n", fd[sock].range_start, fd[sock].range_end);
-      }
-    } else {
-      if (!range_mode) {
-        fd[sock].response_length = gen_bfc_dist(dr);
-      } else {
-        int tmp[3];
-        tmp[0] = gen_bfc_dist(dr);
-        tmp[1] = ((int)(drand48() * 1000000)) % (tmp[0] - 1 - 0 + 1);
-        tmp[2] = ((int)(drand48() * 1000000)) % (tmp[0] - 1 - 0 + 1) + tmp[1] + 100;
-
-        if (tmp[0] > 100) {
-          if (tmp[0] <= tmp[2]) {
-            tmp[2] = tmp[0] - 1;
-          }
+  ink_assert((int)(fd[sock].range_end - fd[sock].range_start + 1) >= 100);
+  snprintf(rbuf, size_limit, "Range: bytes=%lu-%lu\r\n", fd[sock].range_start, fd[sock].range_end);
+}
 
-          if (tmp[2] - tmp[1] < 100) {
-            tmp[1] = tmp[2] - 100;
-          }
-        } else {
-          tmp[1] = 0;
-          tmp[2] = 99;
-        }
+static void
+make_random_url(int sock, double *dr, double *h)
+{
+  *dr = drand48();
+  *h  = drand48();
 
-        fd[sock].response_length = tmp[0];
-        fd[sock].range_start     = tmp[1] > tmp[2] ? tmp[2] : tmp[1];
-        fd[sock].range_end       = tmp[1] < tmp[2] ? tmp[2] : tmp[1];
-        ink_assert((int)(fd[sock].range_end - fd[sock].range_start + 1) >= 100);
-        snprintf(rbuf, 1024, "Range: bytes=%lu-%lu\r\n", fd[sock].range_start, fd[sock].range_end);
-      }
-    }
+  if (zipf == 0.0) {
+    if (*h < hitrate) {
+      *dr                      = 1.0 + (floor(*dr * hotset) / hotset);
+      fd[sock].response_length = gen_bfc_dist(*dr - 1.0);
+    } else
+      fd[sock].response_length = gen_bfc_dist(*dr);
   } else {
-    unsigned long long int doc = get_zipf(dr);
+    unsigned long long int doc = get_zipf(*dr);
     // Some large randomish number.
     unsigned long long int doc_len_int = doc * 0x14A4D0FB0E93E3A7LL;
     unsigned long int x                = doc_len_int;
     double y                           = (double)x;
     y /= 0x100000000LL; // deterministic random number between 0 and 1.0
     fd[sock].response_length = gen_bfc_dist(y);
-    dr                       = doc;
+    *dr                      = doc;
     range_mode               = 0;
   }
+}
+
+static void
+make_nohost_request(int sock, double dr, const char *evo_str, const char *extension, const char *eheaders, const char *rbuf,
+                    const char *cookie)
+{
+  if (range_mode) {
+    sprintf(fd[sock].req_header, "GET http://%s:%d/%12.10f/%d%s%s HTTP/1.1\r\n"
+                                 "%s"
+                                 "%s"
+                                 "%s"
+                                 "%s"
+                                 "%s"
+                                 "%s"
+                                 "\r\n",
+            local_host, server_port, dr, fd[sock].response_length, evo_str, extension,
+            fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "Connection: close\r\n",
+            // coverity[dont_call]
+            reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, "Host: localhost\r\n", rbuf, cookie);
+  } else {
+    sprintf(fd[sock].req_header,
+            ftp ? "GET ftp://%s:%d/%12.10f/%d%s%s HTTP/1.0\r\n"
+                  "%s"
+                  "%s"
+                  "%s"
+                  "%s"
+                  "\r\n" :
+                  "GET http://%s:%d/%12.10f/%d%s%s HTTP/1.0\r\n"
+                  "%s"
+                  "%s"
+                  "%s"
+                  "%s"
+                  "\r\n",
+            local_host, server_port, dr, fd[sock].response_length, evo_str, extension,
+            fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "",
+            // coverity[dont_call]
+            reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
+  }
+}
+
+static void
+make_host1_request(int sock, double dr, const char *evo_str, const char *extension, const char *eheaders, const char *cookie)
+{
+  sprintf(fd[sock].req_header, "GET /%12.10f/%d%s%s HTTP/1.0\r\n"
+                               "Host: %s:%d\r\n"
+                               "%s"
+                               "%s"
+                               "%s"
+                               "%s"
+                               "\r\n",
+          dr, fd[sock].response_length, evo_str, extension, local_host, server_port,
+          fd[sock].keepalive ? "Connection: Keep-Alive\r\n" : "",
+          // coverity[dont_call]
+          reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
+}
+
+static void
+make_host2_request(int sock, double dr, const char *evo_str, const char *extension, const char *eheaders, const char *cookie)
+{
+  /* Send a non-proxy client request i.e. for Transparency testing */
+  sprintf(fd[sock].req_header, "GET /%12.10f/%d%s%s HTTP/1.0\r\n"
+                               "%s"
+                               "%s"
+                               "%s"
+                               "%s"
+                               "\r\n",
+          dr, fd[sock].response_length, evo_str, extension, fd[sock].keepalive ? "Connection: Keep-Alive\r\n" : "",
+          // coverity[dont_call]
+          reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
+}
+
+static void
+build_request(int sock)
+{
+  double dr, h;
+  char rbuf[1024];
+
+  make_random_url(sock, &dr, &h);
+
   if (verbose) {
     printf("gen_bfc_dist %d\n", fd[sock].response_length);
   }
+
+  if (range_mode) {
+    make_range_header(sock, dr, rbuf, 1024);
+  }
+
   char eheaders[16384];
   *eheaders    = 0;
   int nheaders = extra_headers;
@@ -2855,74 +2934,61 @@ make_bfc_client(unsigned int addr, int port)
   default:
     extension = (compd_suite ? ".jpeg" : "");
   }
+
   char evo_str[20];
   evo_str[0] = '\0';
   if (evo_rate != 0.0) {
     double evo_index = dr + (((double)now) / HRTIME_HOUR) * evo_rate;
     sprintf(evo_str, ".%u", ((unsigned int)evo_index));
   }
-  if (0 == hostrequest) {
-    if (range_mode) {
-      sprintf(fd[sock].req_header, "GET http://%s:%d/%12.10f/%d%s%s HTTP/1.1\r\n"
-                                   "%s"
-                                   "%s"
-                                   "%s"
-                                   "%s"
-                                   "%s"
-                                   "%s"
-                                   "\r\n",
-              local_host, server_port, dr, fd[sock].response_length, evo_str, extension,
-              fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "Connection: close\r\n",
-              // coverity[dont_call]
-              reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, "Host: localhost\r\n", rbuf, cookie);
-    } else {
-      sprintf(fd[sock].req_header,
-              ftp ? "GET ftp://%s:%d/%12.10f/%d%s%s HTTP/1.0\r\n"
-                    "%s"
-                    "%s"
-                    "%s"
-                    "%s"
-                    "\r\n" :
-                    "GET http://%s:%d/%12.10f/%d%s%s HTTP/1.0\r\n"
-                    "%s"
-                    "%s"
-                    "%s"
-                    "%s"
-                    "\r\n",
-              local_host, server_port, dr, fd[sock].response_length, evo_str, extension,
-              fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "",
-              // coverity[dont_call]
-              reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
-    }
-  } else if (1 == hostrequest) {
-    sprintf(fd[sock].req_header, "GET /%12.10f/%d%s%s HTTP/1.0\r\n"
-                                 "Host: %s:%d\r\n"
-                                 "%s"
-                                 "%s"
-                                 "%s"
-                                 "%s"
-                                 "\r\n",
-            dr, fd[sock].response_length, evo_str, extension, local_host, server_port,
-            fd[sock].keepalive ? "Connection: Keep-Alive\r\n" : "",
-            // coverity[dont_call]
-            reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
-  } else if (2 == hostrequest) {
-    /* Send a non-proxy client request i.e. for Transparency testing */
-    sprintf(fd[sock].req_header, "GET /%12.10f/%d%s%s HTTP/1.0\r\n"
-                                 "%s"
-                                 "%s"
-                                 "%s"
-                                 "%s"
-                                 "\r\n",
-            dr, fd[sock].response_length, evo_str, extension, fd[sock].keepalive ? "Connection: Keep-Alive\r\n" : "",
-            // coverity[dont_call]
-            reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
+
+  switch (hostrequest) {
+  case 0:
+    make_nohost_request(sock, dr, evo_str, extension, eheaders, rbuf, cookie);
+    break;
+  case 1:
+    make_host1_request(sock, dr, evo_str, extension, eheaders, cookie);
+    break;
+  case 2:
+    make_host2_request(sock, dr, evo_str, extension, eheaders, cookie);
+    break;
+  default:
+    ink_release_assert(!"Unexpected hostrequest! Abort.");
+    return;
   }
 
   if (range_mode) {
     fd[sock].response_length = fd[sock].range_end - fd[sock].range_start + 1;
     ink_assert(fd[sock].response_length > 0);
   }
+}
+
+static void
+make_bfc_client(unsigned int addr, int port)
+{
+  int sock = -1;
+  char rbuf[1024];
+  memset(rbuf, 0, 1024);
+
+  if (bandwidth_test && bandwidth_test_to_go-- <= 0) {
+    return;
+  }
+  if (keepalive) {
+    sock = get_ka(addr);
+  }
+  if (sock < 0) {
+    sock               = make_client(addr, port);
+    fd[sock].keepalive = keepalive;
+  } else {
+    init_client(sock);
+    current_clients++;
+    fd[sock].keepalive--;
+  }
+  if (sock < 0) {
+    panic("unable to open client connection\n");
+  }
+
+  build_request(sock);
 
   if (verbose) {
     printf("request %d [%s]\n", sock, fd[sock].req_header);
@@ -3538,11 +3604,11 @@ main(int argc __attribute__((unused)), const char *argv[])
   This function takes an input URL in src_url and splits it into its
   component parts, including a scheme, host, port, path, fragment,
   query, and parameters. you must pass in buffers for each of these.
-  If you pass in a NULL pointer for any of these, it will not be
+  If you pass in a nullptr pointer for any of these, it will not be
   returned.
 
   The flags "sche_exists", etc. tell you if that part of the URL was
-  found. Each unfound part (with a non-NULL buffer) will also contain
+  found. Each unfound part (with a non-nullptr buffer) will also contain
   the empty string '\0'.
 
   The flag "relative_url" indicates that the src_url did not start
@@ -3565,7 +3631,7 @@ ink_web_decompose_url(const char *src_url, char *sche, char *host, char *port, c
     * Input: src_url
     * Outputs: every other argument
     *
-    * You may pass in NULL pointers for any of: sche, host, port, path,
+    * You may pass in nullptr pointers for any of: sche, host, port, path,
     * frag, quer, or para, and they will not be returned.
     *
     *

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].