From: Michael Tremer Date: Thu, 19 Sep 2024 11:44:18 +0000 (+0000) Subject: main: Don't spread across more ports any more X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=de414c0e3698c2f3b7784e83674788d301227f23;p=fireperf.git main: Don't spread across more ports any more Since we now have the main loop taking care of the connection handling there is probably very little point in spreading this across multiple processors. Signed-off-by: Michael Tremer --- diff --git a/src/client.c b/src/client.c index 92bff26..f87cb56 100644 --- a/src/client.c +++ b/src/client.c @@ -88,16 +88,13 @@ static int open_connection(struct fireperf_ctx* ctx, goto ERROR; } - // Chose a random port - int port = ctx->port + (random() % ctx->listening_sockets); - - DEBUG(ctx, "Opening socket %d (port %d)...\n", fd, port); + DEBUG(ctx, "Opening socket %d (port %d)...\n", fd, ctx->port); // Define the peer struct sockaddr_in6 peer = { .sin6_family = AF_INET6, .sin6_addr = ctx->address, - .sin6_port = htons(port), + .sin6_port = htons(ctx->port), }; // Set socket buffer sizes diff --git a/src/server.c b/src/server.c index 0aab9b0..d5d0c6d 100644 --- a/src/server.c +++ b/src/server.c @@ -83,7 +83,7 @@ static int enable_keepalive(struct fireperf_ctx* ctx, int fd) { return 0; } -static int create_socket(struct fireperf_ctx* ctx, int epollfd, unsigned int i) { +int fireperf_server_init(struct fireperf_ctx* ctx, void** data, int epollfd) { int flags = 1; int fd; int r; @@ -95,14 +95,6 @@ static int create_socket(struct fireperf_ctx* ctx, int epollfd, unsigned int i) goto ERROR; } - // Enable re-use port - r = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &flags, sizeof(flags)); - if (r) { - ERROR(ctx, "Could not set SO_REUSEPORT on socket %d: %s\n", - fd, strerror(errno)); - goto ERROR; - } - // Enable zero-copy r = setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &flags, sizeof(flags)); if (r) { @@ -125,7 +117,7 @@ static int create_socket(struct fireperf_ctx* ctx, int epollfd, unsigned int i) struct sockaddr_in6 addr = { .sin6_family = AF_INET6, - .sin6_port = htons(ctx->port + i), + .sin6_port = htons(ctx->port), }; // Bind it to the selected port @@ -160,7 +152,7 @@ static int create_socket(struct fireperf_ctx* ctx, int epollfd, unsigned int i) DEBUG(ctx, "Created listening socket %d\n", fd); - return fd; + return 0; ERROR: close(fd); @@ -168,19 +160,6 @@ ERROR: return r; } -int fireperf_server_init(struct fireperf_ctx* ctx, void** data, int epollfd) { - int r; - - // Create listening sockets - for (unsigned int i = 0; i < ctx->listening_sockets; i++) { - r = create_socket(ctx, epollfd, i); - if (r < 0) - return r; - } - - return 0; -} - int fireperf_server_handle(struct fireperf_ctx* ctx, void* data, int sockfd) { struct fireperf_worker* worker = NULL; struct sockaddr_in6 addr = {};