[haiku-development] Re: API Design: BUrlRequest and BDataIO

  • From: "Adrien Destugues" <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Wed, 10 Feb 2021 08:49:28 +0000

10 février 2021 09:35 "Niels Sascha Reedijk" <niels.reedijk@xxxxxxxxx> a écrit:

Hi all,

I have been looking at the changes that leorize proposed during their
summer of code. One of the changes [1] is to have the network
operation write directly to a buffer (with the BDataIO) interface that
is owned by the object that requested the data transfer. Since the
network operation is done in a different thread by default, it seems
to me like this is the perfect condition for a data race.

Granted, most callers would probably not touch the data before the
request is completed, but you can imagine that consumers that support
streaming may use an implementation of the BDataIO that allows both
reading and writing.

This was already identified during the GSoC project, and the proposed solution
is to use this for streaming and other similar use cases:
https://review.haiku-os.org/c/haiku/+/2966

This class not only provides locking, it also provides buffering of the
data, making sure the threads don't end up waiting for each other too much.

This approach keeps the simplicity of the main use case (no explicit locks to 
worry about
there), and allows the more complex use case without too much complexity as 
well.

-- 
Adrien.


Other related posts: