struct vsock_test_data { /* This test case if for SOCK_STREAM only. */ bool stream_only; /* Data must be zerocopied. This field is checked against * field 'ee_code' of the 'struct sock_extended_err', which * contains bit to detect that zerocopy transmission was * fallbacked to copy mode.
*/ bool zerocopied; /* Enable SO_ZEROCOPY option on the socket. Without enabled * SO_ZEROCOPY, every MSG_ZEROCOPY transmission will behave * like without MSG_ZEROCOPY flag.
*/ bool so_zerocopy; /* 'errno' after 'sendmsg()' call. */ int sendmsg_errno; /* Number of valid elements in 'vecs'. */ int vecs_cnt; struct iovec vecs[VSOCK_TEST_DATA_MAX_IOV];
};
staticstruct vsock_test_data test_data_array[] = { /* Last element has non-page aligned size. */
{
.zerocopied = true,
.so_zerocopy = true,
.sendmsg_errno = 0,
.vecs_cnt = 3,
{
{ NULL, PAGE_SIZE },
{ NULL, PAGE_SIZE },
{ NULL, 200 }
}
}, /* All elements have page aligned base and size. */
{
.zerocopied = true,
.so_zerocopy = true,
.sendmsg_errno = 0,
.vecs_cnt = 3,
{
{ NULL, PAGE_SIZE },
{ NULL, PAGE_SIZE * 2 },
{ NULL, PAGE_SIZE * 3 }
}
}, /* All elements have page aligned base and size. But * data length is bigger than 64Kb.
*/
{
.zerocopied = true,
.so_zerocopy = true,
.sendmsg_errno = 0,
.vecs_cnt = 3,
{
{ NULL, PAGE_SIZE * 16 },
{ NULL, PAGE_SIZE * 16 },
{ NULL, PAGE_SIZE * 16 }
}
}, /* Middle element has both non-page aligned base and size. */
{
.zerocopied = true,
.so_zerocopy = true,
.sendmsg_errno = 0,
.vecs_cnt = 3,
{
{ NULL, PAGE_SIZE },
{ (void *)1, 100 },
{ NULL, PAGE_SIZE }
}
}, /* Middle element is unmapped. */
{
.zerocopied = false,
.so_zerocopy = true,
.sendmsg_errno = ENOMEM,
.vecs_cnt = 3,
{
{ NULL, PAGE_SIZE },
{ MAP_FAILED, PAGE_SIZE },
{ NULL, PAGE_SIZE }
}
}, /* Valid data, but SO_ZEROCOPY is off. This * will trigger fallback to copy.
*/
{
.zerocopied = false,
.so_zerocopy = false,
.sendmsg_errno = 0,
.vecs_cnt = 1,
{
{ NULL, PAGE_SIZE }
}
}, /* Valid data, but message is bigger than peer's * buffer, so this will trigger fallback to copy. * This test is for SOCK_STREAM only, because * for SOCK_SEQPACKET, 'sendmsg()' returns EMSGSIZE.
*/
{
.stream_only = true,
.zerocopied = false,
.so_zerocopy = true,
.sendmsg_errno = 0,
.vecs_cnt = 1,
{
{ NULL, 100 * PAGE_SIZE }
}
},
};
if (poll(&fds, 1, POLL_TIMEOUT_MS) < 0) {
perror("poll"); exit(EXIT_FAILURE);
}
if (fds.revents & POLLERR) {
vsock_recv_completion(fd, &test_data->zerocopied);
} elseif (test_data->so_zerocopy && !test_data->sendmsg_errno) { /* If we don't have data in the error queue, but * SO_ZEROCOPY was enabled and 'sendmsg()' was * successful - this is an error.
*/
fprintf(stderr, "POLLERR expected\n"); exit(EXIT_FAILURE);
}
if (!test_data->sendmsg_errno)
control_writeulong(iovec_hash_djb2(iovec, test_data->vecs_cnt)); else
control_writeulong(0);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.