1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 3*0Sstevel@tonic-gate * Use is subject to license terms. 4*0Sstevel@tonic-gate */ 5*0Sstevel@tonic-gate 6*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gate #include <stdio.h> 9*0Sstevel@tonic-gate #include <unistd.h> 10*0Sstevel@tonic-gate #include "proxy-io.h" 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate int 13*0Sstevel@tonic-gate proxy_read_write_loop(int readfd, int writefd) 14*0Sstevel@tonic-gate { 15*0Sstevel@tonic-gate int rbytes, bytes_to_write, bytes_written; 16*0Sstevel@tonic-gate char readbuf[BUFFER_SIZ]; 17*0Sstevel@tonic-gate char *ptr; 18*0Sstevel@tonic-gate 19*0Sstevel@tonic-gate rbytes = read(readfd, readbuf, sizeof (readbuf)); 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gate if (rbytes > 0) { 22*0Sstevel@tonic-gate bytes_to_write = rbytes; 23*0Sstevel@tonic-gate ptr = readbuf; 24*0Sstevel@tonic-gate while (bytes_to_write > 0) { 25*0Sstevel@tonic-gate if ((bytes_written = 26*0Sstevel@tonic-gate write(writefd, ptr, bytes_to_write)) < 0) { 27*0Sstevel@tonic-gate perror("write"); 28*0Sstevel@tonic-gate return (0); 29*0Sstevel@tonic-gate } 30*0Sstevel@tonic-gate bytes_to_write -= bytes_written; 31*0Sstevel@tonic-gate ptr += bytes_written; 32*0Sstevel@tonic-gate } 33*0Sstevel@tonic-gate } else if (rbytes <= 0) { 34*0Sstevel@tonic-gate return (0); 35*0Sstevel@tonic-gate } 36*0Sstevel@tonic-gate /* Read and write successful */ 37*0Sstevel@tonic-gate return (1); 38*0Sstevel@tonic-gate } 39