[Ttssh2-commit] [8359] 送信/受信バッファサイズを考慮して送信するようにした

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 11月 4日 (月) 00:23:12 JST


Revision: 8359
          https://osdn.net/projects/ttssh2/scm/svn/commits/8359
Author:   zmatsuo
Date:     2019-11-04 00:23:12 +0900 (Mon, 04 Nov 2019)
Log Message:
-----------
送信/受信バッファサイズを考慮して送信するようにした

Modified Paths:
--------------
    branches/unicode_buf/teraterm/teraterm/sendmem.cpp

-------------- next part --------------
Modified: branches/unicode_buf/teraterm/teraterm/sendmem.cpp
===================================================================
--- branches/unicode_buf/teraterm/teraterm/sendmem.cpp	2019-11-03 15:23:02 UTC (rev 8358)
+++ branches/unicode_buf/teraterm/teraterm/sendmem.cpp	2019-11-03 15:23:12 UTC (rev 8359)
@@ -63,10 +63,6 @@
 	//
 	PComVar cv_;
 	BOOL pause;
-	const BYTE *send_out_retry_ptr;
-	size_t send_out_retry_len;
-	const BYTE *send_echo_retry_ptr;
-	size_t send_echo_retry_len;
 } SendMem;
 
 typedef SendMem sendmem_work_t;
@@ -146,9 +142,6 @@
 
 	p->send_left = p->send_len;
 	p->send_index = 0;
-	p->send_out_retry_ptr = NULL;
-	p->send_echo_retry_ptr = NULL;
-
 	p->waited = FALSE;
 	p->pause = FALSE;
 
@@ -172,6 +165,26 @@
 	EnableWindow(HVTWin, FALSE);
 }
 
+static void GetOutBuffInfo(const TComVar *cv_, size_t *use, size_t *free)
+{
+	if (use != NULL) {
+		*use = cv_->OutBuffCount;
+	}
+	if (free != NULL) {
+		*free = OutBuffSize - cv_->InBuffCount;
+	}
+}
+
+static void GetInBuffInfo(const TComVar *cv_, size_t *use, size_t *free)
+{
+	if (use != NULL) {
+		*use = cv_->InBuffCount;
+	}
+	if (free != NULL) {
+		*free = InBuffSize - cv_->InBuffCount;
+	}
+}
+
 /**
  * \x91\x97\x90M
  */
@@ -196,144 +209,118 @@
 		}
 	}
 
