tools/testing/vsock/util.c
Source file repositories/reference/linux-study-clean/tools/testing/vsock/util.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/vsock/util.c- Extension
.c- Size
- 20195 bytes
- Lines
- 955
- 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
ctype.herrno.hstdio.hstdint.hstdlib.hstring.hsignal.hunistd.hassert.hsys/epoll.hsys/ioctl.hsys/mman.hlinux/sockios.htimeout.hcontrol.hutil.h
Detected Declarations
function Copyrightfunction parse_uintfunction parse_cidfunction parse_portfunction vsock_wait_remote_closefunction vsock_ioctl_intfunction unsent_bytesfunction vsock_bind_tryfunction vsock_bindfunction vsock_connect_fdfunction vsock_bind_connectfunction vsock_connectfunction vsock_stream_connectfunction vsock_seqpacket_connectfunction vsock_listenfunction vsock_acceptfunction vsock_stream_acceptfunction vsock_stream_listenfunction vsock_seqpacket_acceptfunction send_buffunction recv_buffunction send_bytefunction recv_bytefunction run_testsfunction list_testsfunction parse_test_idfunction skip_testfunction pick_testfunction hash_djb2function iovec_bytesfunction iovec_hash_djb2function mmapfunction free_test_iovecfunction setsockopt_ull_checkfunction setsockopt_int_checkfunction mem_invertfunction setsockopt_timeval_checkfunction enable_so_zerocopy_checkfunction enable_so_lingerfunction __get_transportsfunction get_transports
Annotated Snippet
if (ret < 0) {
if (errno == EOPNOTSUPP || errno == ENOTTY)
break;
perror(name);
exit(EXIT_FAILURE);
}
timeout_check(name);
} while (actual != expected);
timeout_end();
return ret >= 0;
}
/* Wait until transport reports no data left to be sent.
* Return false if transport does not implement the unsent_bytes() callback.
*/
bool vsock_wait_sent(int fd)
{
return vsock_ioctl_int(fd, SIOCOUTQ, 0);
}
/* Create socket <type>, bind to <cid, port>.
* Return the file descriptor, or -1 on error.
*/
int vsock_bind_try(unsigned int cid, unsigned int port, int type)
{
struct sockaddr_vm sa = {
.svm_family = AF_VSOCK,
.svm_cid = cid,
.svm_port = port,
};
int fd, saved_errno;
fd = socket(AF_VSOCK, type, 0);
if (fd < 0) {
perror("socket");
exit(EXIT_FAILURE);
}
if (bind(fd, (struct sockaddr *)&sa, sizeof(sa))) {
saved_errno = errno;
close(fd);
errno = saved_errno;
fd = -1;
}
return fd;
}
/* Create socket <type>, bind to <cid, port> and return the file descriptor. */
int vsock_bind(unsigned int cid, unsigned int port, int type)
{
int fd;
fd = vsock_bind_try(cid, port, type);
if (fd < 0) {
perror("bind");
exit(EXIT_FAILURE);
}
return fd;
}
int vsock_connect_fd(int fd, unsigned int cid, unsigned int port)
{
struct sockaddr_vm sa = {
.svm_family = AF_VSOCK,
.svm_cid = cid,
.svm_port = port,
};
int ret;
timeout_begin(TIMEOUT);
do {
ret = connect(fd, (struct sockaddr *)&sa, sizeof(sa));
timeout_check("connect");
} while (ret < 0 && errno == EINTR);
timeout_end();
return ret;
}
/* Bind to <bind_port>, connect to <cid, port> and return the file descriptor. */
int vsock_bind_connect(unsigned int cid, unsigned int port, unsigned int bind_port, int type)
{
int client_fd;
client_fd = vsock_bind(VMADDR_CID_ANY, bind_port, type);
Annotation
- Immediate include surface: `ctype.h`, `errno.h`, `stdio.h`, `stdint.h`, `stdlib.h`, `string.h`, `signal.h`, `unistd.h`.
- Detected declarations: `function Copyright`, `function parse_uint`, `function parse_cid`, `function parse_port`, `function vsock_wait_remote_close`, `function vsock_ioctl_int`, `function unsent_bytes`, `function vsock_bind_try`, `function vsock_bind`, `function vsock_connect_fd`.
- 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.