[Ttssh2-commit] [4857]

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2012年 3月 9日 (金) 00:50:27 JST


Revision: 4857
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=4857
Author:   yutakapon
Date:     2012-03-09 00:50:26 +0900 (Fri, 09 Mar 2012)
Log Message:
-----------

名前付きパイプをサポートした。
VMware Player 3.1.5 + Fedora 16 で動作確認済み。

* 未サポート
  - 接続ダイアログからの設定
  - ブレーク送信
  - 他

* コマンドライン
  書式 /NAMEDPIPE 名前付きパイプ名
  例   /NAMEDPIPE \\.\pipe\vmware-serial-port

* teraterm.ini
  Port=namedpipe 追加

Modified Paths:
--------------
    trunk/installer/release/TERATERM.INI
    trunk/teraterm/common/tttypes.h
    trunk/teraterm/teraterm/commlib.c
    trunk/teraterm/teraterm/ttwinman.c
    trunk/teraterm/ttpset/ttset.c

-------------- next part --------------
Modified: trunk/installer/release/TERATERM.INI
===================================================================
--- trunk/installer/release/TERATERM.INI	2012-03-08 13:12:30 UTC (rev 4856)
+++ trunk/installer/release/TERATERM.INI	2012-03-08 15:50:26 UTC (rev 4857)
@@ -116,7 +116,7 @@
 ; Background color of text uses background color of screen (on/off)
 UseNormalBGColor=on
 
-;	Port type (serial/tcpip)
+;	Port type (serial/tcpip/namedpipe)
 Port=tcpip
 
 ;	Window positions

Modified: trunk/teraterm/common/tttypes.h
===================================================================
--- trunk/teraterm/common/tttypes.h	2012-03-08 13:12:30 UTC (rev 4856)
+++ trunk/teraterm/common/tttypes.h	2012-03-08 15:50:26 UTC (rev 4857)
@@ -158,6 +158,7 @@
 #define IdTCPIP  1
 #define IdSerial 2
 #define IdFile   3
+#define IdNamedPipe   4
 
   /* XMODEM option */
 #define XoptCheck 1

Modified: trunk/teraterm/teraterm/commlib.c
===================================================================
--- trunk/teraterm/teraterm/commlib.c	2012-03-08 13:12:30 UTC (rev 4856)
+++ trunk/teraterm/teraterm/commlib.c	2012-03-08 15:50:26 UTC (rev 4857)
@@ -234,8 +234,8 @@
 #ifdef NO_INET6
 	int Err;
 #endif /* NO_INET6 */
-	char ErrMsg[21];
-	char P[50];
+	char ErrMsg[21+256];
+	char P[50+256];
 
 	MSG Msg;
 #ifndef NO_INET6
@@ -550,6 +550,33 @@
 				PostMessage(cv->HWin, WM_USER_COMMOPEN, 0, 0);
 			}
 			break;
+
+		case IdNamedPipe:
+			InitFileIO(IdNamedPipe);  /* TTPLUG */
+			TTXOpenFile(); /* TTPLUG */
+			strncpy_s(P, sizeof(P), ts->HostName, _TRUNCATE);
+			cv->ComID =
+			PCreateFile(P,GENERIC_READ | GENERIC_WRITE,
+			            0,NULL,OPEN_EXISTING,
+			            0,  // \x83u\x83\x8D\x83b\x83L\x83\x93\x83O\x83\x82\x81[\x83h\x82ɂ\xB7\x82\xE9(FILE_FLAG_OVERLAPPED \x82͎w\x92肵\x82Ȃ\xA2)
+						NULL);
+			if (cv->ComID == INVALID_HANDLE_VALUE ) {
+				get_lang_msg("MSG_CANTOEPN_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Cannot open %s(%d)", ts->UILanguageFile);
+				_snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, ts->UIMsg, &P[0], GetLastError());
+
+				if (cv->NoMsg==0) {
+					get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
+					MessageBox(cv->HWin,ErrMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
+				}
+				InvalidHost = TRUE;
+			}
+			else {
+				cv->Open = TRUE;
+				PostMessage(cv->HWin, WM_USER_COMMOPEN, 0, 0);
+				InvalidHost = FALSE;
+			}
+			break; /* end of "case IdNamedPipe:" */
+
 	} /* end of "switch" */
 
 #ifndef NO_INET6
