On Thu, Jul 17, 2014 at 06:31:14PM +0200, Vincent Gross wrote: > Hi folks, > > I have to implement a buffer mechanism in a daemon I'm writing, and I am > reading various pieces of high-quality software (that all happen to be > part of openbsd source tree (yes I am lazy)) to compare how it's done. > That includes of course OpenSMTPd. > > I took a look at iobuf.c, and as I understand it when they are used to > read data you use realloc(3) to extend the size of a single char array, > but to write you chain several char arrays into an iovec. > > Why did it end up this way ? More precisely, are there any drawbacks in > using an iovec to read inbound data ?
It ended up like this because it's convenient. It is much easier for the API user to read input data from a single linear buffer. In smtpd we want to split lines on "\r\n" so we don't need to write contorted code to deal with lines potentially spanning several buffers. And since you always want to limit the amount of input data buffered it's not a big problem to have that space allocated once. The only drawback is that you sometimes (when you need more data to consume what's there) have to move pending data back to the start of the buffer (iobuf_normalize). It could indeed be avoided by using that buffer as a ring buffer fed with an iovec, but again, the user we would have to deal with non-linear data. In smtpd we would probably re-linearize that anyway for processing. Eric. -- You received this mail because you are subscribed to [email protected] To unsubscribe, send a mail to: [email protected]
