tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

iovec member reuse


Query: is it safe to re-use an iovec array without re-initialising it?

What I mean is in the following scenario:

        struct {
                int     type;
                int     id;
                int     len;
        } hdr;

        hdr.type = xx;
        hdr.len = sizeof(body);

        iov[0].iov_base = &hdr;
        iov[0].iov_len = sizeof(hdr);

        iov[1].iov_base = body;
        iov[1].iov_len = sizeof(body);

        for ( = 0; < 5;
                writev(fd, iov, 2);

Is it ok to assume that the iovec array is not being modified inside the
writev function and that the output will be five complete packets with
increasing id fields?

It certainly seems to be the case on NetBSD and the manpage says nothing
about it (nor does opengroup specification page) and I'm thinking that
principle of least surprise should apply, in that where no side effects
are mentioned, there should be none..


Home | Main Index | Thread Index | Old Index