[haiku-commits] Re: haiku: hrev46860 - in src/kits: shared package/hpkg package/hpkg/v1

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 17 Feb 2014 16:41:42 +0100

On 02/17/2014 04:15 PM, Adrien Destugues wrote:
I think it would be better to revert the interface switch and rather
introduce a BDataOutput -> BDataIO adapter. This would allow using
BDataIOs with ZlibDecompressor while keeping the more concise interface.

Well, I'll schedule the whole series of related commits for reversal, then.

Sorry, I thought I had replied to this already.
I'm unsure how the wrapper can be done in a safe way, as you can't (by design) 
assume it's possible to use a BDataIO for atomic writes. What would the wrapper 
do if it can only write part of the data to the underlying BDataIO? should it 
block until the remaining part can be written? Should it return an error, and 
risk getting the following Write calls out of sync?

I don't see why the writes have to be atomic. What I'm saying is that the writes should be complete and fail otherwise. Usually, when incomplete reads or writes are possible and a certain amount of data needs to be read or written, a loop is needed, which incrementally processes the buffer, failing when it no longer makes any progress.

If BDataIO is used, such a loop should be in the ZlibDecompressor class. Otherwise (and preferably) it would be in the wrapper class.

I don't see how it's possible to handle this in a better way using a wrapper. 
It would only be masquerading incomplete writes as errors, leaving the caller 
with no idea of how much data has actually been written. While this is probably 
not a problem with the way BDataOuput is used in the package kit (it already 
worked, after all), it can cause issues when used with other types of I/Os, 
such as the DynamicBuffer currently in use in the Http code (this could go out 
of memory when trying to write, but that's recoverable, once the consumer has 
read enough data out of the buffer, the freed memory can be used again).

Huh? ATM ZlibDecompressor does not provide the number of bytes written either *and* you are masquerading incomplete writes as a success!

The wrapper class could easily provide the number of bytes actually written. That's the best place anyway, since that's where the error occurs. No need to concern unrelated classes like ZlibDecompressor with peculiarities of certain outputs. (Ideally it would be completely unaware of I/O errors and we would use exceptions, but that's another topic.)

If you really don't want BDataIO in the package kit, I'll have no choice but 
duplicate the ZlibDecompressor in the network kit and have a BDataIO version 
there.

There's no basis for this conclusion.

CU, Ingo


Other related posts: