Sha256: 78d77675c7fce2a7392c66a5f3d1cc49cfb421ee5caba8d8d8206e3973695e09

Contents?: true

Size: 1.8 KB

Versions: 30

Compression:

Stored size: 1.8 KB

Contents

/* SPDX-License-Identifier: MIT */
/*
 * Description: Check to see if accept handles addr and addrlen
 */
#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <assert.h>
#include "liburing.h"
#include "helpers.h"

int main(int argc, char *argv[])
{
	struct io_uring_sqe *sqe;
	struct io_uring_cqe *cqe;
	struct io_uring ring;
	struct sockaddr_un addr;
	socklen_t addrlen = sizeof(addr);
	int ret, fd;
	struct __kernel_timespec ts = {
		.tv_sec = 0,
		.tv_nsec = 1000000
	};

	if (argc > 1)
		return T_EXIT_SKIP;

	if (io_uring_queue_init(4, &ring, 0) != 0) {
		fprintf(stderr, "ring setup failed\n");
		return T_EXIT_FAIL;
	}

	fd = socket(AF_UNIX, SOCK_STREAM, 0);
	assert(fd != -1);

	memset(&addr, 0, sizeof(addr));
	addr.sun_family = AF_UNIX;
	memcpy(addr.sun_path, "\0sock2", 7);

	ret = bind(fd, (struct sockaddr *)&addr, addrlen);
	assert(ret != -1);
	ret = listen(fd, 128);
	assert(ret != -1);

	sqe = io_uring_get_sqe(&ring);
	if (!sqe) {
		fprintf(stderr, "get sqe failed\n");
		return T_EXIT_FAIL;
	}
	io_uring_prep_accept(sqe, fd, (struct sockaddr*)&addr, &addrlen, 0);
	sqe->user_data = 1;

	ret = io_uring_submit(&ring);
	if (ret != 1) {
		fprintf(stderr, "Got submit %d, expected 1\n", ret);
		return T_EXIT_FAIL;
	}

	ret = io_uring_wait_cqe_timeout(&ring, &cqe, &ts);
	if (!ret) {
		if (cqe->res == -EBADF || cqe->res == -EINVAL) {
			fprintf(stdout, "Accept not supported, skipping\n");
			goto skip;
		} else if (cqe->res < 0) {
			fprintf(stderr, "cqe error %d\n", cqe->res);
			goto err;
		}
	} else if (ret != -ETIME) {
		fprintf(stderr, "accept() failed to use addr & addrlen parameters!\n");
		return T_EXIT_FAIL;
	}

	io_uring_queue_exit(&ring);
	return T_EXIT_PASS;

skip:
	io_uring_queue_exit(&ring);
	return T_EXIT_SKIP;
err:
	io_uring_queue_exit(&ring);
	return T_EXIT_FAIL;
}

Version data entries

30 entries across 30 versions & 3 rubygems

Version Path
uringmachine-0.5.1 vendor/liburing/test/accept-test.c
uringmachine-0.5 vendor/liburing/test/accept-test.c
uringmachine-0.4 vendor/liburing/test/accept-test.c
uringmachine-0.3 vendor/liburing/test/accept-test.c
uringmachine-0.2 vendor/liburing/test/accept-test.c
uringmachine-0.1 vendor/liburing/test/accept-test.c
iou-0.2 vendor/liburing/test/accept-test.c
iou-0.1 vendor/liburing/test/accept-test.c
polyphony-1.6 vendor/liburing/test/accept-test.c
polyphony-1.5 vendor/liburing/test/accept-test.c
polyphony-1.4 vendor/liburing/test/accept-test.c
polyphony-1.3 vendor/liburing/test/accept-test.c
polyphony-1.2.1 vendor/liburing/test/accept-test.c
polyphony-1.2 vendor/liburing/test/accept-test.c
polyphony-1.1.1 vendor/liburing/test/accept-test.c
polyphony-1.1 vendor/liburing/test/accept-test.c
polyphony-1.0.2 vendor/liburing/test/accept-test.c
polyphony-1.0.1 vendor/liburing/test/accept-test.c
polyphony-1.0 vendor/liburing/test/accept-test.c
polyphony-0.99.6 vendor/liburing/test/accept-test.c