summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2021-03-29 10:38:03 -0600
committerJens Axboe <axboe@kernel.dk>2021-03-29 10:38:03 -0600
commita36a801cfb38b3ce0e97dac03696f5e5fc28b760 (patch)
tree134ef921e84edfba44b51c0f0add0758508219d3
parent8bfdf56caaca4dc58e230f07d33f875b7d0648c8 (diff)
downloadliburing-a36a801cfb38b3ce0e97dac03696f5e5fc28b760.tar.gz
liburing-a36a801cfb38b3ce0e97dac03696f5e5fc28b760.tar.bz2
test/connect: randomize connect port
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/connect.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/test/connect.c b/test/connect.c
index 34e3954..ab81bb8 100644
--- a/test/connect.c
+++ b/test/connect.c
@@ -18,6 +18,7 @@
#include "liburing.h"
static int no_connect;
+static int use_port;
static int create_socket(void)
{
@@ -87,7 +88,7 @@ static int listen_on_socket(int fd)
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- addr.sin_port = 0x1234;
+ addr.sin_port = use_port;
addr.sin_addr.s_addr = 0x0100007fU;
ret = bind(fd, (struct sockaddr*)&addr, sizeof(addr));
@@ -123,7 +124,7 @@ static int configure_connect(int fd, struct sockaddr_in* addr)
memset(addr, 0, sizeof(*addr));
addr->sin_family = AF_INET;
- addr->sin_port = 0x1234;
+ addr->sin_port = use_port;
addr->sin_addr.s_addr = 0x0100007fU;
return 0;
@@ -247,7 +248,7 @@ err1:
static int test_connect_timeout(struct io_uring *ring)
{
- int fd = -1, connect_fd = -1, accept_fd = -1;
+ int connect_fd = -1, accept_fd = -1;
int ret;
struct sockaddr_in addr;
struct io_uring_sqe *sqe;
@@ -276,13 +277,6 @@ static int test_connect_timeout(struct io_uring *ring)
goto err;
}
- // Fill up available place in the accept queue (backlog)
- fd = create_socket();
- if (connect(fd, &addr, sizeof(addr)) == -1) {
- fprintf(stderr, "unable to connect %d\n", errno);
- goto err;
- }
-
sqe = io_uring_get_sqe(ring);
if (!sqe) {
fprintf(stderr, "unable to get sqe\n");
@@ -328,16 +322,12 @@ static int test_connect_timeout(struct io_uring *ring)
close(connect_fd);
close(accept_fd);
- close(fd);
-
return 0;
err:
close(connect_fd);
if (accept_fd != -1)
close(accept_fd);
- if (fd != -1)
- close(fd);
return -1;
}
@@ -355,6 +345,9 @@ int main(int argc, char *argv[])
return 1;
}
+ srand(getpid());
+ use_port = (rand() % 61440) + 4096;
+
ret = test_connect_with_no_peer(&ring);
if (ret == -1) {
fprintf(stderr, "test_connect_with_no_peer(): failed\n");