CFStreamCreateBoundPair is writing 4kb data to stream and stream will parse the data which contains start node of xml and it doesnt contain end node

StackOverflow https://stackoverflow.com/questions/14730613

Question

CFStreamCreateBoundPair is writing 4kb data to stream and stream will parser the data which contains start node of xml and it doesnt contain end node.how to write the code and manage the code so that we are writing correct xml data to nsoutputstream.

CFStreamCreateBoundPair(NULL, (CFReadStreamRef *)&iStream, (CFWriteStreamRef *)&oStream,4096);

Was it helpful?

Solution

The bound stream pair works such that you can write in chunks into the write stream and something else can read in chunks from the read stream. You've set transferBufferSize to 4096 here. This indicates that the data will be moved from the write stream to the read stream in chunks of 4096 bytes (4K). If your source data is >4K but <8K in length, that would explain why you're only getting the first 4K of it. If, say, your data is 6K long, then the first 4K will be sent to the read stream, then the next 2K will be queued up, but my understanding is that it will sit waiting in a buffer until one of two things happen:

  1. Enough data arrives to complete a second 4K block.
  2. The write stream is closed.

So if 6K is all you're ever going to write to the write stream, then you need to close the write stream with CFWriteStreamClose(oStream); in order for the last 2K to be sent to the read stream. Otherwise, my expectation would be that it would just sit there forever.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top