I can't simply make my WriteProc loop internally until it is done
because my output is the IR library which uses a callback to let 
me know when I can write the next chunk.  My plan was to have a flag
set to DoNotWrite after calling IrDataReq to send the data and clear
the flag in the callback when I was notified it is ok to send the
next bit.  I check the flag at the start of WriteProc and exit the 
function returning 0 if it is set to DoNotWrite thinking I'll get
called later to send the same data.  Just to make things 
really hairy I have to call IrHandleEvent in WriteProc 
to give the IR library some time to run due to it being in the 
user task (unlike the NetLib).

It would seem to me that this bug in combination with a non-blocking
write mechanism like the IR library uses makes this a difficult problem
to solve.  Any ideas?

thx...Adrian.

Danny Epstein wrote:
> 
> I'd say you found a bug. The value passed back from the WriteProc in *sizeP
> is ignored. Actually, it's accumulated and then thrown out. If the WriteProc
> doesn't write all the data it was asked to, it won't be called again to
> write the rest.
> 
> The documentation for ExgDBWrite says "ExgDBWrite stops calling the write
> callback function after 0 is returned in sizeP." This isn't true either. I
> think the intent was to say that it stops calling the callback when it's
> written all the data. Or perhaps it's a cut-n-paste error from ExgDBRead.
> What I'm wondering is whether returning 0 in *sizeP should be allowed. I
> suppose it could be useful occasionally, but it could produce an infinite
> loop if the WriteProc returns 0 by mistake. I'd be interested in your
> thoughts on this.
> 
> Given this bug, my advice is to make your WriteProc loop internally if
> necessary to write all the data that was passed to it. It should then return
> that it has written all the data, even though this is ignored, to be
> compatible with a future version of ExgDBWrite that works properly.
> 
> I'll file a bug for this suggesting that we change WriteData (called by
> ExgDBWrite) to call the WriteProc repeatedly until all the data has been
> written, and that we update the docs for ExgDBWrite to say that the
> WriteProc only gets one chance to write all the data in certain versions of
> Palm OS.
> 
> Thanks for the bug report. :)
> --
> Danny @ Palm
> 
> "Adrian Pfisterer" <[EMAIL PROTECTED]> wrote in message
> news:54276@palm-dev-forum...
> > The way the ExgDBWrite function works is that it takes a function
> > pointer (WriteProc) as one of its arguments and the OS repeatedly calls
> > that function with a pointer to some database information that the
> > WriteProc function should write to the output of its choice.  The OS also
> > passes in a number of bytes to write and expects the function
> > doing the writing to update it with the number of bytes written.
> > The theory is if it can't write all the bytes it will return
> > what it was able to write and the next time it will be called
> > with the pointer updated to the correct next bytes to be
> > written.  As Danny Epstein wrote earlier:
> >
> > "The amount of data being written is determined by a collaboration of
> > ExgDBWrite and your WriteProc. ExgDBWrite is asking your WriteProc to
> write
> > out some number of bytes, but you don't have to write them all. If you
> write
> > fewer bytes, you must set *sizeP to the number of bytes actually written.
> In
> > this case, it will have to call your WriteProc again to write the rest.
> Even
> > if your WriteProc always writes all the data given to it, it'll still get
> > called multiple times. ExgDBWrite will call your WriteProc for each
> > record/resource, among other things."
> >
> >
> > Now, if I use the following function as the WriteProc I would expect
> > that it would continually get called with the same parameters:
> >
> > Err WriteProc( const void *dataP, UInt32 *sizeDataP, void *userDataP )
> > {
> >     PrintLog( "OS asking to send %ld bytes", *sizeDataP );
> >     *sizeDataP = 0;
> >     return 0;
> > }
> >
> >
> > The output from this is:
> >
> > OS asking to send 72 bytes
> > OS asking to send 6 bytes
> > OS asking to send 8 bytes
> > OS asking to send 8 bytes
> > OS asking to send 2 bytes
> > OS asking to send 18 bytes
> > OS asking to send 1166 bytes
> >
> > This tells me it is ignoring whatever I set *sizeDataP to and looking
> > at the source for ExgDBWrite in ExgDB.c would support this.
> >
> > What's going on with ExgDBWrite?  Has it ever been tested with a
> > WriteProc that doesn't write all the bytes the first time?
> >
> > Thanks...
> >
> > Adrian Pfisterer.
> >
> >

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to