ttybuf.c
来自「支持Telnet功能的Modem通讯程序」· C语言 代码 · 共 74 行
C
74 行
#include <stdio.h> /*stderr,(perror)*/#include <unistd.h> /*(read,write)*/#include <sys/time.h> /*->ttybuf.h (timeval)*/#include "defs.h" /*->ttybuf.h (uchar,SOCKBUFR_SIZE,TTYBUFR_SIZE)*/#include "ttybuf.h" /*sockBufR,sockBufW*/#include "sock.h" /*(sockShutdown)*/#include "verbose.h" /*VERB_MISC*//* reading tty */voidttyBufRead(void){ int l; l = read(tty.rfd, ttyBufR.buf, sizeof(ttyBufR.buf)); if (l <= 0) { sockClose(); verboseOut(VERB_MISC, "Pty closed. (read() returns %d)\r\n", l); if (l < 0) verbosePerror(VERB_MISC, "read()"); exit(0); } ttyBufR.prevT = ttyBufR.newT; gettimeofday(&ttyBufR.newT, NULL); ttyBufR.ptr = ttyBufR.buf; ttyBufR.end = ttyBufR.buf + l;}/* writing tty */voidttyBufWrite(void){ int wl,l; wl = ttyBufW.ptr - ttyBufW.top; if (wl == 0) return; l = write(tty.wfd, ttyBufW.top, wl); if (l <= 0) { sockClose(); verboseOut(VERB_MISC, "Pty closed. (write() returns %d)\r\n", l); if (l < 0) verbosePerror(VERB_MISC, "write()"); exit(0); } else if (l < wl) { ttyBufW.top += l; /*return 1;*/ /* needs retry */ return; } ttyBufW.ptr = ttyBufW.top = ttyBufW.buf; ttyBufW.stop = 0; return;}voidputTty1(uchar c){ if (ttyBufW.ptr >= ttyBufW.buf + TTYBUFW_SIZE) { /* limit */ if (ttyBufW.ptr >= ttyBufW.buf + TTYBUFW_SIZE_A) { /*actual limit*/ fprintf(stderr,"\attyBufW overrun.\n"); return; } else ttyBufW.stop = 1; /* flow control */ } *ttyBufW.ptr++ = c;}voidputTtyN(const uchar *cp, int n){ for (; n > 0; n--,cp++) putTty1(*cp);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?