On Thu, Sep 21, 2017 at 03:20:02PM +0800, Hangbin Liu wrote:
> 
> Or maybe we can set buf_len very small first. Then it will force to realloc at
> the second time. And the code would like
> 
>       int buf_len = 16;
>       bufp = realloc(buf, buf_len);
>       /* check bufp and set msg */
> 
>       len = recvmsg(fd, msg, flag);
>       /* check len */
> 
>       buf_len = len;
>       bufp = realloc(buf, buf_len);
>       /* check bufp and set msg */
> 
>       len = recvmsg(fd, msg, flag);
>       /* check len */
> 
> What do you think?

I will have to check but IIRC it might be possible to use zero length
for the peek to only check the length which could help you to avoid both
the reallocation and copying the same data from kernel to userspace
twice.

Michal Kubecek

Reply via email to