On Mon, Jul 1, 2013 at 10:40 AM, Ivan Zhakov <
iv...@visualsvn.com> wrote:
> Hi,
>
> It already discussed that would be useful to add optional vtable
> method to buckets to return length of available in bucket. It seems to
> be easy to implement without breaking compatibility. See attached
> patch.
>
> Comments? Objections?
Let's say that we add this in serf 1.4. And say an app using serf's
1.0 API has some custom bucket types. serf would have no idea that the
(new) vtable entry is not present. (note that I'm assuming serf will
start to use get_remaining internally; thus, we can't say "no crashes
cuz old apps won't use the new vtable entry").
We need a way to tell serf the bucket API version in use.
Here is a total hack on how to do that:
Note that read_bucket() is not called by anybody today, afaik, so we
will slow it down a tiny bit and use it for versioning:
serf_bucket_t * serf_buckets_are_v2(
serf_bucket_t *bucket,
const serf_bucket_type_t *type)
{
return bucket->read_bucket_v2(bucket, type);
}
apr_uint64_t serf_bucket_get_remaining(serf_bucket_t *bucket)
{
if (bucket->read_bucket == serf_buckets_are_v2
&& bucket->get_remaining != NULL)
return bucket->get_remaining(bucket);
return SERF_LENGTH_UNKNOWN;
}
So: we'd add two new vtable entry points: get_remaining and
read_bucket_v2. Implementors would set their read_bucket entrypoint to
serf_buckets_are_v2 to indicate they've switched over to the new API.
If we add more vtable entries, then we just add serf_buckets_are_v3 / _v4 / etc.
Total hack. I know. But it should work in a compatible fashion.
Thoughts?
Cheers,
-g