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