Re: Using a GCD Client ( was Re: Trouble getting SSD Project working & Questions )
Re: Using a GCD Client ( was Re: Trouble getting SSD Project working & Questions )
- Subject: Re: Using a GCD Client ( was Re: Trouble getting SSD Project working & Questions )
- From: Eric Gorr <email@hidden>
- Date: Thu, 28 Jul 2011 07:57:12 -0400
On Jul 28, 2011, at 7:01 AM, Quinn The Eskimo! wrote:
>
> On 28 Jul 2011, at 03:43, email@hidden wrote:
>
>> The problem is that the client continues to receive read events. However, there are no bytes to read associated with the event.
>
> Are you saying that your read event handler gets called but then calls read() and gets a function result of 0? If so, that's standard BSD Sockets speak for EOF, and you should treat it accordingly. If not, what exactly is read() returning?
Yes, it is returning 0.
To treat is accordingly, means what in this case? There is clearly something I am missing.
My original idea for how to write the client code was as follows:
1. Use the 'connect' function to make a connection with the server
2. Setup a DISPATCH_SOURCE_TYPE_READ handler to read data coming back from the server
3. Use a new DISPATCH_SOURCE_TYPE_WRITE handler to send data to the server each time I needed to send a message
4. On program exit, dispatch_release the DISPATCH_SOURCE_TYPE_READ handler.
On program exit, I don't believe there is anything I need to call to balance the call to 'connect'...i.e. there is no 'disconnect' function.
The situation is slightly more complex because when I receive an event inside of the DISPATCH_SOURCE_TYPE_READ handler in step #2 (let's call it the READ A handler), I setup another DISPATCH_SOURCE_TYPE_READ handler (call it READ B). I noticed this is what the SSD sample code is doing and I am not sure I fully understand why it needs two read handlers to read the data. I followed the same basic pattern in the client code. When I receive an event on READ A, I setup READ B to read the data coming in. Once the data has been read, dispatch_release READ B. But, perhaps, what is going wrong is that I am dispatch_release'ing READ B a bit to early. I should wait until I receive an EOF in the client before doing so....something which appears to be unnecessary in the server code. Is this correct?
_______________________________________________
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