CFWriteStreamCallback stops being called
CFWriteStreamCallback stops being called
- Subject: CFWriteStreamCallback stops being called
- From: Liwei <email@hidden>
- Date: Wed, 30 Jul 2008 21:14:04 +0800
I've initialised a pair of read and write streams with
CFStreamCreatePairWithSocketToHost() and put both of them in my main
run-loop to respond to read and write events.
The read stream callback basically retrieves and prints out any text
it receives from the stream. It works perfectly.
The write stream callback basically checks a buffer for any pending
bytes to be written. If the event received is
kCFStreamEventCanAcceptBytes and there are bytes to be written, it
will write as much as it can using CFWriteStreamWrite(). This is what
I'm having problems with.
I've written a small for-loop to fill up the write buffer before I
start the main run-loop (I thought the main run-loop is automatically
started? I have to start it manually). When the run-loop starts, all
the data from the buffer gets written and I can see the text coming
out on the server side.
Now, I add a run-loop timer to the code that writes to the buffer (I
have implemented mutexes to prevent reading and writing to the buffer
at the same time) every 5 seconds and recompile the code again. What I
hope to see is that after the initial printout of text from the
pre-filled buffer, I will get a printout every 5 seconds due to the
timer.
The problem is, other than the few printouts that occurred when the
timer triggered when the application was still trying to empty the
initial buffer, I do not get anything printed after that, even though
the timer continues to trigger. I can see my buffer being filled up
from 0 (after the initial clearing), but it stops being cleared.
It appears that after the buffer is first emptied, the write stream
callback stops being called. I've put in debug statements at all the
points where I would explicitly remove the write stream from the
run-loop, but none of them has been triggered.
I've include statements that print out the status of the read and
write streams in my run-loop timer as well, they show that both
streams are still open.
My read and write stream callbacks check for the
kCFStreamEventErrorOccurred and kCFStreamEventEndEncountered events as
well and none of them has occurred.
So why does my callback stop getting called?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden