tools/testing/selftests/net/udpgso_bench_rx.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/udpgso_bench_rx.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/udpgso_bench_rx.c
Extension
.c
Size
8831 bytes
Lines
410
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (ret == 0) {
			if (!timeout_ms)
				continue;

			timeout_ms -= 10;
			if (timeout_ms <= 0) {
				interrupted = true;
				break;
			}

			/* no events and more time to wait, do poll again */
			continue;
		}
		if (pfd.revents != POLLIN)
			error(1, errno, "poll: 0x%x expected 0x%x\n",
					pfd.revents, POLLIN);
	} while (!ret);
}

static int do_socket(bool do_tcp)
{
	int fd, val;

	fd = socket(cfg_family, cfg_tcp ? SOCK_STREAM : SOCK_DGRAM, 0);
	if (fd == -1)
		error(1, errno, "socket");

	val = 1 << 21;
	if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)))
		error(1, errno, "setsockopt rcvbuf");
	val = 1;
	if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)))
		error(1, errno, "setsockopt reuseport");

	if (bind(fd, (void *)&cfg_bind_addr, cfg_alen))
		error(1, errno, "bind");

	if (do_tcp) {
		int accept_fd = fd;

		if (listen(accept_fd, 1))
			error(1, errno, "listen");

		do_poll(accept_fd, cfg_connect_timeout_ms);
		if (interrupted)
			exit(0);

		fd = accept(accept_fd, NULL, NULL);
		if (fd == -1)
			error(1, errno, "accept");
		if (close(accept_fd))
			error(1, errno, "close accept fd");
	}

	return fd;
}

/* Flush all outstanding bytes for the tcp receive queue */
static void do_flush_tcp(int fd)
{
	int ret;

	while (true) {
		/* MSG_TRUNC flushes up to len bytes */
		ret = recv(fd, NULL, 1 << 21, MSG_TRUNC | MSG_DONTWAIT);
		if (ret == -1 && errno == EAGAIN)
			return;
		if (ret == -1)
			error(1, errno, "flush");
		if (ret == 0) {
			/* client detached */
			exit(0);
		}

		packets++;
		bytes += ret;
	}

}

static char sanitized_char(char val)
{
	return (val >= 'a' && val <= 'z') ? val : '.';
}

static void do_verify_udp(const char *data, int len)
{
	char cur = data[0];
	int i;

Annotation

Implementation Notes