1 2 void rlogind(int r_in, int r_out, int l_in, int l_out) 3 { 4 fd_set in = 0, out; 5 int want_l_write = 0, want_r_write = 0; 6 int want_l_read = 1, want_r_read = 1; 7 int eof = 0, tsize, fsize, wret; 8 char fubf[BSIZE], tbuf[BSIZE]; 9 10 fcntl(r_in, F_SETFL, O_NONBLOCK); 11 fcntl(r_out, F_SETFL, O_NONBLOCK); 12 fcntl(l_in, F_SETFL, O_NONBLOCK); 13 fcntl(l_out, F_SETFL, O_NONBLOCK); 14 15 while(!eof) { 16 FD_ZERO(&in); 17 FD_ZERO(&out); 18 if(want_l_read) 19 FD_SET(l_in, &in); 20 if(want_r_read) 21 FD_SET(r_in, &in); 22 if(want_l_write) 23 FD_SET(l_out, &in); 24 if(want_r_write) 25 FD_SET(r_out, &in); 26 27 select(MAXFD, &in, &out, 0, 0); 28 if (FD_ISSET(l_in, &in)) { 29 if ((tsize=read(l_in, tbuf, BSIZE)) > 0 ) { 30 want_l_read = 0; 31 want_r_write = 1; 32 } else 33 eof = 1; 34 } 35 if (FD_ISSET(r_in, &in)) { 36 if ((tsize=read(l_in, tbuf, BSIZE)) > 0 ) { 37 want_r_read = 0; 38 want_l_write = 1; 39 } else 40 eof = 1; 41 } 42 ... } }