diff -ur ttssh2.org/ttxssh/fwd.c ttssh2/ttxssh/fwd.c --- ttssh2.org/ttxssh/fwd.c 2019-09-27 11:18:16.762388000 +0900 +++ ttssh2/ttxssh/fwd.c 2019-09-27 13:16:54.127169200 +0900 @@ -264,6 +264,20 @@ /* freeaddrinfo(); */ } +void FWD_shutdown_channel(PTInstVar pvar, uint32 local_channel_num) { + + FWDChannel* channel = pvar->fwd_state.channels + local_channel_num; + + shutdown(channel->local_socket, 2); // Shut down the channle with the SD_BOTH(2). + logprintf(LOG_LEVEL_VERBOSE, "%s: channel was shut down. local:%d", + __FUNCTION__, local_channel_num); + + closed_local_connection(pvar, local_channel_num); + logprintf(LOG_LEVEL_VERBOSE, "%s: channel was closed. local:%d", + __FUNCTION__, local_channel_num); + FWD_free_channel(pvar, local_channel_num); +} + void FWD_free_channel(PTInstVar pvar, uint32 local_channel_num) { FWDChannel *channel = &pvar->fwd_state.channels[local_channel_num]; @@ -310,14 +324,8 @@ channel = pvar->fwd_state.channels + local_channel_num; - if (channel->local_socket != INVALID_SOCKET) { - shutdown(channel->local_socket, 1); - } + // The channel will be shut down on channel close. channel->status |= FWD_CLOSED_REMOTE_IN; - if ((channel->status & FWD_CLOSED_REMOTE_OUT) == FWD_CLOSED_REMOTE_OUT) { - closed_local_connection(pvar, local_channel_num); - FWD_free_channel(pvar, local_channel_num); - } } void FWD_channel_output_eof(PTInstVar pvar, uint32 local_channel_num) @@ -329,14 +337,8 @@ channel = pvar->fwd_state.channels + local_channel_num; - if (channel->local_socket != INVALID_SOCKET) { - shutdown(channel->local_socket, 0); - } + // The channel will be shut down on channel close. channel->status |= FWD_CLOSED_REMOTE_OUT; - if ((channel->status & FWD_CLOSED_REMOTE_IN) == FWD_CLOSED_REMOTE_IN) { - closed_local_connection(pvar, local_channel_num); - FWD_free_channel(pvar, local_channel_num); - } } static char *describe_socket_error(PTInstVar pvar, int code) diff -ur ttssh2.org/ttxssh/fwd.h ttssh2/ttxssh/fwd.h --- ttssh2.org/ttxssh/fwd.h 2019-09-27 11:18:17.265027300 +0900 +++ ttssh2/ttxssh/fwd.h 2019-09-26 16:35:39.210377900 +0900 @@ -166,6 +166,7 @@ void FWD_channel_output_eof(PTInstVar pvar, uint32 local_channel_num); void FWD_end(PTInstVar pvar); void FWD_free_channel(PTInstVar pvar, uint32 local_channel_num); +void FWD_shutdown_channel(PTInstVar pvar, uint32 local_channel_num); int FWD_check_local_channel_num(PTInstVar pvar, int local_num); int FWD_agent_open(PTInstVar pvar, uint32 remote_channel_num); BOOL FWD_agent_forward_confirm(PTInstVar pvar); diff -ur ttssh2.org/ttxssh/ssh.c ttssh2/ttxssh/ssh.c --- ttssh2.org/ttxssh/ssh.c 2019-09-27 11:18:16.759461500 +0900 +++ ttssh2/ttxssh/ssh.c 2019-09-27 13:15:44.881674900 +0900 @@ -9204,6 +9204,10 @@ notify_closed_connection(pvar, "disconnected by server request"); } else if (c->type == TYPE_PORTFWD) { + + // Shut down the channel. + FWD_shutdown_channel(pvar, c->local_num); + // CHANNEL_CLOSE 𑗂ԂȂƃ[gchannelJȂ // c.f. RFC 4253 5.3. Closing a Channel ssh2_channel_send_close(pvar, c);