Bläddra i källkod

Avoid reusing auto-allocated ports after connection close.

tags/v0.9.3
Michael Brown 18 år sedan
förälder
incheckning
d5735c631c
1 ändrade filer med 3 tillägg och 2 borttagningar
  1. 3
    2
      src/net/tcp.c

+ 3
- 2
src/net/tcp.c Visa fil

160
  */
160
  */
161
 static int tcp_bind ( struct tcp_connection *tcp, unsigned int port ) {
161
 static int tcp_bind ( struct tcp_connection *tcp, unsigned int port ) {
162
 	struct tcp_connection *existing;
162
 	struct tcp_connection *existing;
163
-	static uint16_t try_port = 1024;
163
+	static uint16_t try_port = 1023;
164
 
164
 
165
 	/* If no port specified, find the first available port */
165
 	/* If no port specified, find the first available port */
166
 	if ( ! port ) {
166
 	if ( ! port ) {
167
-		for ( ; try_port ; try_port++ ) {
167
+		while ( try_port ) {
168
+			try_port++;
168
 			if ( try_port < 1024 )
169
 			if ( try_port < 1024 )
169
 				continue;
170
 				continue;
170
 			if ( tcp_bind ( tcp, htons ( try_port ) ) == 0 )
171
 			if ( tcp_bind ( tcp, htons ( try_port ) ) == 0 )

Laddar…
Avbryt
Spara