Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libc/tests/sys/sendfile_test.c
Show First 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* This function is a helper routine for taking data being sent by `sendfile` via | * This function is a helper routine for taking data being sent by `sendfile` via | ||||
* `server_sock`, and pushing the received stream out to a file, denoted by | * `server_sock`, and pushing the received stream out to a file, denoted by | ||||
* `dest_filename`. | * `dest_filename`. | ||||
*/ | */ | ||||
static void | static void | ||||
server_cat(const char *dest_filename, int server_sock, size_t len) | server_cat(const char *dest_filename, int server_sock, size_t len) | ||||
{ | { | ||||
void *buffer; | char *buffer; | ||||
int recv_sock; | int recv_sock; | ||||
ssize_t received_bytes; | ssize_t received_bytes; | ||||
buffer = calloc(len + 1, sizeof(char)); | buffer = calloc(len + 1, sizeof(char)); | ||||
if (buffer == NULL) | if (buffer == NULL) | ||||
err(1, "malloc failed"); | err(1, "malloc failed"); | ||||
recv_sock = accept(server_sock, NULL, 0); | recv_sock = accept(server_sock, NULL, 0); | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* NB: `nbytes` == 0 has special connotations given the sendfile(2) API | * NB: `nbytes` == 0 has special connotations given the sendfile(2) API | ||||
* contract. In short, "send the whole file" (paraphrased). | * contract. In short, "send the whole file" (paraphrased). | ||||
*/ | */ | ||||
static void | static void | ||||
verify_source_and_dest(const char* dest_filename, int src_fd, off_t offset, | verify_source_and_dest(const char* dest_filename, int src_fd, off_t offset, | ||||
size_t nbytes) | size_t nbytes) | ||||
{ | { | ||||
void *dest_pointer, *src_pointer; | char *dest_pointer, *src_pointer; | ||||
off_t dest_file_size, src_file_size; | off_t dest_file_size, src_file_size; | ||||
size_t length; | size_t length; | ||||
int dest_fd; | int dest_fd; | ||||
atf_utils_cat_file(dest_filename, "dest_file: "); | atf_utils_cat_file(dest_filename, "dest_file: "); | ||||
dest_fd = open(dest_filename, O_RDONLY); | dest_fd = open(dest_filename, O_RDONLY); | ||||
ATF_REQUIRE_MSG(dest_fd != -1, "open failed"); | ATF_REQUIRE_MSG(dest_fd != -1, "open failed"); | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
fd_positive_file_test(AF_INET6); | fd_positive_file_test(AF_INET6); | ||||
} | } | ||||
static void | static void | ||||
fd_positive_shm_test(int domain) | fd_positive_shm_test(int domain) | ||||
{ | { | ||||
void *shm_pointer; | char *shm_pointer; | ||||
off_t offset; | off_t offset; | ||||
size_t nbytes, pattern_size; | size_t nbytes, pattern_size; | ||||
pid_t server_pid; | pid_t server_pid; | ||||
int client_sock, error, fd, port, server_sock; | int client_sock, error, fd, port, server_sock; | ||||
pattern_size = strlen(DETERMINISTIC_PATTERN); | pattern_size = strlen(DETERMINISTIC_PATTERN); | ||||
printf("pattern size: %zu\n", pattern_size); | printf("pattern size: %zu\n", pattern_size); | ||||
▲ Show 20 Lines • Show All 286 Lines • ▼ Show 20 Lines | if (testcases[i].include_trailers) { | ||||
hdtr.trl_cnt = 0; | hdtr.trl_cnt = 0; | ||||
} | } | ||||
port = generate_random_port(i * __LINE__ + domain); | port = generate_random_port(i * __LINE__ + domain); | ||||
server_sock = setup_tcp_server(domain, port); | server_sock = setup_tcp_server(domain, port); | ||||
client_sock = setup_tcp_client(domain, port); | client_sock = setup_tcp_client(domain, port); | ||||
rc = asprintf(&pattern, "%s%s%s", | rc = asprintf(&pattern, "%s%s%s", | ||||
testcases[i].include_headers ? headers[0].iov_base : "", | testcases[i].include_headers ? (char *)headers[0].iov_base : "", | ||||
DETERMINISTIC_PATTERN, | DETERMINISTIC_PATTERN, | ||||
testcases[i].include_trailers ? trailers[0].iov_base : ""); | testcases[i].include_trailers ? (char *)trailers[0].iov_base : ""); | ||||
ATF_REQUIRE_MSG(rc != -1, "asprintf failed: %s", strerror(errno)); | ATF_REQUIRE_MSG(rc != -1, "asprintf failed: %s", strerror(errno)); | ||||
atf_utils_create_file(SOURCE_FILE ".full", "%s", pattern); | atf_utils_create_file(SOURCE_FILE ".full", "%s", pattern); | ||||
atf_utils_create_file(SOURCE_FILE, "%s", DETERMINISTIC_PATTERN); | atf_utils_create_file(SOURCE_FILE, "%s", DETERMINISTIC_PATTERN); | ||||
fd = open(SOURCE_FILE, O_RDONLY); | fd = open(SOURCE_FILE, O_RDONLY); | ||||
ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno)); | ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno)); | ||||
▲ Show 20 Lines • Show All 446 Lines • Show Last 20 Lines |