Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Commit 549a2aef authored by Christopher Friedt's avatar Christopher Friedt Committed by Alexandre Bailon
Browse files

controllers: tcpip: use shutdown instead of close


When close(fd) is used on the a TCP/IP socket in Linux, it puts the socket
into a FIN_WAIT1 state and the TCP/IP connection is not completely severed
until the application terminates. On the server side, this has the effect
of keeping sockets open for an unnecessarily long period of time. If the
server is a memory-contstrained device such as a microcontroller, that
can have very negative effects.

For that reason, it is preferred to use shutdown(fd, SHUT_RDWR) instead.

Signed-off-by: default avatarChristopher Friedt <chrisfriedt@gmail.com>
parent 8ba7f56f
1 merge request!3This fixes many issues
...@@ -99,7 +99,10 @@ static int tcpip_connection_destroy(struct connection *conn) ...@@ -99,7 +99,10 @@ static int tcpip_connection_destroy(struct connection *conn)
struct tcpip_connection *tconn = conn->priv; struct tcpip_connection *tconn = conn->priv;
conn->priv = NULL; conn->priv = NULL;
close(tconn->sock); pr_info("closing socket %d\n", tconn->sock);
if (shutdown(tconn->sock, SHUT_RDWR)) {
pr_err("failed to close socket %d\n", tconn->sock);
}
free(tconn); free(tconn);
return 0; return 0;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment