Re: eventio API

From: Alex Rousskov <rousskov@dont-contact.us>
Date: Tue, 20 Feb 2001 14:41:41 -0700 (MST)

On Wed, 21 Feb 2001, Robert Collins wrote:

> I have a small question:
> What if I want to pull the first 32K out of a 64K IOBuf, and send that
> somewhere in squid. Then I want to send a locally generated 12Kb buff,
> and then the rest of the 64Kb buffer. Do I need to memcpy the 32Kb
> buffers? Can the 12Kb be a static buffer? (marked in some fashion as not
> needing free - or is this just plain bad? )

I can answer only using the IOBufRange approach. Henrik probably has a
different, better interface in mind.

You could use IOBufRange pointing to the "first 32K out of a 64K
IOBuf" to write those 32K.

The "locally generated 12Kb buff" must be dynamically allocated or
static memory (i.e., not stack memory). The reference counters should
be smart enough to distinguish a static case from dynamically
allocated one (i.e. refcount for static memory should be set to 1 when
the static object is created so it is never freed() during normal
program execution). You will use that 12K buffer (or a "full"
IOBufRange pointing to it) for your second ncomm_write() call.

Finally, you will use another IOBufRange pointing to the "rest of
the 64Kb buffer" for the third ncom_write() call.

Putting all things together:

        ncom_write(..., IOBufRange(buf64, 0, 32K), ...);
        ncom_write(..., IOBufRange(buf12, 0, buf12.size()), ...);
        ncom_write(..., IOBufRange(buf64, 32K, buf64.size()), ...);

Where IOBufRange(buf, min, maxplusone) returns an IOBufRange structure
with the given parameters. We could even have a IOBufRest(buf, min)
call to avoid calling buf.size() all the time.

Callbacks could be called with appropriate IOBufRanges as parameters
as well.

No copying is necessary. I omitted calls to IOBufLockRead (before
ncom_write) and IOBufUnlockRead (in the callback, as appropriate).

HTH,

Alex.
Received on Tue Feb 20 2001 - 14:41:44 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:13:33 MST