diff options
author | Not Zed <NotZed@Ximian.com> | 2004-09-08 12:02:41 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-09-08 12:02:41 +0800 |
commit | f28eb2be4e77d749ee72c69c2bdcfc510741fe9b (patch) | |
tree | cca3e7bfb8dd2cc4abc09eb28d86341ee37491b6 /camel/camel-tcp-stream-ssl.c | |
parent | 585a2ea55469ad698f2aecb47ca7e70751c46d9a (diff) | |
download | gsoc2013-evolution-f28eb2be4e77d749ee72c69c2bdcfc510741fe9b.tar.gz gsoc2013-evolution-f28eb2be4e77d749ee72c69c2bdcfc510741fe9b.tar.zst gsoc2013-evolution-f28eb2be4e77d749ee72c69c2bdcfc510741fe9b.zip |
make ssl connection async and cancellable, and minor api update to async
2004-09-03 Not Zed <NotZed@Ximian.com>
* camel-tcp-stream-ssl.c (stream_connect): make ssl connection
async and cancellable, and minor api update to async connection.
svn path=/trunk/; revision=27180
Diffstat (limited to 'camel/camel-tcp-stream-ssl.c')
-rw-r--r-- | camel/camel-tcp-stream-ssl.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/camel/camel-tcp-stream-ssl.c b/camel/camel-tcp-stream-ssl.c index 820912ffa5..791083186c 100644 --- a/camel/camel-tcp-stream-ssl.c +++ b/camel/camel-tcp-stream-ssl.c @@ -1028,7 +1028,7 @@ stream_connect (CamelTcpStream *stream, struct hostent *host, int port) { CamelTcpStreamSSL *ssl = CAMEL_TCP_STREAM_SSL (stream); PRNetAddr netaddr; - PRFileDesc *fd; + PRFileDesc *fd, *cancel_fd; g_return_val_if_fail (host != NULL, -1); @@ -1070,26 +1070,37 @@ stream_connect (CamelTcpStream *stream, struct hostent *host, int port) fd = ssl_fd; } - - if (PR_Connect (fd, &netaddr, CONNECT_TIMEOUT) == PR_FAILURE) { + + cancel_fd = camel_operation_cancel_prfd(NULL); + + if (PR_Connect (fd, &netaddr, cancel_fd?0:CONNECT_TIMEOUT) == PR_FAILURE) { int errnosave; set_errno (PR_GetError ()); - if (errno == EINPROGRESS) { + if (errno == EINPROGRESS || (cancel_fd && errno == ETIMEDOUT)) { gboolean connected = FALSE; - PRPollDesc poll; + PRPollDesc poll[2]; + + poll[0].fd = fd; + poll[0].in_flags = PR_POLL_WRITE | PR_POLL_EXCEPT; + poll[1].fd = cancel_fd; + poll[1].in_flags = PR_POLL_READ; do { - poll.fd = fd; - poll.in_flags = PR_POLL_WRITE | PR_POLL_EXCEPT; - poll.out_flags = 0; - - if (PR_Poll (&poll, 1, CONNECT_TIMEOUT) == PR_FAILURE) { + poll[0].out_flags = 0; + poll[1].out_flags = 0; + + if (PR_Poll (poll, cancel_fd?2:1, CONNECT_TIMEOUT) == PR_FAILURE) { set_errno (PR_GetError ()); goto exception; } - if (PR_GetConnectStatus (&poll) == PR_FAILURE) { + if (poll[1].out_flags == PR_POLL_READ) { + errno = EINTR; + goto exception; + } + + if (PR_ConnectContinue(fd, poll[0].out_flags) == PR_FAILURE) { set_errno (PR_GetError ()); if (errno != EINPROGRESS) goto exception; |