Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!bbn.com!papaya.bbn.com!rsalz From: rsalz@bbn.com (Rich Salz) Newsgroups: comp.unix.programmer Subject: Re: readv/writev Message-ID: <3643@litchi.bbn.com> Date: 25 Jun 91 21:30:10 GMT References: <1991Jun21.215941.5693@ncsu.edu> Organization: BBN Systems and Technology, Inc. Lines: 42 In <1991Jun21.215941.5693@ncsu.edu> jwb@cepmax.ncsu.edu writes: >Stevens (in Unix Network Programming) notes that read/write on a >socket may input/output fewer bytes than requested. Can I expect the >same behavior for readv/writev? If so, how might one implement >"readvn"/"writevn"? (a la Steven's readn/writen) I assume you want something like this: /* ** Handling the return value of writev is a pain. It should return ** the number of iov's it fully wrote out, and update the fields ** in all of them to contain the new startpoints. */ int bigwritev(fd, vp, vpcount) int fd; struct iovec *vp; register int vpcount; { register int i; register long left; /* Get the total bytecount. */ for (left = 0, i = vpcount; --i >= 0; ) left += vp[i].iov_len; while (vpcount) { if ((i = writev(fd, vp, vpcount)) < 0) return -1; if ((left -= i) <= 0) break; for (; i >= vp->iov_len; vp++, vpcount--) i -= vp->iov_len; vp->iov_base += i; vp->iov_len -= i; } return 0; } -- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net. Use a domain-based address or give alternate paths, or you may lose out.