From e7432164869e777b21aee021e23033bbdf747cac Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 2 May 2002 18:19:57 +0000 Subject: Change the order of some code so that we check if the select() failed 2002-05-02 Jeffrey Stedfast * camel-pgp-context.c (crypto_exec_with_passwd): Change the order of some code so that we check if the select() failed before we check for user-cancellation. * camel-service.c (camel_gethostbyname): Check for EINTR when select()ing. (camel_gethostbyaddr): Same. svn path=/trunk/; revision=16666 --- camel/ChangeLog | 15 +++++++++++++++ camel/camel-pgp-context.c | 13 ++++++------- camel/camel-service.c | 34 +++++++++++++++++++++------------- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/camel/ChangeLog b/camel/ChangeLog index a4d7dc2b69..e3d981d6e5 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,18 @@ +2002-05-02 Jeffrey Stedfast + + * camel-pgp-context.c (crypto_exec_with_passwd): Change the order + of some code so that we check if the select() failed before we + check for user-cancellation. + + * camel-service.c (camel_gethostbyname): Check for EINTR when + select()ing. + (camel_gethostbyaddr): Same. + +2002-04-29 Jeffrey Stedfast + + * camel-provider.c (camel_provider_auto_detect): Now takes a + CamelURL argument rather than a GHashTable *settings argument. + 2002-04-29 Not Zed * providers/local/camel-spool-store.c (get_folder_info): We want diff --git a/camel/camel-pgp-context.c b/camel/camel-pgp-context.c index 29a948e881..e6ef1a7820 100644 --- a/camel/camel-pgp-context.c +++ b/camel/camel-pgp-context.c @@ -422,21 +422,20 @@ crypto_exec_with_passwd (const char *path, char *argv[], const char *input, int select_result = select (max + 1, &fdset, &write_fdset, NULL, &timeout); - if (cancel_fd != -1 && FD_ISSET (cancel_fd, &fdset)) { - /* user-cancelled */ - break; - } - if (select_result < 0) { if (errno == EINTR) continue; break; - } - if (select_result == 0) { + } else if (select_result == 0) { /* timeout */ break; } + if (cancel_fd != -1 && FD_ISSET (cancel_fd, &fdset)) { + /* user-cancelled */ + break; + } + if (FD_ISSET (op_fds[0], &fdset)) { /* More output is available. */ diff --git a/camel/camel-service.c b/camel/camel-service.c index 502da90c5a..19c058f970 100644 --- a/camel/camel-service.c +++ b/camel/camel-service.c @@ -600,10 +600,10 @@ get_hostbyname(void *data) } struct hostent * -camel_gethostbyname(const char *name, CamelException *ex) +camel_gethostbyname (const char *name, CamelException *ex) { #ifdef ENABLE_THREADS - int fdmax, fd, cancel_fd; + int fdmax, status, fd, cancel_fd; #endif struct _lookup_msg *msg; @@ -635,12 +635,16 @@ camel_gethostbyname(const char *name, CamelException *ex) reply_port = msg->msg.reply_port = e_msgport_new(); fd = e_msgport_fd(msg->msg.reply_port); if (pthread_create(&id, NULL, get_hostbyname, msg) == 0) { - FD_ZERO(&rdset); - FD_SET(cancel_fd, &rdset); - FD_SET(fd, &rdset); - fdmax = MAX(fd, cancel_fd) + 1; d(printf("waiting for name return/cancellation in main process\n")); - if (select(fdmax, &rdset, NULL, 0, NULL) == -1) { + do { + FD_ZERO(&rdset); + FD_SET(cancel_fd, &rdset); + FD_SET(fd, &rdset); + fdmax = MAX(fd, cancel_fd) + 1; + status = select (fdmax, &rdset, NULL, 0, NULL); + } while (status == -1 && errno == EINTR); + + if (status == -1) { camel_exception_setv(ex, 1, _("Failure in name lookup: %s"), strerror(errno)); d(printf("Cancelling lookup thread\n")); pthread_cancel(id); @@ -707,7 +711,7 @@ struct hostent * camel_gethostbyaddr (const char *addr, int len, int type, CamelException *ex) { #ifdef ENABLE_THREADS - int fdmax, fd, cancel_fd; + int fdmax, status, fd, cancel_fd; #endif struct _lookup_msg *msg; @@ -741,12 +745,16 @@ camel_gethostbyaddr (const char *addr, int len, int type, CamelException *ex) reply_port = msg->msg.reply_port = e_msgport_new (); fd = e_msgport_fd (msg->msg.reply_port); if (pthread_create (&id, NULL, get_hostbyaddr, msg) == 0) { - FD_ZERO(&rdset); - FD_SET(cancel_fd, &rdset); - FD_SET(fd, &rdset); - fdmax = MAX(fd, cancel_fd) + 1; d(printf("waiting for name return/cancellation in main process\n")); - if (select (fdmax, &rdset, NULL, 0, NULL) == -1) { + do { + FD_ZERO(&rdset); + FD_SET(cancel_fd, &rdset); + FD_SET(fd, &rdset); + fdmax = MAX(fd, cancel_fd) + 1; + status = select (fdmax, &rdset, NULL, 0, NULL); + } while (status == -1 && errno == EINTR); + + if (status == -1) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Failure in name lookup: %s"), g_strerror (errno)); d(printf ("Cancelling lookup thread\n")); -- cgit v1.2.3