@@ -568,6 +595,45 @@
 	}
 }
 
+// \x96\xBC\x91O\x95t\x82\xAB\x83p\x83C\x83v\x97p\x83X\x83\x8C\x83b\x83h
+void NamedPipeThread(void *arg)
+{
+	PComVar cv = (PComVar)arg;
+	DWORD DErr;
+	HANDLE REnd;
+	char Temp[20];
+	char Buffer[1];  // 1byte
+	DWORD BytesRead, TotalBytesAvail, BytesLeftThisMessage;
+
+	_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", READENDNAME, cv->ComPort);
+	REnd = OpenEvent(EVENT_ALL_ACCESS,FALSE, Temp);
+	while (TRUE) {
+		BytesRead = 0;
+		// \x96\xBC\x91O\x95t\x82\xAB\x83p\x83C\x83v\x82̓C\x83x\x83\x93\x83g\x82\xF0\x91҂‚\xB1\x82Ƃ\xAA\x82ł\xAB\x82Ȃ\xA2\x8Ed\x97l\x82Ȃ̂ŁA\x83L\x83\x85\x81[\x82̒\x86\x90g\x82\xF0
+		// \x94`\x82\xAB\x8C\xA9\x82\xB7\x82邱\x82ƂŁAReadFile() \x82\xB7\x82邩\x82ǂ\xA4\x82\xA9\x94\xBB\x92f\x82\xB7\x82\xE9\x81B
+		if (PeekNamedPipe(cv->ComID, Buffer, sizeof(Buffer), &BytesRead, &TotalBytesAvail, &BytesLeftThisMessage)) {
+			if (! cv->Ready) {
+				_endthread();
+			}
+			if (BytesRead == 0) {  // \x8B󂾂\xC1\x82\xBD\x82\xE7\x81A\x89\xBD\x82\xE0\x82\xB5\x82Ȃ\xA2\x81B
+				Sleep(1);
+				continue;
+			}
+			if (! cv->RRQ) {
+				PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_READ);
+			}
+			// ReadFile() \x82\xAA\x8FI\x82\xED\x82\xE9\x82܂ő҂B
+			WaitForSingleObject(REnd,INFINITE);
+		}
+		else {
+			DErr = GetLastError();  // this returns 995 (operation aborted) if a USB com port is removed
+			if (! cv->Ready || ERROR_OPERATION_ABORTED == DErr) {
+				_endthread();
+			}
+		}
+	}
+}
+
 void CommThread(void *arg)
 {
 	DWORD Evt;
@@ -703,6 +769,25 @@
 		case IdFile:
 			cv->RRQ = TRUE;
 			break;
+
+		case IdNamedPipe:
+			cv->ComPort = 0;
+			_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", READENDNAME, cv->ComPort);
+			ReadEnd = CreateEvent(NULL,FALSE,FALSE,Temp);
+			_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", WRITENAME, cv->ComPort);
+			memset(&wol,0,sizeof(OVERLAPPED));
+			wol.hEvent = CreateEvent(NULL,TRUE,TRUE,Temp);
+			_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", READNAME, cv->ComPort);
+			memset(&rol,0,sizeof(OVERLAPPED));
+			rol.hEvent = CreateEvent(NULL,TRUE,FALSE,Temp);
+
+			/* create the receiver thread */
+			if (_beginthread(NamedPipeThread,0,cv) == -1) {
+				get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
+				get_lang_msg("MSG_TT_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Can't create thread", ts->UILanguageFile);
+				MessageBox(cv->HWin,ts->UIMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
+			}
+			break;
 	}
 	cv->Ready = TRUE;
 }
