[Ttssh2-commit] [3368] バッファフラッシュ処理を見直し

svnno****@sourc***** svnno****@sourc*****
2009年 4月 29日 (水) 18:08:27 JST


Revision: 3368
          http://svn.sourceforge.jp/view?root=ttssh2&view=rev&rev=3368
Author:   doda
Date:     2009-04-29 18:08:26 +0900 (Wed, 29 Apr 2009)

Log Message:
-----------
バッファフラッシュ処理を見直し
・バッファフラッシュを関数にした
・IAC処理時にフラッシュ仕切れなかったデータが多かった時の処理の誤りを修正

Modified Paths:
--------------
    trunk/TTXSamples/TTXOutputBuffering/TTXOutputBuffering.c


-------------- next part --------------
Modified: trunk/TTXSamples/TTXOutputBuffering/TTXOutputBuffering.c
===================================================================
--- trunk/TTXSamples/TTXOutputBuffering/TTXOutputBuffering.c	2009-04-29 03:12:37 UTC (rev 3367)
+++ trunk/TTXSamples/TTXOutputBuffering/TTXOutputBuffering.c	2009-04-29 09:08:26 UTC (rev 3368)
@@ -36,25 +36,39 @@
 }
 
 //
+//  flush_buffer -- ƒ‰ƒCƒ“ƒoƒbƒtƒ@‚̃tƒ‰ƒbƒVƒ…
+//	ƒtƒ‰ƒbƒVƒ…ŽdØ‚ê‚È‚©‚Á‚½ƒoƒCƒg”‚ð•Ô‚·B
+//
+int flush_buffer(SOCKET s, int flags) {
+	int i, len;
+
+	for (i=0; i<10; i++) {
+		len = pvar->origPsend(s, pvar->buff, pvar->buff_used, flags);
+		if (len < pvar->buff_used) {
+			if (len > 0) {
+				pvar->buff_used -= len;
+				memmove(pvar->buff, &(pvar->buff[len]), pvar->buff_used);
+			}
+		}
+		else {
+			pvar->buff_used = 0;
+			break;
+		}
+	}
+	len = pvar->buff_used;
+	pvar->buff_used = 0;
+	return len;
+}
+
+//
 //  TTXSend -- ƒL[“ü—͏ˆ—
 //
 static int PASCAL FAR TTXsend(SOCKET s, const char FAR *buf, int len, int flags) {
-	int i, j, wlen;
+	int i, wlen, left_len;
 
 	if (len > 0 && pvar->enable) {
 		if (pvar->cv->isSSH || pvar->cv->TelFlag) {
-			for (i=0; i<10; i++) {
-				wlen = pvar->origPsend(s, pvar->buff, pvar->buff_used, flags);
-				if (wlen < pvar->buff_used) {
-					if (wlen > 0) {
-						pvar->buff_used -= wlen;
-						memmove(pvar->buff, &(pvar->buff[wlen]), pvar->buff_used);
-					}
-				}
-				else {
-					break;
-				}
-			}
+			flush_buffer(s, flags);
 			pvar->enable = FALSE;
 			return pvar->origPsend(s, buf, len, flags);
 		}
@@ -78,23 +92,12 @@
 					pvar->buff_used = 0;
 					break;
 				case 0xff: // IAC
-					for (j=0; j<10; j++) {
-						wlen = pvar->origPsend(s, pvar->buff, pvar->buff_used, flags);
-						if (wlen < pvar->buff_used) {
-							if (wlen > 0) {
-								pvar->buff_used -= wlen;
-								memmove(pvar->buff, &(pvar->buff[wlen]), pvar->buff_used);
-							}
-						}
-						else {
-							break;
-						}
+					left_len = flush_buffer(s, flags);
+					if (i < left_len) {
+						wlen = 0;
 					}
-					if (i < pvar->buff_used) {
-						wlen = i;
-					}
 					else {
-						wlen = i - pvar->buff_used;
+						wlen = i - left_len;
 					}
 					pvar->enable = FALSE;
 					return wlen + pvar->origPsend(s, buf + wlen, len - wlen, flags);



Ttssh2-commit メーリングリストの案内