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
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;
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) {
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
DEBUG(ctx, "Created listening socket %d\n", fd);
- return fd;
+ return 0;
ERROR:
close(fd);
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 = {};