- if (msg->Input.Shutdown.shut_rx) {
- msg->Output.Shutdown.Error = tcp_shutdown(pcb, TRUE, FALSE);
+ if (msg->Input.Shutdown.shut_rx != msg->Input.Shutdown.shut_tx) {
+ if (msg->Input.Shutdown.shut_rx) {
+ msg->Output.Shutdown.Error = tcp_shutdown(pcb, TRUE, FALSE);
+ }
+ if (msg->Input.Shutdown.shut_tx) {
+ msg->Output.Shutdown.Error = tcp_shutdown(pcb, FALSE, TRUE);
+ }
+ }
+ else if (msg->Input.Shutdown.shut_rx) {
+ /* We received both RX and TX requests, which seems to mean closing connection from TDI.
+ * So call tcp_close, otherwise we risk to be put in TCP_WAIT_* states, which makes further
+ * attempts to close the socket to fail in this state.
+ */
+ msg->Output.Shutdown.Error = tcp_close(pcb);