Am 24.11.2010, 06:29 Uhr, schrieb Donn Cave <donn@xxxxxxxxxxx>:
Quoth Ingo Weinhold <ingo_weinhold@xxxxxx>,On 2010-11-23 at 17:15:02 [+0100], Donn Cave <donn@xxxxxxxxxxx> wrote:...If he insists on using the IDLE feature, the client will be waiting for unsolicited I/O, like a server, so he may need wait_for_objects() in order to respond to application message events as well.That's what I was saying. :-) Often the only other event an explicit receiver thread has to react to is the termination of the connection (or application), though. Closing the socket accomplishes that without any extra provision, soa blocking recv() should do just fine in such a case.
whats happen if there are 3 bytes in the queue and I try to read 4 will recv return earlier?
anyway thanks to both of you for all the input will try it out now :-)
In an IDLE situation, you'll want to FETCH a message from your folder or something, and at that point you need to wake up that recv and end the IDLE, or at 29 minutes you need to end it anyway or risk server timeout. I suppose you could send the "DONE\r\n" response from another thread, more or less as you might have closed the socket from another thread, and then the recv will get the tagged server response.
I'm unsure about this too can I write to the same socket id (from a second thread) while a recv is blocking? or do I have to create a second socket? if yes how?, can I clone it somehow?
Note that the server may have no way to know about receipt of messages, other than to do its own polling at whatever interval the developer or site admin thinks appropriate. Mail is delivered to folders by sendmail or the like, not imapd. So for the extra trouble to support IDLE, it isn't clear you will get notified about incoming mail any sooner. Maybe it's different on other types of platforms where they don't have imapd and sendmail, like Microsoft Exchange ... but I wouldn't bet on Microsoft to get IDLE right, for some reason.
I think in this case the server should not publish that it support IDLE, anyway for such a case one can reduce the time to send the idle DONE command to renew the server connection. If I got it right the server should then send an status update too, if not you can send a NOOP command to trigger it.
Regards, Clemens