mirror of
https://github.com/openharmony/third_party_liburing.git
synced 2026-07-20 22:58:41 -04:00
t/socket-rw-offset: Don't brute force the port number
Don't brute force the port number, use `t_bind_ephemeral_port()`, much simpler and reliable for choosing a port number that is not in use. Cc: Dylan Yudaken <dylany@fb.com> Cc: Facebook Kernel Team <kernel-team@fb.com> Cc: Pavel Begunkov <asml.silence@gmail.com> Reviewed-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org> Tested-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org> Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> Link: https://lore.kernel.org/r/20220902071153.3168814-6-ammar.faizi@intel.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
+2
-11
@@ -20,6 +20,7 @@
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "liburing.h"
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -43,17 +44,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
|
||||
do {
|
||||
addr.sin_port = htons((rand() % 61440) + 4096);
|
||||
ret = bind(recv_s0, (struct sockaddr*)&addr, sizeof(addr));
|
||||
if (!ret)
|
||||
break;
|
||||
if (errno != EADDRINUSE) {
|
||||
perror("bind");
|
||||
exit(1);
|
||||
}
|
||||
} while (1);
|
||||
assert(!t_bind_ephemeral_port(recv_s0, &addr));
|
||||
ret = listen(recv_s0, 128);
|
||||
assert(ret != -1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user