|
21 | 21 | #include <sys/epoll.h>
|
22 | 22 | #include <sys/types.h>
|
23 | 23 | #include <sys/socket.h>
|
| 24 | +#include <sys/resource.h> |
24 | 25 | #include <unistd.h>
|
25 | 26 |
|
26 | 27 | #ifndef ARRAY_SIZE
|
@@ -190,11 +191,14 @@ static void send_from(struct test_params p, uint16_t sport, char *buf,
|
190 | 191 | struct sockaddr * const saddr = new_any_sockaddr(p.send_family, sport);
|
191 | 192 | struct sockaddr * const daddr =
|
192 | 193 | new_loopback_sockaddr(p.send_family, p.recv_port);
|
193 |
| - const int fd = socket(p.send_family, p.protocol, 0); |
| 194 | + const int fd = socket(p.send_family, p.protocol, 0), one = 1; |
194 | 195 |
|
195 | 196 | if (fd < 0)
|
196 | 197 | error(1, errno, "failed to create send socket");
|
197 | 198 |
|
| 199 | + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) |
| 200 | + error(1, errno, "failed to set reuseaddr"); |
| 201 | + |
198 | 202 | if (bind(fd, saddr, sockaddr_size()))
|
199 | 203 | error(1, errno, "failed to bind send socket");
|
200 | 204 |
|
@@ -433,6 +437,21 @@ void enable_fastopen(void)
|
433 | 437 | }
|
434 | 438 | }
|
435 | 439 |
|
| 440 | +static struct rlimit rlim_old, rlim_new; |
| 441 | + |
| 442 | +static __attribute__((constructor)) void main_ctor(void) |
| 443 | +{ |
| 444 | + getrlimit(RLIMIT_MEMLOCK, &rlim_old); |
| 445 | + rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20); |
| 446 | + rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20); |
| 447 | + setrlimit(RLIMIT_MEMLOCK, &rlim_new); |
| 448 | +} |
| 449 | + |
| 450 | +static __attribute__((destructor)) void main_dtor(void) |
| 451 | +{ |
| 452 | + setrlimit(RLIMIT_MEMLOCK, &rlim_old); |
| 453 | +} |
| 454 | + |
436 | 455 | int main(void)
|
437 | 456 | {
|
438 | 457 | fprintf(stderr, "---- IPv4 UDP ----\n");
|
|
0 commit comments