void str_cli(FILE *fp, int sockfd) { fd_set rset; char buff[MAXLINE]; fb_zero(&set); int stdineof = 0; while (true) { if (stdineof == 0) fb_set(fileno(fp), &rset); fb_set(sockfd, &rset); int maxfp = max(fileno(fp), sockfd) + 1; lx_select(maxfp, &rset, NULL, NULL, NULL); if (fb_isset(sockfd, &rset)) { if (lx_readline(sockfd, recvline, MAXLINE) == 0) lx_err_quit("str_cli: server terminated prematurely"); lx_fputs(recvline, stdout); } if (fb_isset(fileno(fp), &rest)) { if (fb_fgets(sendline, MAXLINE, fp) == NULL) return; lx_writen(sockfd, sendline, strlen(sendline)); } } }
static void draw(void) { int i; fbval_t *rbuf = malloc(scols * sizeof(rbuf[0])); for (i = srow; i < srow + srows; i++) { int cbeg = MAX(scol, pcol); int cend = MIN(scol + scols, pcol + pcols); memset(rbuf, 0, scols * sizeof(rbuf[0])); if (i >= prow && i < prow + prows && cbeg < cend) { memcpy(rbuf + cbeg - scol, pbuf + (i - prow) * pcols + cbeg - pcol, (cend - cbeg) * sizeof(rbuf[0])); } fb_set(i - srow, 0, rbuf, scols); } free(rbuf); }