test/send_recv: use stderr for errors
And include error value.
@@ -49,10 +49,11 @@ static int recv_prep(struct io_uring *ring, struct iovec *iov)
sqe = io_uring_get_sqe(ring);
io_uring_prep_recv(sqe, sockfd, iov->iov_base, iov->iov_len, 0);
+ sqe->user_data = 2;
ret = io_uring_submit(ring);
if (ret <= 0) {
- printf("submit failed\n");
+ fprintf(stderr, "submit failed: %d\n", ret);
goto err;
}
@@ -68,17 +69,18 @@ static int do_recv(struct io_uring *ring, struct iovec *iov)
io_uring_wait_cqe(ring, &cqe);
if (cqe->res < 0) {
- printf("failed cqe: %d\n", cqe->res);
+ fprintf(stderr, "failed cqe: %d\n", cqe->res);
goto err;
}
if (cqe->res -1 != strlen(str)) {
- printf("got wrong length\n");
+ fprintf(stderr, "got wrong length: %d/%d\n", cqe->res,
+ (int) strlen(str) + 1);
goto err;
}
if (strcmp(str, iov->iov_base)) {
- printf("string mismatch\n");
+ fprintf(stderr, "string mismatch\n");
goto err;
}
@@ -122,7 +124,7 @@ static int do_send(void)
ret = io_uring_queue_init(1, &ring, 0);
if (ret) {
- printf("queue init fail\n");
+ fprintf(stderr, "queue init fail: %d\n", ret);
return 1;
}
@@ -145,16 +147,17 @@ static int do_send(void)
sqe = io_uring_get_sqe(&ring);
io_uring_prep_send(sqe, sockfd, iov.iov_base, iov.iov_len, 0);
+ sqe->user_data = 1;
ret = io_uring_submit(&ring);
if (ret <= 0) {
- printf("submit failed\n");
+ fprintf(stderr, "submit failed: %d\n", ret);
goto err;
}
ret = io_uring_wait_cqe(&ring, &cqe);
if (cqe->res != iov.iov_len) {
- printf("failed cqe: %d\n", cqe->res);
+ fprintf(stderr, "failed cqe: %d\n", cqe->res);
goto err;
}
@@ -180,7 +183,7 @@ int main(int argc, char *argv[])
ret = pthread_create(&recv_thread, NULL, recv_fn, &mutex);
if (ret) {
- fprintf(stderr, "Thread create failed\n");
+ fprintf(stderr, "Thread create failed: %d\n", ret);
return 1;
}