@@ -782,6 +867,16 @@
 			}
 			TTXCloseFile(); /* TTPLUG */
 			break;
+
+		case IdNamedPipe:
+			if ( cv->ComID != INVALID_HANDLE_VALUE ) {
+				CloseHandle(ReadEnd);
+				CloseHandle(wol.hEvent);
+				CloseHandle(rol.hEvent);
+				PCloseFile(cv->ComID);
+			}
+			TTXCloseFile(); /* TTPLUG */
+			break;
 	}
 	cv->ComID = INVALID_HANDLE_VALUE;
 	cv->PortType = 0;
@@ -870,6 +965,29 @@
 					DErr = GetLastError();
 				}
 				break;
+
+			case IdNamedPipe:
+				// \x83L\x83\x85\x81[\x82̒\x86\x82ɍŒ\xE11\x83o\x83C\x83g\x88ȏ\xE3\x82̃f\x81[\x83^\x82\xAA\x93\xFC\x82\xC1\x82Ă\xA2\x82邱\x82Ƃ\xF0\x8Am\x94F\x82ł\xAB\x82Ă\xA2\x82邽\x82߁A
+				// ReadFile() \x82̓u\x83\x8D\x83b\x83N\x82\xB7\x82邱\x82Ƃ͂Ȃ\xA2\x82\xBD\x82߁A\x88ꊇ\x82\xB5\x82ēǂށB
+				if (PReadFile(cv->ComID,&(cv->InBuff[cv->InBuffCount]),
+				              InBuffSize-cv->InBuffCount,&C,NULL)) {
+					if (C == 0) {
+						DErr = ERROR_HANDLE_EOF;
+					}
+					else {
+						cv->InBuffCount = cv->InBuffCount + C;
+					}
+				}
+				else {
+					DErr = GetLastError();
+				}
+
+				// 1\x83o\x83C\x83g\x88ȏ\xE3\x93ǂ߂\xBD\x82\xE7\x81A\x83C\x83x\x83\x93\x83g\x82\xF0\x8BN\x82\xB1\x82\xB5\x81A\x83X\x83\x8C\x83b\x83h\x82\xF0\x8DĊJ\x82\xB3\x82\xB9\x82\xE9\x81B
+				if (cv->InBuffCount > 0) {
+					cv->RRQ = FALSE;
+					SetEvent(ReadEnd);
+				}
+				break;
 		}
 	}
 
@@ -894,6 +1012,17 @@
 					cv->RRQ = TRUE;
 				}
 				return;
+			case IdNamedPipe:
+				// TODO: \x82\xBD\x82Ԃ\xF1\x81A\x82\xB1\x82\xB1\x82ɗ\x88\x82邱\x82Ƃ͂Ȃ\xA2\x81B
+				if (DErr != ERROR_IO_PENDING) {
+					PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
+					cv->RRQ = FALSE;
+				}
+				else {
+					cv->RRQ = TRUE;
+				}
+				SetEvent(ReadEnd);
+				return;
 		}
 		cv->RRQ = FALSE;
 	}
@@ -931,6 +1060,9 @@
 		case IdFile:
 			Max = cv->OutBuffCount;
 			break;
+		case IdNamedPipe:
+			Max = cv->OutBuffCount;
+			break;
 	}
 
 	if ( Max<=0 ) {
@@ -1008,6 +1140,14 @@
 				}
 			}
 			break;
+
+		case IdNamedPipe:
+			if (! PWriteFile(cv->ComID, &(cv->OutBuff[cv->OutPtr]), C, (LPDWORD)&D, NULL)) {
+				if (! GetLastError() == ERROR_IO_PENDING) {
+					D = C; /* ignore data */
+				}
+			}
+			break;
 	}
 
 	cv->OutBuffCount = cv->OutBuffCount - D;

