Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!visdc!jiii From: jiii@visdc.UUCP (John E Van Deusen III) Newsgroups: comp.unix.wizards Subject: Re: Write calls which do partial writes Keywords: write select poll SIGIO connect Message-ID: <527@visdc.UUCP> Date: 3 May 89 18:33:21 GMT References: <103@matrix.UUCP> Reply-To: jiii@visdc.UUCP (John E Van Deusen III) Organization: VI Software Development, Boise, Idaho Lines: 29 In article <103@matrix.UUCP> neeraj@matrix.UUCP (neeraj sangal) writes: > n = write(fd, buf, len); > > As documented in write(2), n is the number of bytes written if the > call is successful; n is -1 otherwise. I have recently purchased a book called C LANGUAGE INTERFACES that is part of the Prentice Hall, AT&T series. It has a wealth of information about this sort of thing that was completely absent in the documentation that I previously used; the AT&T UNIX SYSTEM V PROGRAMMER'S REFERENCE MANUAL, also published by Prentice Hall. When writing to pipes and FIFO's there are only so many bytes that will fit at any given time (PIPE_BUF). If more than PIPE_BUF bytes are to be written, and O_NDELAY is clear, the bytes are written piecemeal until the write is satisfied. Because this process is not atomic, it is possible for other processes to interleave output. If this is a problem O_NDELAY can be set, and write(2) will return the number of bytes that could be written contiguously. If the request is for PIPE_BUF bytes or less, and O_NDELAY is clear, the process will block until the entire request can be accommodated. If O_NDELAY is set, and there is not enough room for the entire write request, zero is returned. Write requests of PIPE_BUF bytes or less are always contiguous. -- John E Van Deusen III, PO Box 9283, Boise, ID 83707, (208) 343-1865 uunet!visdc!jiii