Skip to content

Commit e58bdf9

Browse files
committed
test: keep using the same local port unless EADDRNOTAVAIL occurs
1 parent dd81490 commit e58bdf9

4 files changed

Lines changed: 9 additions & 37 deletions

File tree

src/hev-conf.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ static int dmon;
2626
static int tmsec;
2727
static int brand;
2828
static int bport[3];
29-
static int nrebind;
3029
static unsigned int mark;
3130

3231
static char mport[16];
@@ -68,8 +67,6 @@ hev_conf_help (void)
6867
" - <port>: specified\n"
6968
" - <port>~<port>: random allocation within the range\n"
7069
" - <port>-<port>: sequential allocation within the range\n"
71-
" -r <times> when using port range, number of times to rebind\n"
72-
" the previous port before switching (0: disable)\n"
7370
"\n"
7471
"Forward options:\n"
7572
" -C <congestion> TCP congestion control algorithm\n"
@@ -87,7 +84,7 @@ hev_conf_init (int argc, char *argv[])
8784
int opt;
8885
char c;
8986

90-
while ((opt = getopt (argc, argv, "46udk:c:s:h:e:f:b:r:C:T:t:p:i:")) != -1) {
87+
while ((opt = getopt (argc, argv, "46udk:c:s:h:e:f:b:C:T:t:p:i:")) != -1) {
9188
switch (opt) {
9289
case '4':
9390
type = AF_INET;
@@ -122,9 +119,6 @@ hev_conf_init (int argc, char *argv[])
122119
case 'b':
123120
sscanf (optarg, "%u%c%u", &bport[0], &c, &bport[1]);
124121
break;
125-
case 'r':
126-
nrebind = strtoul (optarg, NULL, 10);
127-
break;
128122
case 'C':
129123
ttcca = optarg;
130124
break;
@@ -182,10 +176,6 @@ hev_conf_init (int argc, char *argv[])
182176
return -1;
183177
}
184178

185-
if (nrebind < 0) {
186-
nrebind = 0;
187-
}
188-
189179
if (iface && inet_pton (type, iface, &sa)) {
190180
baddr = iface;
191181
iface = NULL;
@@ -276,12 +266,6 @@ hev_conf_bport (void)
276266
return port;
277267
}
278268

279-
int
280-
hev_conf_nrebind (void)
281-
{
282-
return nrebind;
283-
}
284-
285269
const char *
286270
hev_conf_taddr (void)
287271
{

src/hev-conf.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,6 @@ const char *hev_conf_baddr (void);
120120
*/
121121
const char *hev_conf_bport (void);
122122

123-
/**
124-
* hev_conf_nrebind:
125-
*
126-
* Get the maximum number of times to rebind the previous port.
127-
* This is used when a port range is configured to minimize port switching.
128-
*
129-
* Returns: returns the number of times to rebind.
130-
*/
131-
int hev_conf_nrebind (void);
132-
133123
/**
134124
* hev_conf_taddr:
135125
*

src/hev-tnsk.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
static struct sockaddr_storage saddr;
2929
static char last_port[16];
30-
static int rebind_times;
30+
static int port_valid;
3131
static HevTask *task;
3232
static int timeout;
3333
static int fd;
@@ -105,20 +105,19 @@ tnsk_run (void)
105105
iface = hev_conf_iface ();
106106
mark = hev_conf_mark ();
107107

108-
if (rebind_times > 0) {
108+
if (port_valid == 1) {
109109
port = last_port;
110-
rebind_times--;
111110
} else {
112111
port = hev_conf_bport ();
113112
snprintf (last_port, sizeof (last_port), "%s", port);
114-
rebind_times = hev_conf_nrebind ();
113+
port_valid = 1;
115114
}
116115

117116
fd = hev_sock_client_base (type, SOCK_STREAM, addr, port, http, hport,
118117
iface, mark, &saddr, NULL);
119118
if (fd < 0) {
120119
if (errno == EADDRNOTAVAIL) {
121-
rebind_times = 0;
120+
port_valid = 0;
122121
}
123122
LOGV (E, "%s", "Start TCP keep-alive service failed.");
124123
return;

src/hev-unsk.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static HevTask *task;
3131
static int timeout;
3232
static unsigned int cycle;
3333
static char last_port[16];
34-
static int rebind_times;
34+
static int port_valid;
3535

3636
static void
3737
stun_handler (void)
@@ -105,20 +105,19 @@ unsk_run (void)
105105
timeout = hev_conf_keep ();
106106
cycle = hev_conf_ucount ();
107107

108-
if (rebind_times > 0) {
108+
if (port_valid == 1) {
109109
port = last_port;
110-
rebind_times--;
111110
} else {
112111
port = hev_conf_bport ();
113112
snprintf (last_port, sizeof (last_port), "%s", port);
114-
rebind_times = hev_conf_nrebind ();
113+
port_valid = 1;
115114
}
116115

117116
fd = hev_sock_client_base (type, SOCK_DGRAM, addr, port, stun, sport, iface,
118117
mark, &saddr, &daddr);
119118
if (fd < 0) {
120119
if (errno == EADDRNOTAVAIL) {
121-
rebind_times = 0;
120+
port_valid = 0;
122121
}
123122
LOGV (E, "%s", "Start UDP keep-alive service failed.");
124123
return;

0 commit comments

Comments
 (0)