Modified: trunk/teraterm/teraterm/ttwinman.c
===================================================================
--- trunk/teraterm/teraterm/ttwinman.c	2012-03-08 13:12:30 UTC (rev 4856)
+++ trunk/teraterm/teraterm/ttwinman.c	2012-03-08 15:50:26 UTC (rev 4857)
@@ -183,6 +183,19 @@
 				strncat_s(TempTitle, sizeof(TempTitle), str, _TRUNCATE); 
 			}
 		}
+		else if (cv.PortType == IdNamedPipe)
+		{
+			char str[sizeof(TempTitle)];
+			strncpy_s(str, sizeof(str), ts.HostName, _TRUNCATE);
+
+			if (ts.TitleFormat & 8) {
+				// format ID = 13(8 + 5): <hots/port> - <title>
+				_snprintf_s(TempTitle, sizeof(TempTitle), _TRUNCATE, "%s - %s", str, TempTitleWithRemote);
+			}
+			else {
+				strncat_s(TempTitle, sizeof(TempTitle), str, _TRUNCATE);
+			}
+		}
 		else {
 			char str[sizeof(TempTitle)];
 			if (ts.TitleFormat & 16) {

Modified: trunk/teraterm/ttpset/ttset.c
===================================================================
--- trunk/teraterm/ttpset/ttset.c	2012-03-08 13:12:30 UTC (rev 4856)
+++ trunk/teraterm/ttpset/ttset.c	2012-03-08 15:50:26 UTC (rev 4857)
@@ -258,6 +258,8 @@
 		ts->PortType = IdTCPIP;
 	else if (_stricmp(Temp, "serial") == 0)
 		ts->PortType = IdSerial;
+	else if (_stricmp(Temp, "namedpipe") == 0)
+		ts->PortType = IdNamedPipe;
 	else {
 		ts->PortType = IdTCPIP;
 	}
@@ -1508,6 +1510,8 @@
 	/* Port type */
 	if (ts->PortType == IdSerial)
 		strncpy_s(Temp, sizeof(Temp), "serial", _TRUNCATE);
+	if (ts->PortType == IdNamedPipe)
+		strncpy_s(Temp, sizeof(Temp), "namedpipe", _TRUNCATE);
 	else						/* IdFile -> IdTCPIP */
 		strncpy_s(Temp, sizeof(Temp), "tcpip", _TRUNCATE);
 
@@ -3192,7 +3196,10 @@
 			HostNameFlag = FALSE;
 		}
 
-		if (_strnicmp(Temp, "/BAUD=", 6) == 0) {	/* Serial port baud rate */
+		if (_strnicmp(Temp, "/NAMEDPIPE", 10) == 0) {	/* \x96\xBC\x91O\x95t\x82\xAB\x83p\x83C\x83v */
+			ParamPort = IdNamedPipe;
+		}
+		else if (_strnicmp(Temp, "/BAUD=", 6) == 0) {	/* Serial port baud rate */
 			ParamPort = IdSerial;
 			ParamBaud = atoi(&Temp[6]);
 		}
@@ -3368,9 +3375,14 @@
 			if (JustAfterHost && (sscanf(Temp, "%d", &c) == 1))
 				ParamTCP = c;
 			else {
-				ParamPort = IdTCPIP;
 				strncpy_s(ts->HostName, sizeof(ts->HostName), Temp, _TRUNCATE);	/* host name */
-				HostNameFlag = TRUE;
+				if (ParamPort == IdNamedPipe) {
+					// \x89\xBD\x82\xE0\x82\xB5\x82Ȃ\xA2\x81B
+
+				} else {
+					ParamPort = IdTCPIP;
+					HostNameFlag = TRUE;
+				}
 			}
 		}
 		JustAfterHost = FALSE;
@@ -3435,6 +3447,11 @@
 		break;
 	case IdFile:
 		ts->PortType = IdFile;
+		break;
+	case IdNamedPipe:
+		ts->PortType = IdNamedPipe;
+		ts->ComPort = 0;
+		break;
 	}
 }
 



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