Revision: 7732 https://osdn.net/projects/ttssh2/scm/svn/commits/7732 Author: yutakapon Date: 2019-06-06 00:00:47 +0900 (Thu, 06 Jun 2019) Log Message: ----------- ポート転送においてlocal channelからのパケット読み込み時、SSHサーバへの送信でremote_windowに 空きがない場合は、ソケットのメッセージ通知を抑止するようにした。remote_windowに空きができたら、 再度通知を再開させる。 これにより、延々とlocal channelからのパケットを読み込み続けることがなくなる。 チケット #39297 Ticket Links: ------------ https://osdn.net/projects/ttssh2/tracker/detail/39297 Modified Paths: -------------- branches/portfwd_memleak/ttssh2/ttxssh/fwd.c branches/portfwd_memleak/ttssh2/ttxssh/fwd.h branches/portfwd_memleak/ttssh2/ttxssh/ssh.c -------------- next part -------------- Modified: branches/portfwd_memleak/ttssh2/ttxssh/fwd.c =================================================================== --- branches/portfwd_memleak/ttssh2/ttxssh/fwd.c 2019-06-05 14:16:02 UTC (rev 7731) +++ branches/portfwd_memleak/ttssh2/ttxssh/fwd.c 2019-06-05 15:00:47 UTC (rev 7732) @@ -740,6 +740,48 @@ } } +// local connection\x82\xA9\x82\xE7\x82̃p\x83P\x83b\x83g\x83\x8A\x81[\x83h(FD_READ)\x82̒ʒm\x82\xF0\x90\xE8\x91ւ\xA6\x82\xE9 +// +// notify: TRUE FD_READ\x82\xF0\x92ʒm\x82\xB7\x82\xE9 +// FALSE FD_READ\x82\xF0\x92ʒm\x82\xB5\x82Ȃ\xA2 +// +// remote_window\x82ɋ\xAA\x82Ȃ\xA2\x8Fꍇ\x82͒ʒm\x83I\x83t\x82Ƃ\xB5\x81A\x8B\xAA\x82ł\xAB\x82\xBD\x8Fꍇ\x82\xCD +// \x92ʒm\x82\xF0\x8DĊJ\x82\xB7\x82\xE9\x81B +// +// remote_window\x82ɗ]\x97T\x82\xAA\x82Ȃ\xA2\x8F\xF3\x91ԂŁAlocal connection\x82\xA9\x82\xE7\x82̃p\x83P\x83b\x83g\x82\xF0 +// \x8E\xF3\x90M\x82\xB5\x91\xB1\x82\xAF\x82\xE9\x82ƁA\x8F\xC1\x94\x83\x82\x83\x8A\x82\xAA\x94\xEC\x91剻\x82\xB7\x82\xE9\x82Ƃ\xA2\x82\xA4\x96\xE2\x91\xE8\x82\xF0\x89\xF1\x94\xF0\x82\xB7\x82\xE9\x81B +// +// (2019.6.5 yutaka) +void FWD_suspend_resume_local_connection(PTInstVar pvar, Channel_t* c, int notify) +{ + int channel_num; + FWDChannel* channel; + int ret; + + channel_num = c->local_num; + channel = pvar->fwd_state.channels + channel_num; + + if (notify) { + ret = WSAAsyncSelect( + channel->local_socket, + make_accept_wnd(pvar), WM_SOCK_IO, + FD_CONNECT | FD_READ | FD_CLOSE | FD_WRITE + ); + } else { + ret = WSAAsyncSelect( + channel->local_socket, + make_accept_wnd(pvar), + 0, 0); + } + + if (ret != 0) { + logprintf(LOG_LEVEL_ERROR, "%s: Can not change local channel(%d) notification(%d)", + __FUNCTION__, channel_num, notify); + } + +} + + static LRESULT CALLBACK accept_wnd_proc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) { Modified: branches/portfwd_memleak/ttssh2/ttxssh/fwd.h =================================================================== --- branches/portfwd_memleak/ttssh2/ttxssh/fwd.h 2019-06-05 14:16:02 UTC (rev 7731) +++ branches/portfwd_memleak/ttssh2/ttxssh/fwd.h 2019-06-05 15:00:47 UTC (rev 7732) @@ -164,5 +164,6 @@ 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); +void FWD_suspend_resume_local_connection(PTInstVar pvar, Channel_t* c, int notify); #endif Modified: branches/portfwd_memleak/ttssh2/ttxssh/ssh.c =================================================================== --- branches/portfwd_memleak/ttssh2/ttxssh/ssh.c 2019-06-05 14:16:02 UTC (rev 7731) +++ branches/portfwd_memleak/ttssh2/ttxssh/ssh.c 2019-06-05 15:00:47 UTC (rev 7732) @@ -231,7 +231,7 @@ } // remote_window\x82̋\xAA\x82Ȃ\xA2\x8Fꍇ\x82ɁA\x91\x97\x82\xEA\x82Ȃ\xA9\x82\xC1\x82\xBD\x83o\x83b\x83t\x83@\x82\xF0\x83\x8A\x83X\x83g\x81i\x93\xFC\x97͏\x87\x81j\x82ւȂ\xA2\x82ł\xA8\x82\xAD\x81B -static void ssh2_channel_add_bufchain(Channel_t *c, unsigned char *buf, unsigned int buflen) +static void ssh2_channel_add_bufchain(PTInstVar pvar, Channel_t *c, unsigned char *buf, unsigned int buflen) { bufchain_t *p, *old; @@ -255,6 +255,8 @@ old = old->next; old->next = p; } + + FWD_suspend_resume_local_connection(pvar, c, FALSE); } static void ssh2_channel_retry_send_bufchain(PTInstVar pvar, Channel_t *c) @@ -261,6 +263,7 @@ { bufchain_t *ch; unsigned int size; + int count = 0; while (c->bufchain) { // \x90擪\x82\xA9\x82\xE7\x90\xE6\x82ɑ\x97\x82\xE9 @@ -279,7 +282,13 @@ buffer_free(ch->msg); free(ch); + + count++; } + + if (count > 0) { + FWD_suspend_resume_local_connection(pvar, c, TRUE); + } } // channel close\x8E\x9E\x82Ƀ`\x83\x83\x83l\x83\x8B\x8D\\x91\xA2\x91̂\xF0\x83\x8A\x83X\x83g\x82֕ԋp\x82\xB7\x82\xE9 @@ -3441,7 +3450,7 @@ // \x82\xB1\x82\xEA\x82ɂ\xE6\x82\xE8\x83p\x83P\x83b\x83g\x82\xAA\x89\xF3\x82ꂽ\x82悤\x82Ɍ\xA9\x82\xA6\x82錻\x8Fۂ\xAA\x89\xFC\x91P\x82\xB3\x82\xEA\x82\xE9\x81B // (2012.10.14 yutaka) if (retry == 0 && c->bufchain) { - ssh2_channel_add_bufchain(c, buf, buflen); + ssh2_channel_add_bufchain(pvar, c, buf, buflen); return; } @@ -3448,7 +3457,7 @@ if ((unsigned int)buflen > c->remote_window) { unsigned int offset = 0; // \x91\x97\x82\xEA\x82Ȃ\xA2\x83f\x81[\x83^\x82͂\xA2\x82\xC1\x82\xBD\x82\xF1\x95ۑ\xB6\x82\xB5\x82Ă\xA8\x82\xAD - ssh2_channel_add_bufchain(c, buf + offset, buflen - offset); + ssh2_channel_add_bufchain(pvar, c, buf + offset, buflen - offset); buflen = offset; return; }