previous | start

Thread Version

void incoming(int r_in, int l_out)
{
    int eof = 0;
    char buf[BSIZE];
    int size;

    while(!eof) {
      size = read(r_in, buf, BSIZE);
      if (size <= 0) 
        eof = 1;
      if (write(l_out, buf, size) <= 0)
        eof = 1;
    }
}

void outgoing(int l_in, int r_out)
{
    int eof = 0;
    char buf[BSIZE];
    int size;

    while(!eof) {
      size = read(l_in, buf, BSIZE);
      if (size <= 0) 
        eof = 1;
      if (write(r_out, buf, size) <= 0)
        eof = 1;
    }
}


previous | start