【发布时间】:2013-07-23 07:16:46
【问题描述】:
我有一个在 Linux 操作系统上运行的 c 应用程序。此应用程序从终端获取键盘键并将它们发送到远程服务器。
下面的代码打开终端:
// save old terminal attributes
if (tcgetattr(0, &ttyold) != 0) {
fprintf(stderr, "Failed getting terminal attributes\n");
goto out;
}
ttynew = ttyold;
ttynew.c_iflag = 0;
ttynew.c_oflag = 0;
// disable canonical mode (don't buffer by line)
ttynew.c_lflag &= ~ICANON;
// disable local echo
ttynew.c_lflag &= ~ECHO;
ttynew.c_cc[VMIN] = 1;
ttynew.c_cc[VTIME] = 1;
// set new terminal attributes
if (tcsetattr(0, TCSANOW, &ttynew) != 0) {
fprintf(stderr, "Failed setting terminal attributes\n");
goto out;
我没有编写这个应用程序,我只是想理解这段代码。
我不明白为什么以前的工程师禁用了回声?必须发送的数据不是秘密。这还有什么意义?表现?禁用缓冲?
另外,我很高兴得到“ttynew.c_lflag &= ~ICANON;”的解释代码。
提前致谢。
【问题讨论】:
-
最好的办法是问他..
-
他离开了我们的开发团队....