-	// \x91\x97\x90M\x83o\x83b\x83t\x83@(echo)\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD\x95\xAA\x82\xF0\x8Dđ\x97
-	int r;
-	size_t sended_size = 0;
-	if (p->send_out_retry_ptr != NULL) {
-		if (p->type == SendMemTypeBinary) {
-			r = CommBinaryBuffOut(p->cv_, (PCHAR)p->send_out_retry_ptr, (int)p->send_out_retry_len);
+	// \x8FI\x92[?
+	if (p->send_left == 0) {
+		// \x8FI\x97\xB9, \x91\x97\x90M\x83o\x83b\x83t\x83@\x82\xAA\x8B\xF3\x82ɂȂ\xE9\x82܂ő҂\xC2
+		size_t out_buff_use;
+		GetOutBuffInfo(p->cv_, &out_buff_use, NULL);
+
+		if (p->dlg != NULL) {
+			p->dlg->RefreshNum(p->send_index, p->send_len - out_buff_use);
 		}
-		else {
-			// text (not binary)
-			r = CommTextOutW(p->cv_, (wchar_t *)p->send_out_retry_ptr, (int)(p->send_out_retry_len / sizeof(wchar_t)));
-			r *= sizeof(wchar_t);
+
+		if (out_buff_use == 0) {
+			// \x91\x97\x90M\x83o\x83b\x83t\x83@\x82\xE0\x8B\xF3\x82ɂȂ\xC1\x82\xBD
+			EndPaste();
+			return;
 		}
-		sended_size = r;
-		p->send_out_retry_len -= r;
-		if (p->send_out_retry_len == 0) {
-			p->send_out_retry_ptr = NULL;
-		}
-		else {
-			p->send_out_retry_ptr += r;
-		}
 	}
-	if (p->send_echo_retry_ptr != NULL) {
-		size_t echo_size = sended_size < p->send_echo_retry_len ? sended_size : p->send_echo_retry_len;
-		if (p->type == SendMemTypeBinary) {
-			r = CommTextEcho(p->cv_, (PCHAR)p->send_echo_retry_ptr, (int)echo_size);
+
+	// \x91\x97\x90M\x82ł\xAB\x82\xE9\x83o\x83b\x83t\x83@\x83T\x83C\x83Y
+	size_t buff_len;
+	{
+		size_t out_buff_free;
+		GetOutBuffInfo(p->cv_, NULL, &out_buff_free);
+		buff_len = out_buff_free;
+		if (p->local_echo_enable) {
+			// \x83\x8D\x81[\x83J\x83\x8B\x83G\x83R\x81[\x82\xAA\x95K\x97v\x82ȏꍇ\x82́A\x93\xFC\x97̓o\x83b\x83t\x83@\x82\xE0\x8Dl\x97\xB6
+			size_t in_buff_free;
+			GetInBuffInfo(p->cv_, NULL, &in_buff_free);
+			if (buff_len > in_buff_free) {
+				buff_len = in_buff_free;
+			}
 		}
-		else {
-			r = CommTextEchoW(p->cv_, (wchar_t *)p->send_echo_retry_ptr, (int)(echo_size / sizeof(wchar_t)));
-			r *= sizeof(wchar_t);
-		}
-		p->send_echo_retry_len -= r;
-		if (p->send_echo_retry_len == 0) {
-			p->send_echo_retry_ptr = NULL;
-		}
-		else {
-			p->send_echo_retry_ptr += r;
-		}
 	}
-	if (p->send_out_retry_ptr != NULL || p->send_echo_retry_ptr != NULL) {
-		// \x82܂\xBE\x91S\x95\x94\x91\x97\x90M\x82ł\xAB\x82Ă\xA2\x82Ȃ\xA2
+	if (buff_len == 0) {
+		// \x83o\x83b\x83t\x83@\x82ɋ󂫂\xAA\x82Ȃ\xA2
 		return;
 	}
 
-	// \x91\x97\x90M
-	for (;;) {
-		// \x8FI\x92[?
-		if (p->send_left == 0) {
-			// \x8FI\x97\xB9
-			EndPaste();
-			return;
+	// \x91\x97\x90M\x92\xB7
+	BOOL need_delay = FALSE;
+	size_t send_len;
+	if (p->delay_per_char > 0) {
+		// 1\x83L\x83\x83\x83\x89\x83N\x83^\x91\x97\x90M
+		need_delay = TRUE;
+		if (p->type == SendMemTypeBinary) {
+			send_len = 1;
 		}
-
-		// \x91\x97\x90M\x92\xB7
-		BOOL need_delay = FALSE;
-		size_t send_len;
-		if (p->delay_per_char > 0) {
-			// 1\x83L\x83\x83\x83\x89\x83N\x83^\x91\x97\x90M
-			need_delay = TRUE;
-			if (p->type == SendMemTypeBinary) {
-				send_len = 1;
-			}
-			else {
-				send_len = sizeof(wchar_t);
-			}
+		else {
+			send_len = sizeof(wchar_t);
 		}
-		else if (p->delay_per_line > 0) {
-			// 1\x83\x89\x83C\x83\x93\x91\x97\x90M
-			need_delay = TRUE;
+	}
+	else if (p->delay_per_line > 0) {
+		// 1\x83\x89\x83C\x83\x93\x91\x97\x90M
+		need_delay = TRUE;
 
-			// 1\x8Ds\x8E\xE6\x82\xE8\x8Fo\x82\xB5(\x89\xFC\x8Ds\x83R\x81[\x83h\x82\xCD 0x0a \x82ɐ\xB3\x8BK\x89\xBB\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9)
-			const wchar_t *line_top = (wchar_t *)&p->send_ptr[p->send_index];
-			const wchar_t *line_end = wcschr(line_top, 0x0a);
-			if (line_end != NULL) {
-				// 0x0a \x82܂ő\x97\x90M
-				send_len = ((line_end - line_top) + 1) * sizeof(wchar_t);
-			}
-			else {
-				// \x89\xFC\x8Ds\x8C\xA9\x82‚\xA9\x82炸\x81A\x8DŌ\xE3\x82܂ő\x97\x90M
-				send_len = p->send_left;
-			}
+		// 1\x8Ds\x8E\xE6\x82\xE8\x8Fo\x82\xB5(\x89\xFC\x8Ds\x83R\x81[\x83h\x82\xCD 0x0a \x82ɐ\xB3\x8BK\x89\xBB\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9)
+		const wchar_t *line_top = (wchar_t *)&p->send_ptr[p->send_index];
+		const wchar_t *line_end = wcschr(line_top, 0x0a);
+		if (line_end != NULL) {
+			// 0x0a \x82܂ő\x97\x90M
+			send_len = ((line_end - line_top) + 1) * sizeof(wchar_t);
 		}
 		else {
-			// \x91S\x97͑\x97\x90M
+			// \x89\xFC\x8Ds\x8C\xA9\x82‚\xA9\x82炸\x81A\x8DŌ\xE3\x82܂ő\x97\x90M
 			send_len = p->send_left;
 		}
 
-		// \x91\x97\x90M\x82\xB7\x82\xE9
-		const BYTE *send_ptr = (BYTE *)&p->send_ptr[p->send_index];
-		p->send_index += send_len;
-		p->send_left -= send_len;
-		size_t sended_len;
-		if (p->type == SendMemTypeBinary) {
-			sended_len = CommBinaryBuffOut(p->cv_, (PCHAR)send_ptr, (int)send_len);
+		// \x91\x97\x90M\x82ł\xAB\x82Ȃ\xA2
+		if (buff_len < send_len) {
+			return;
 		}
-		else {
-			sended_len = CommTextOutW(p->cv_, (wchar_t *)send_ptr, (int)(send_len / sizeof(wchar_t)));
-			sended_len *= sizeof(wchar_t);
+	}
+	else {
+		// \x91S\x97͑\x97\x90M
+		send_len = p->send_left;
+		if (buff_len < send_len) {
+			send_len = buff_len;
 		}
-		if ((sended_len != 0) && (p->local_echo_enable)) {
-			// \x91\x97\x90M\x82ł\xAB\x82\xBD\x95\xAAecho\x82\xB7\x82\xE9
-			size_t echo_len = sended_len;
-			size_t echoed_len;
-			if (p->type == SendMemTypeBinary) {
-				echoed_len = CommTextEcho(p->cv_, (PCHAR)send_ptr, (int)echo_len);
-			}
-			else {
-				echoed_len = CommTextEchoW(p->cv_, (wchar_t *)send_ptr, (int)(echo_len / sizeof(wchar_t)));
-				sended_len *= sizeof(wchar_t);
-			}
-			if (echoed_len != echo_len) {
-				p->send_out_retry_ptr = send_ptr + echoed_len;
-				p->send_out_retry_len = echo_len - echoed_len;
-			}
+	}
+
+	// \x91\x97\x90M\x82\xB7\x82\xE9
+	const BYTE *send_ptr = (BYTE *)&p->send_ptr[p->send_index];
+	p->send_index += send_len;
+	p->send_left -= send_len;
+	size_t sended_len;
+	if (p->type == SendMemTypeBinary) {
+		sended_len = CommBinaryBuffOut(p->cv_, (PCHAR)send_ptr, (int)send_len);
+		if (p->local_echo_enable) {
+			CommTextEcho(p->cv_, (PCHAR)send_ptr, (int)send_len);
 		}
-		if (sended_len < send_len) {
-			// \x82\xB7\x82ׂđ\x97\x90M\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD
-			p->send_out_retry_ptr = send_ptr + sended_len;
-			p->send_out_retry_len = send_len - sended_len;
+	}
+	else {
+		sended_len = CommTextOutW(p->cv_, (wchar_t *)send_ptr, (int)(send_len / sizeof(wchar_t)));
+		if (p->local_echo_enable) {
+			CommTextEchoW(p->cv_, (wchar_t *)send_ptr, (int)(send_len / sizeof(wchar_t)));
 		}
-		if (p->send_out_retry_ptr != NULL || p->send_echo_retry_ptr != NULL) {
-			// \x8Fo\x97͂ł\xAB\x82Ȃ\xAD\x82Ȃ\xC1\x82\xBD(\x8Fo\x97̓o\x83b\x83t\x83@\x82\xAA\x82\xA2\x82\xC1\x82ς\xA2?)
-			return;
-		}
+		sended_len *= sizeof(wchar_t);
+	}
 
-		// \x83_\x83C\x83A\x83\x8D\x83O\x8DX\x90V
-		if (p->dlg != NULL) {
-			p->dlg->RefreshNum(p->send_index, p->send_len);
-		}
+	// \x83_\x83C\x83A\x83\x8D\x83O\x8DX\x90V
+	if (p->dlg != NULL) {
+		size_t out_buff_use;
+		GetOutBuffInfo(p->cv_, &out_buff_use, NULL);
+		p->dlg->RefreshNum(p->send_index - out_buff_use, p->send_len);
+	}
 
-		if (need_delay) {
-			// wait\x82ɓ\xFC\x82\xE9
-			p->waited = TRUE;
-			p->last_send_tick = GetTickCount();
-			// \x83^\x83C\x83}\x81[\x82\xCDidle\x82𓮍삳\x82\xB9\x82邽\x82߂Ɏg\x97p\x82\xB5\x82Ă\xA2\x82\xE9
-			const DWORD delay = p->delay_per_line > 0 ? p->delay_per_line : p->delay_per_char;
-			SetTimer(p->hWnd, p->timer_id, delay, NULL);
-			break;
-		}
+	if (need_delay) {
+		// wait\x82ɓ\xFC\x82\xE9
+		p->waited = TRUE;
+		p->last_send_tick = GetTickCount();
+		// \x83^\x83C\x83}\x81[\x82\xCDidle\x82𓮍삳\x82\xB9\x82邽\x82߂Ɏg\x97p\x82\xB5\x82Ă\xA2\x82\xE9
+		const DWORD delay = p->delay_per_line > 0 ? p->delay_per_line : p->delay_per_char;
+		SetTimer(p->hWnd, p->timer_id, delay, NULL);
 	}
 }
 


Ttssh2-commit メーリングリストの案内
Back to archive index