[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Incremental search



Hi,

On Sat, Dec 16, 2017 at 10:57:08PM +0100, Marcin Szewczyk wrote:
> On Sun, Dec 17, 2017 at 12:09:32AM +0300, Azat Khuzhin wrote:
> > (and evbuffer_ptr_set()+evbuffer_search_range() is not compatible with
> > evbuffer_pullup() and any other API that playing with chains)
> 
> I've tried to take the invalidation of evbuffer_ptrs into account.
> 
> > > } else {
> > >     // a hit
> > >
> > >     incr_ptr.pos = -1;
> > 
> > So here you don't remove that part of the buffer (the one from the
> > beginning to the delimiter), yes?
> 
> Actually I do. Currently it looks like that:
> #v+
>     } else {
>         // a hit
> 
>         ctx->incr_ptr.pos = -1;
> 
>         cptr = malloc (tmp_ptr.pos + 1);
>         evbuffer_remove (ctx->evbuff_in, cptr, tmp_ptr.pos);
>         evbuffer_drain (ctx->evbuff_in, 1);
>         cptr[tmp_ptr.pos] = '\0';
>         printf("data: %s\n", cptr);
>         free (cptr);
>     }
> #v-
> 
> In my previous email I left only the line marking the evbuffer_ptr as
> invalid to force recalculation in the next iteration:
> 
>     ctx->incr_ptr.pos != -1 ? &ctx->incr_ptr : NULL

Just to be sure -- is the above solution correct or did I miss something
(about evbuffer_ptr invalidation for example)?

-- 
Marcin Szewczyk
http://wodny.org
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.