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 22:40:20 -0400
On Jul 28, 2011, at 9:09 PM, Eric Gorr wrote:
> On Jul 28, 2011, at 8:39 AM, Quinn The Eskimo! wrote:
>
>> On 28 Jul 2011, at 12:57, Eric Gorr wrote:
>>
>>> To treat is accordingly, means what in this case?
>>
>> It means that the socket has returned all the data it's ever going to return. At that point you should have the full message back from the server, and you should process it. If you need to return from your event handler in order to do that, you should either suspend or cancel your event source so that it doesn't call the event handler again.
>
> Ah. I was under the impression that the read handler would only be called when there was data to read.
>
> So, since I know I will be sending and receiving multiple messages, what should another read handler be installed? After read returns 0 and I dispatch_source_cancel the read handler, is it generally the right thing to do to turn around and make another one?
>
> I've updated the sample project again and, hurrah, I've got a round trip data transfer. However, this joy didn't last long.
>
> http://ericgorr.net/pq/AF_UNIX_GCD_Client.zip
>
> In the main function, I have the following
>
> assert( client_read_replies( sfd ) );
> assert( client_send_request( sfd, req ) );
> //assert( client_send_request( sfd, req ) );
>
> What is going on here is that I
>
> 1. Install a read handler
> 2. Send a request to the server
> 3. Send another request to the server
>
> With the second request commented out, I get a nice, simple, round-trip data transfer. However, the moment I try to send two messages to the server, I do not receive any reply back even though it appears the server is sending one. Furthermore, the server enters into a very strange state which I am not sure I can explain very well. It would seem the server is still rather fragile, but I am uncertain how to fix it.
>
> One question I had with respect to the server is why does it setup two read handlers - with one inside of another?
>
> Thank you for any assistance!
After look at it some more, what appears to be going on is that the two messages sent by the client are coming in at the same time. The server does not know how to handle that situation. It expects to be able to receive and reply to just a single message at a time. I expect that once I get the code written so it can handle multiple messages I expect it to behave better. I suppose the client could be written to queue up the messages and not send the next message until a reply from the previous one has been received, but I like the idea of making the server smarter.
_______________________________________________
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