Subject: [Imap-uw] timeouts for client operations?

From: Andrew Biggs <[email-masked]>
Date: Wed, 14 Sep 2005 17:47:27 -0600

Hello,

I've got an IMAP client application built on imap-2004e which is 
particularly sensitive to any sort of delays or latency.  If the server 
is for some reason slow to respond to an open, or any other operation 
for that matter, are there any hooks in the c-client for setting a 
timeout (say 5 seconds, for instance)?  I can always spin off a worker 
thread and deal with this that way, I was just wondering if there was 
anything internal I could take advantage of for this.

Thanks!
Andrew
_______________________________________________
Imap-uw mailing list
[email-masked]
https://mailman1.u.washington.edu/mailman/listinfo/imap-uw

---

From: Mark Crispin <[email-masked]>
Date: Wed, 14 Sep 2005 17:05:22 -0700 (PDT)

There are various timeouts that you can set.  On UNIX, you can set TCP 
open, TCP read, and TCP write timeouts.  On Windows, you can set TCP read 
and TCP write timeouts.  This is done via the SET_OPENTIMEOUT, 
SET_READTIMEOUT, and SET_WRITETIMEOUT functions of mail_parameters().

If you fail to arm a timeout handler via SET_TIMEOUT, a timeout will cause 
an immediate disconnect.  If you arm a timeout handler, then the timeout 
handler is able to decide whether to disconnect or dismiss the timeout.

Note that "disconnect or dismiss" are your only two choices; and the only 
way that a c-client function will return is if it completes or the session 
is disconnected.  However, your timeout handler *does* have the option of 
doing other tasks, (e.g., updating the screen) prior to dismissing the 
timeout.

The point is that you can't return to the main thread from a timeout 
without abandoning the IMAP session.

-- Mark --

http://panda.com/mrc
Democracy is two wolves and a sheep deciding what to eat for lunch.
Liberty is a well-armed sheep contesting the vote.
_______________________________________________
Imap-uw mailing list
[email-masked]
https://mailman1.u.washington.edu/mailman/listinfo/imap-uw

---

From: Andrew Biggs <[email-masked]>
Date: Wed, 14 Sep 2005 20:46:59 -0600

Thanks Mark, this is exactly what I was looking for.  I gave this a go, 
but it didn't seem to take.  I went into the code and it seems like the 
SET_OPENTIMEOUT parameter isn't used by the tcp_parameters() function in 
tcp_nt.c called by mail_parameters().  Is this not supported on windows 
or have I perhaps just not used this correctly?  Here are the commands I 
issue just after calling mail_open on _mailstream:

        mail_parameters(_mailstream, SET_OPENTIMEOUT, (void *)5);
        mail_parameters(_mailstream, SET_READTIMEOUT, (void *)5);
        mail_parameters(_mailstream, SET_WRITETIMEOUT, (void *)5);

The intent is to simply have the connection close if any of the 
open/read/write commands doesn't succeed within 5 seconds.

Thanks again for your help!

Andrew

Mark Crispin wrote:

> open, TCP read, and TCP write timeouts.  On Windows, you can set TCP 
> read and TCP write timeouts.  This is done via the SET_OPENTIMEOUT, 
> If you fail to arm a timeout handler via SET_TIMEOUT, a timeout will 
> cause an immediate disconnect.  If you arm a timeout handler, then the 
> timeout handler is able to decide whether to disconnect or dismiss the 
> timeout.
>
> Note that "disconnect or dismiss" are your only two choices; and the 
> only way that a c-client function will return is if it completes or 
> the session is disconnected.  However, your timeout handler *does* 
> have the option of doing other tasks, (e.g., updating the screen) 
> prior to dismissing the timeout.
>

---

From: Mark Crispin <[email-masked]>
Date: Wed, 14 Sep 2005 19:55:47 -0700

On Wed, 14 Sep 2005, Andrew Biggs wrote:
> Thanks Mark, this is exactly what I was looking for.  I gave this a go, but 
> it didn't seem to take.  I went into the code and it seems like the 
> tcp_nt.c called by mail_parameters().

That's correct.

That's what I meant when I wrote:
>> On UNIX, you can set TCP 
>> and TCP write timeouts.

I'm sorry if I was unclear.

Open timeouts aren't supported on Windows.  The feature used in UNIX to 
implement open timeouts does not exist in Windows.

-- Mark --

http://staff.washington.edu/mrc
Science does not emerge from voting, party politics, or public debate.
Si vis pacem, para bellum.
_______________________________________________
Imap-uw mailing list
[email-masked]
https://mailman1.u.washington.edu/mailman/listinfo/imap-uw

---

From: Andrew Biggs <[email-masked]>
Date: Wed, 14 Sep 2005 21:02:39 -0600

Ahh... my error.  Sorry, I should have read that part more carefully.  
At any rate, having at least the read and write timeouts will still be 
very helpful.   Thanks very much for your quick responses, too!

Andrew

Mark Crispin wrote:

>> Thanks Mark, this is exactly what I was looking for.  I gave this a 
>> go, but it didn't seem to take.  I went into the code and it seems 
>> like the SET_OPENTIMEOUT parameter isn't used by the tcp_parameters() 
>> function in tcp_nt.c called by mail_parameters().
>
>
> That's correct.
>
>>> On UNIX, you can set TCP open, TCP read, and TCP write timeouts.  On 
>>> Windows, you can set TCP read and TCP write timeouts.
>>
>
> Open timeouts aren't supported on Windows.  The feature used in UNIX 
> to implement open timeouts does not exist in Windows.
>
> -- Mark --
>

---

From: "Eric Schreuder" <[email-masked]>
Date: Thu, 15 Sep 2005 10:27:50 +0200

Hi Mark,

> implement open timeouts does not exist in Windows.

Other features exist in Windows since winsock2, that make it possible to
implement open timeouts. I have sent you a patch two years ago, implementing
open timeouts on Windows. I think it was rejected at the time because
c-client was based on winsock. We have used the patch ever since, so it has
been tested quite well. Maybe a feature to (re)consider for imap-2006?

Eric

---

From: Mark Crispin <[email-masked]>
Date: Thu, 15 Sep 2005 08:28:44 -0700 (PDT)

> been tested quite well. Maybe a feature to (re)consider for imap-2006?

Yes, I would.  Could you re-send me that patch?  The Windows version of 
c-client is now based on winsock2, although currently the only aspect of 
winsock2 that is used is IPv6 support and that's only in w2k builds (not 
nt or ntk builds).

Have you tested your patch on Win95/98/Me/NT4 systems?  Believe it or not, 
we still hear from people who use such systems (especially Win98).

-- Mark --

http://panda.com/mrc