tools/testing/vsock/control.c
Source file repositories/reference/linux-study-clean/tools/testing/vsock/control.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/vsock/control.c- Extension
.c- Size
- 4776 bytes
- Lines
- 252
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hnetdb.hstdio.hstdlib.hstring.hunistd.hsys/types.hsys/socket.htimeout.hcontrol.hutil.h
Detected Declarations
function control_initfunction control_cleanupfunction control_writelnfunction control_writeulongfunction control_readulongfunction freefunction control_expectlnfunction control_cmpln
Annotated Snippet
if (!server) {
if (connect(fd, ai->ai_addr, ai->ai_addrlen) < 0)
goto next;
control_fd = fd;
printf("Control socket connected to %s:%s.\n",
control_host, control_port);
break;
}
setsockopt_int_check(fd, SOL_SOCKET, SO_REUSEADDR, 1,
"setsockopt SO_REUSEADDR");
if (bind(fd, ai->ai_addr, ai->ai_addrlen) < 0)
goto next;
if (listen(fd, 1) < 0)
goto next;
printf("Control socket listening on %s:%s\n",
control_host, control_port);
fflush(stdout);
control_fd = accept(fd, NULL, 0);
close(fd);
if (control_fd < 0) {
perror("accept");
exit(EXIT_FAILURE);
}
printf("Control socket connection accepted...\n");
break;
next:
close(fd);
}
if (control_fd < 0) {
fprintf(stderr, "Control socket initialization failed. Invalid address %s:%s?\n",
control_host, control_port);
exit(EXIT_FAILURE);
}
freeaddrinfo(result);
}
/* Free resources */
void control_cleanup(void)
{
close(control_fd);
control_fd = -1;
}
/* Write a line to the control socket */
void control_writeln(const char *str)
{
ssize_t len = strlen(str);
ssize_t ret;
timeout_begin(TIMEOUT);
do {
ret = send(control_fd, str, len, MSG_MORE);
timeout_check("send");
} while (ret < 0 && errno == EINTR);
if (ret != len) {
perror("send");
exit(EXIT_FAILURE);
}
do {
ret = send(control_fd, "\n", 1, 0);
timeout_check("send");
} while (ret < 0 && errno == EINTR);
if (ret != 1) {
perror("send");
exit(EXIT_FAILURE);
}
timeout_end();
}
void control_writeulong(unsigned long value)
{
char str[32];
if (snprintf(str, sizeof(str), "%lu", value) >= sizeof(str)) {
perror("snprintf");
exit(EXIT_FAILURE);
}
Annotation
- Immediate include surface: `errno.h`, `netdb.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `sys/types.h`, `sys/socket.h`.
- Detected declarations: `function control_init`, `function control_cleanup`, `function control_writeln`, `function control_writeulong`, `function control_readulong`, `function free`, `function control_expectln`, `function control_cmpln`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.