[Midnightbsd-cvs] src [11938] trunk/tools/tools/netrate: add receive
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Jul 21 16:01:26 EDT 2018
Revision: 11938
http://svnweb.midnightbsd.org/src/?rev=11938
Author: laffer1
Date: 2018-07-21 16:01:25 -0400 (Sat, 21 Jul 2018)
Log Message:
-----------
add receive
Added Paths:
-----------
trunk/tools/tools/netrate/http/
trunk/tools/tools/netrate/http/Makefile
trunk/tools/tools/netrate/http/http.c
trunk/tools/tools/netrate/httpd/
trunk/tools/tools/netrate/httpd/Makefile
trunk/tools/tools/netrate/httpd/httpd.c
trunk/tools/tools/netrate/tcpreceive/
trunk/tools/tools/netrate/tcpreceive/Makefile
trunk/tools/tools/netrate/tcpreceive/tcpreceive.c
Added: trunk/tools/tools/netrate/http/Makefile
===================================================================
--- trunk/tools/tools/netrate/http/Makefile (rev 0)
+++ trunk/tools/tools/netrate/http/Makefile 2018-07-21 20:01:25 UTC (rev 11938)
@@ -0,0 +1,10 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/tools/tools/netrate/http/Makefile 276486 2014-12-31 23:25:37Z ngie $
+
+PROG= http
+MAN=
+WARNS?= 3
+DPADD= ${LIBPTHREAD}
+LDADD= -lpthread
+
+.include <bsd.prog.mk>
Property changes on: trunk/tools/tools/netrate/http/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/tools/tools/netrate/http/http.c
===================================================================
--- trunk/tools/tools/netrate/http/http.c (rev 0)
+++ trunk/tools/tools/netrate/http/http.c 2018-07-21 20:01:25 UTC (rev 11938)
@@ -0,0 +1,362 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005-2006 Robert N. M. Watson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/tools/tools/netrate/http/http.c 203800 2010-02-12 16:33:03Z ru $
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+
+#include <netinet/in.h>
+
+#include <arpa/inet.h>
+
+#include <err.h>
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+static int threaded; /* 1 for threaded, 0 for forked. */
+static int numthreads; /* Number of threads/procs. */
+static int numseconds; /* Length of test. */
+
+/*
+ * Simple, multi-threaded HTTP benchmark. Fetches a single URL using the
+ * specified parameters, and after a period of execution, reports on how it
+ * worked out.
+ */
+#define MAXTHREADS 128
+#define DEFAULTTHREADS 32
+#define DEFAULTSECONDS 20
+#define BUFFER (48*1024)
+#define QUIET 1
+
+struct http_worker_description {
+ pthread_t hwd_thread;
+ pid_t hwd_pid;
+ uintmax_t hwd_count;
+ uintmax_t hwd_errorcount;
+ int hwd_start_signal_barrier;
+};
+
+static struct state {
+ struct sockaddr_in sin;
+ char *path;
+ struct http_worker_description hwd[MAXTHREADS];
+ int run_done;
+ pthread_barrier_t start_barrier;
+} *statep;
+
+int curthread;
+
+/*
+ * Borrowed from sys/param.h>
+ */
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */
+
+/*
+ * Given a partially processed URL, fetch it from the specified host.
+ */
+static int
+http_fetch(struct sockaddr_in *sin, char *path, int quiet)
+{
+ u_char buffer[BUFFER];
+ ssize_t len;
+ size_t sofar;
+ int sock;
+
+ sock = socket(PF_INET, SOCK_STREAM, 0);
+ if (sock < 0) {
+ if (!quiet)
+ warn("socket(PF_INET, SOCK_STREAM)");
+ return (-1);
+ }
+
+ /* XXX: Mark non-blocking. */
+
+ if (connect(sock, (struct sockaddr *)sin, sizeof(*sin)) < 0) {
+ if (!quiet)
+ warn("connect");
+ close(sock);
+ return (-1);
+ }
+
+ /* XXX: select for connection. */
+
+ /* Send a request. */
+ snprintf(buffer, BUFFER, "GET %s HTTP/1.0\n\n", path);
+ sofar = 0;
+ while (sofar < strlen(buffer)) {
+ len = send(sock, buffer, strlen(buffer), 0);
+ if (len < 0) {
+ if (!quiet)
+ warn("send");
+ close(sock);
+ return (-1);
+ }
+ if (len == 0) {
+ if (!quiet)
+ warnx("send: len == 0");
+ }
+ sofar += len;
+ }
+
+ /* Read until done. Not very smart. */
+ while (1) {
+ len = recv(sock, buffer, BUFFER, 0);
+ if (len < 0) {
+ if (!quiet)
+ warn("recv");
+ close(sock);
+ return (-1);
+ }
+ if (len == 0)
+ break;
+ }
+
+ close(sock);
+ return (0);
+}
+
+static void
+killall(void)
+{
+ int i;
+
+ for (i = 0; i < numthreads; i++) {
+ if (statep->hwd[i].hwd_pid != 0)
+ kill(statep->hwd[i].hwd_pid, SIGTERM);
+ }
+}
+
+static void
+signal_handler(int signum)
+{
+
+ statep->hwd[curthread].hwd_start_signal_barrier = 1;
+}
+
+static void
+signal_barrier_wait(void)
+{
+
+ /* Wait for EINTR. */
+ if (signal(SIGHUP, signal_handler) == SIG_ERR)
+ err(-1, "signal");
+ while (1) {
+ sleep(100);
+ if (statep->hwd[curthread].hwd_start_signal_barrier)
+ break;
+ }
+}
+
+static void
+signal_barrier_wakeup(void)
+{
+ int i;
+
+ for (i = 0; i < numthreads; i++) {
+ if (statep->hwd[i].hwd_pid != 0)
+ kill(statep->hwd[i].hwd_pid, SIGHUP);
+ }
+}
+
+static void *
+http_worker(void *arg)
+{
+ struct http_worker_description *hwdp;
+ int ret;
+
+ if (threaded) {
+ ret = pthread_barrier_wait(&statep->start_barrier);
+ if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)
+ err(-1, "pthread_barrier_wait");
+ } else {
+ signal_barrier_wait();
+ }
+
+ hwdp = arg;
+ while (!statep->run_done) {
+ if (http_fetch(&statep->sin, statep->path, QUIET) < 0) {
+ hwdp->hwd_errorcount++;
+ continue;
+ }
+ /* Don't count transfers that didn't finish in time. */
+ if (!statep->run_done)
+ hwdp->hwd_count++;
+ }
+
+ if (threaded)
+ return (NULL);
+ else
+ exit(0);
+}
+
+static void
+usage(void)
+{
+
+ fprintf(stderr,
+ "http [-n numthreads] [-s seconds] [-t] ip port path\n");
+ exit(EX_USAGE);
+}
+
+static void
+main_sighup(int signum)
+{
+
+ killall();
+}
+
+int
+main(int argc, char *argv[])
+{
+ int ch, error, i;
+ char *pagebuffer;
+ uintmax_t total;
+ size_t len;
+ pid_t pid;
+
+ numthreads = DEFAULTTHREADS;
+ numseconds = DEFAULTSECONDS;
+ while ((ch = getopt(argc, argv, "n:s:t")) != -1) {
+ switch (ch) {
+ case 'n':
+ numthreads = atoi(optarg);
+ break;
+
+ case 's':
+ numseconds = atoi(optarg);
+ break;
+
+ case 't':
+ threaded = 1;
+ break;
+
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 3)
+ usage();
+
+ if (numthreads > MAXTHREADS)
+ errx(-1, "%d exceeds max threads %d", numthreads,
+ MAXTHREADS);
+
+ len = roundup(sizeof(struct state), getpagesize());
+ pagebuffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
+ if (pagebuffer == MAP_FAILED)
+ err(-1, "mmap");
+ if (minherit(pagebuffer, len, INHERIT_SHARE) < 0)
+ err(-1, "minherit");
+ statep = (struct state *)pagebuffer;
+
+ bzero(&statep->sin, sizeof(statep->sin));
+ statep->sin.sin_len = sizeof(statep->sin);
+ statep->sin.sin_family = AF_INET;
+ statep->sin.sin_addr.s_addr = inet_addr(argv[0]);
+ statep->sin.sin_port = htons(atoi(argv[1]));
+ statep->path = argv[2];
+
+ /*
+ * Do one test retrieve so we can report the error from it, if any.
+ */
+ if (http_fetch(&statep->sin, statep->path, 0) < 0)
+ exit(-1);
+
+ if (threaded) {
+ if (pthread_barrier_init(&statep->start_barrier, NULL,
+ numthreads) != 0)
+ err(-1, "pthread_barrier_init");
+ }
+
+ for (i = 0; i < numthreads; i++) {
+ statep->hwd[i].hwd_count = 0;
+ if (threaded) {
+ if (pthread_create(&statep->hwd[i].hwd_thread, NULL,
+ http_worker, &statep->hwd[i]) != 0)
+ err(-1, "pthread_create");
+ } else {
+ curthread = i;
+ pid = fork();
+ if (pid < 0) {
+ error = errno;
+ killall();
+ errno = error;
+ err(-1, "fork");
+ }
+ if (pid == 0) {
+ http_worker(&statep->hwd[i]);
+ printf("Doh\n");
+ exit(0);
+ }
+ statep->hwd[i].hwd_pid = pid;
+ }
+ }
+ if (!threaded) {
+ signal(SIGHUP, main_sighup);
+ sleep(2);
+ signal_barrier_wakeup();
+ }
+ sleep(numseconds);
+ statep->run_done = 1;
+ if (!threaded)
+ sleep(2);
+ for (i = 0; i < numthreads; i++) {
+ if (threaded) {
+ if (pthread_join(statep->hwd[i].hwd_thread, NULL)
+ != 0)
+ err(-1, "pthread_join");
+ } else {
+ pid = waitpid(statep->hwd[i].hwd_pid, NULL, 0);
+ if (pid == statep->hwd[i].hwd_pid)
+ statep->hwd[i].hwd_pid = 0;
+ }
+ }
+ if (!threaded)
+ killall();
+ total = 0;
+ for (i = 0; i < numthreads; i++)
+ total += statep->hwd[i].hwd_count;
+ printf("%ju transfers/second\n", total / numseconds);
+ total = 0;
+ for (i = 0; i < numthreads; i++)
+ total += statep->hwd[i].hwd_errorcount;
+ printf("%ju errors/second\n", total / numseconds);
+ return (0);
+}
Property changes on: trunk/tools/tools/netrate/http/http.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/tools/tools/netrate/httpd/Makefile
===================================================================
--- trunk/tools/tools/netrate/httpd/Makefile (rev 0)
+++ trunk/tools/tools/netrate/httpd/Makefile 2018-07-21 20:01:25 UTC (rev 11938)
@@ -0,0 +1,10 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/tools/tools/netrate/httpd/Makefile 276486 2014-12-31 23:25:37Z ngie $
+
+PROG= httpd
+MAN=
+WARNS?= 3
+DPADD= ${LIBPTHREAD}
+LDADD= -lpthread
+
+.include <bsd.prog.mk>
Property changes on: trunk/tools/tools/netrate/httpd/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/tools/tools/netrate/httpd/httpd.c
===================================================================
--- trunk/tools/tools/netrate/httpd/httpd.c (rev 0)
+++ trunk/tools/tools/netrate/httpd/httpd.c 2018-07-21 20:01:25 UTC (rev 11938)
@@ -0,0 +1,314 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005-2006 Robert N. M. Watson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/tools/tools/netrate/httpd/httpd.c 203800 2010-02-12 16:33:03Z ru $
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <sys/utsname.h>
+#include <sys/wait.h>
+
+#include <netinet/in.h>
+
+#include <arpa/inet.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+static int threaded; /* 1 for threaded, 0 for forked. */
+
+/*
+ * Simple, multi-threaded/multi-process HTTP server. Very dumb.
+ *
+ * If a path is specified as an argument, only that file is served. If no
+ * path is specified, httpd will create one file to send per server thread.
+ */
+#define THREADS 128
+#define BUFFER 1024
+#define FILESIZE 1024
+
+#define HTTP_OK "HTTP/1.1 200 OK\n"
+#define HTTP_SERVER1 "Server rwatson_httpd/1.0 ("
+#define HTTP_SERVER2 ")\n"
+#define HTTP_CONNECTION "Connection: close\n"
+#define HTTP_CONTENT "Content-Type: text/html\n\n"
+
+/*
+ * In order to support both multi-threaded and multi-process operation but
+ * use a single shared memory statistics model, we create a page-aligned
+ * statistics buffer. For threaded operation, it's just shared memory due to
+ * threading; for multi-process operation, we mark it as INHERIT_SHARE, so we
+ * must put it in page-aligned memory that isn't shared with other memory, or
+ * risk accidental sharing of other statep.
+ */
+static struct state {
+ struct httpd_thread_statep {
+ pthread_t hts_thread; /* Multi-thread. */
+ pid_t hts_pid; /* Multi-process. */
+ int hts_fd;
+ } hts[THREADS];
+
+ const char *path;
+ int data_file;
+ int listen_sock;
+ struct utsname utsname;
+} *statep;
+
+/*
+ * Borrowed from sys/param.h.
+ */
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */
+
+/*
+ * Given an open client socket, process its request. No notion of timeout.
+ */
+static int
+http_serve(int sock, int fd)
+{
+ struct iovec header_iovec[6];
+ struct sf_hdtr sf_hdtr;
+ char buffer[BUFFER];
+ ssize_t len;
+ int i, ncount;
+
+ /* Read until \n\n. Not very smart. */
+ ncount = 0;
+ while (1) {
+ len = recv(sock, buffer, BUFFER, 0);
+ if (len < 0) {
+ warn("recv");
+ return (-1);
+ }
+ if (len == 0)
+ return (-1);
+ for (i = 0; i < len; i++) {
+ switch (buffer[i]) {
+ case '\n':
+ ncount++;
+ break;
+
+ case '\r':
+ break;
+
+ default:
+ ncount = 0;
+ }
+ }
+ if (ncount == 2)
+ break;
+ }
+
+ bzero(&sf_hdtr, sizeof(sf_hdtr));
+ bzero(&header_iovec, sizeof(header_iovec));
+ header_iovec[0].iov_base = HTTP_OK;
+ header_iovec[0].iov_len = strlen(HTTP_OK);
+ header_iovec[1].iov_base = HTTP_SERVER1;
+ header_iovec[1].iov_len = strlen(HTTP_SERVER1);
+ header_iovec[2].iov_base = statep->utsname.sysname;
+ header_iovec[2].iov_len = strlen(statep->utsname.sysname);
+ header_iovec[3].iov_base = HTTP_SERVER2;
+ header_iovec[3].iov_len = strlen(HTTP_SERVER2);
+ header_iovec[4].iov_base = HTTP_CONNECTION;
+ header_iovec[4].iov_len = strlen(HTTP_CONNECTION);
+ header_iovec[5].iov_base = HTTP_CONTENT;
+ header_iovec[5].iov_len = strlen(HTTP_CONTENT);
+ sf_hdtr.headers = header_iovec;
+ sf_hdtr.hdr_cnt = 6;
+ sf_hdtr.trailers = NULL;
+ sf_hdtr.trl_cnt = 0;
+
+ if (sendfile(fd, sock, 0, 0, &sf_hdtr, NULL, 0) < 0)
+ warn("sendfile");
+
+ return (0);
+}
+
+static void *
+httpd_worker(void *arg)
+{
+ struct httpd_thread_statep *htsp;
+ int sock;
+
+ htsp = arg;
+
+ while (1) {
+ sock = accept(statep->listen_sock, NULL, NULL);
+ if (sock < 0)
+ continue;
+ (void)http_serve(sock, htsp->hts_fd);
+ close(sock);
+ }
+}
+
+static void
+killall(void)
+{
+ int i;
+
+ for (i = 0; i < THREADS; i++) {
+ if (statep->hts[i].hts_pid != 0)
+ (void)kill(statep->hts[i].hts_pid, SIGTERM);
+ }
+}
+
+static void
+usage(void)
+{
+
+ fprintf(stderr, "httpd [-t] port [path]\n");
+ exit(EX_USAGE);
+}
+
+int
+main(int argc, char *argv[])
+{
+ u_char filebuffer[FILESIZE];
+ char temppath[PATH_MAX];
+ struct sockaddr_in sin;
+ int ch, error, i;
+ char *pagebuffer;
+ ssize_t len;
+ pid_t pid;
+
+
+ while ((ch = getopt(argc, argv, "t")) != -1) {
+ switch (ch) {
+ case 't':
+ threaded = 1;
+ break;
+
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 1 && argc != 2)
+ usage();
+
+ len = roundup(sizeof(struct state), getpagesize());
+ pagebuffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
+ if (pagebuffer == MAP_FAILED)
+ err(-1, "mmap");
+ if (minherit(pagebuffer, len, INHERIT_SHARE) < 0)
+ err(-1, "minherit");
+ statep = (struct state *)pagebuffer;
+
+ if (uname(&statep->utsname) < 0)
+ err(-1, "utsname");
+
+ statep->listen_sock = socket(PF_INET, SOCK_STREAM, 0);
+ if (statep->listen_sock < 0)
+ err(-1, "socket(PF_INET, SOCK_STREAM)");
+
+ bzero(&sin, sizeof(sin));
+ sin.sin_len = sizeof(sin);
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(atoi(argv[0]));
+
+ /*
+ * If a path is specified, use it. Otherwise, create temporary files
+ * with some data for each thread.
+ */
+ statep->path = argv[1];
+ if (statep->path != NULL) {
+ statep->data_file = open(statep->path, O_RDONLY);
+ if (statep->data_file < 0)
+ err(-1, "open: %s", statep->path);
+ for (i = 0; i < THREADS; i++)
+ statep->hts[i].hts_fd = statep->data_file;
+ } else {
+ memset(filebuffer, 'A', FILESIZE - 1);
+ filebuffer[FILESIZE - 1] = '\n';
+ for (i = 0; i < THREADS; i++) {
+ snprintf(temppath, PATH_MAX, "/tmp/httpd.XXXXXXXXXXX");
+ statep->hts[i].hts_fd = mkstemp(temppath);
+ if (statep->hts[i].hts_fd < 0)
+ err(-1, "mkstemp");
+ (void)unlink(temppath);
+ len = write(statep->hts[i].hts_fd, filebuffer,
+ FILESIZE);
+ if (len < 0)
+ err(-1, "write");
+ if (len < FILESIZE)
+ errx(-1, "write: short");
+ }
+ }
+
+ if (bind(statep->listen_sock, (struct sockaddr *)&sin,
+ sizeof(sin)) < 0)
+ err(-1, "bind");
+
+ if (listen(statep->listen_sock, -1) < 0)
+ err(-1, "listen");
+
+ for (i = 0; i < THREADS; i++) {
+ if (threaded) {
+ if (pthread_create(&statep->hts[i].hts_thread, NULL,
+ httpd_worker, &statep->hts[i]) != 0)
+ err(-1, "pthread_create");
+ } else {
+ pid = fork();
+ if (pid < 0) {
+ error = errno;
+ killall();
+ errno = error;
+ err(-1, "fork");
+ }
+ if (pid == 0)
+ httpd_worker(&statep->hts[i]);
+ statep->hts[i].hts_pid = pid;
+ }
+ }
+
+ for (i = 0; i < THREADS; i++) {
+ if (threaded) {
+ if (pthread_join(statep->hts[i].hts_thread, NULL)
+ != 0)
+ err(-1, "pthread_join");
+ } else {
+ pid = waitpid(statep->hts[i].hts_pid, NULL, 0);
+ if (pid == statep->hts[i].hts_pid)
+ statep->hts[i].hts_pid = 0;
+ }
+ }
+ if (!threaded)
+ killall();
+ return (0);
+}
Property changes on: trunk/tools/tools/netrate/httpd/httpd.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/tools/tools/netrate/tcpreceive/Makefile
===================================================================
--- trunk/tools/tools/netrate/tcpreceive/Makefile (rev 0)
+++ trunk/tools/tools/netrate/tcpreceive/Makefile 2018-07-21 20:01:25 UTC (rev 11938)
@@ -0,0 +1,8 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/tools/tools/netrate/tcpreceive/Makefile 276486 2014-12-31 23:25:37Z ngie $
+
+PROG= tcpreceive
+MAN=
+WARNS?= 3
+
+.include <bsd.prog.mk>
Property changes on: trunk/tools/tools/netrate/tcpreceive/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/tools/tools/netrate/tcpreceive/tcpreceive.c
===================================================================
--- trunk/tools/tools/netrate/tcpreceive/tcpreceive.c (rev 0)
+++ trunk/tools/tools/netrate/tcpreceive/tcpreceive.c 2018-07-21 20:01:25 UTC (rev 11938)
@@ -0,0 +1,114 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005 Robert N. M. Watson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/tools/tools/netrate/tcpreceive/tcpreceive.c 150970 2005-10-05 12:10:35Z rwatson $
+ */
+
+/*
+ * Back end to a variety of TCP-related benchmarks. This program accepts TCP
+ * connections on a port, and echoes all received data back to the sender.
+ * It is capable of handling only one connection at a time out of a single
+ * thread.
+ */
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
+#include <arpa/inet.h>
+
+#include <err.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * Simple micro-benchmark to see how many connections/second can be created
+ * in a serialized fashion against a given server. A timer signal is used
+ * to interrupt the loop and assess the cost, and uses a fixed maximum
+ * buffer size. It makes no attempt to time out old connections.
+ */
+#define BUFFERSIZE 128*1024
+#define PORT 6060
+
+static void
+handle_connection(int accept_sock)
+{
+ u_char buffer[BUFFERSIZE];
+ ssize_t len, recvlen, sofar;
+ int s;
+
+ s = accept(accept_sock, NULL, NULL);
+ if (s < 0) {
+ warn("accept");
+ return;
+ }
+
+ while (1) {
+ recvlen = recv(s, buffer, BUFFERSIZE, 0);
+ if (recvlen < 0 || recvlen == 0) {
+ close(s);
+ return;
+ }
+ sofar = 0;
+ while (sofar < recvlen) {
+ len = send(s, buffer + sofar, recvlen - sofar, 0);
+ if (len < 0) {
+ close(s);
+ return;
+ }
+ sofar += len;
+ }
+ }
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct sockaddr_in sin;
+ int accept_sock;
+
+ accept_sock = socket(PF_INET, SOCK_STREAM, 0);
+ if (accept_sock < 0)
+ err(-1, "socket(PF_INET, SOCKET_STREAM, 0)");
+
+ bzero(&sin, sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_len = sizeof(sin);
+ sin.sin_addr.s_addr = INADDR_ANY;
+ sin.sin_port = htons(PORT);
+
+ if (bind(accept_sock, (struct sockaddr *)&sin, sizeof(sin)) < 0)
+ err(-1, "bind");
+
+ if (listen(accept_sock, -1) < 0)
+ err(-1, "listen");
+
+ while (1)
+ handle_connection(accept_sock);
+
+ return (0);
+}
Property changes on: trunk/tools/tools/netrate/tcpreceive/tcpreceive.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
More information about the Midnightbsd-cvs
mailing list