Re: buffer usage

From: Laurent Bercot <ska-skaware_at_skarnet.org>
Date: Thu, 25 Aug 2016 14:59:52 +0200

  OK, now I understand what you're doing. You're declaring a buffer with
your own function (listener_read) as a reading function.

  ... Don't do that. Just declare your buffers with the standard buffer_read
function (which is an alias to fd_readsv), it will make your life a lot
easier. But I understand you did that for debugging purposes, to log
stuff; please do not try to do anything more fancy than logging and
accounting. It's very easy to get things wrong if you override the
default buffer_read.

  The reason why your read() call blocks is that you didn't set your
lfd and sfd non-blocking. You need to do that in open_listener() and
open_sender() if you're going to use lfd and sfd with nonblocking IO.
I don't know why it doesn't block when you're using readv() instead but
it's probably an accident. Don't rely on it. The skalibs ndelay_on()
function can properly set the O_NONBLOCK flag for you.

  Note that in your main loop, your usage of buffer_get() is incorrect:
it will only return the data you want if you read it all in one step,
which may not be the case (especially if you read from the network). You
need to know how many bytes you're waiting for, and use buffer_getall()
instead, which will only return 1 when you have all the data you're
expecting (which can take several loop iterations).

-- 
  Laurent
Received on Thu Aug 25 2016 - 12:59:52 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC