[evolution-patches] updated async hostname cancel patch



finally got around to making it work w/ gethostbyaddr too.

the logic is the same as the original ...

 Z

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/camel/ChangeLog,v
retrieving revision 1.1831
diff -u -3 -r1.1831 ChangeLog
--- ChangeLog	18 Jun 2003 06:14:08 -0000	1.1831
+++ ChangeLog	18 Jun 2003 08:51:24 -0000
@@ -1,3 +1,13 @@
+2003-06-18  Not Zed  <NotZed Ximian com>
+
+	* camel-service.c (get_hostbyaddr, get_hostbyname): if we got
+	cancelled, the message is floating, so free it.
+	(struct _lookup_msg): Add a cancelled tag.
+	(camel_gethostbyname, camel_gethostbyaddr): if we get a
+	failure/cancel, cancel the lookup thread and detach, so we dont
+	have to wait for it to return.  cleanup changed to handle the case
+	where we didn't get a reply message.
+
 2003-06-17  Not Zed  <NotZed Ximian com>
 
 	* camel-vee-folder.c (vee_folder_remove_folder): Calculate ranges
@@ -8,6 +18,14 @@
 
 	* camel-folder-summary.c (camel_folder_summary_remove_index): new
 	function to drop a range of index entries in one hit.
+
+2003-06-16  Not Zed  <NotZed Ximian com>
+
+	** See bug #31745
+
+	* providers/imap/camel-imap-store-summary.c
+	(camel_imap_store_summary_namespace_new): Workaround a shell bug -
+	if the namespace has '#' in it, then strip it.
 
 2003-06-16  Not Zed  <NotZed Ximian com>
 
Index: camel-service.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-service.c,v
retrieving revision 1.81
diff -u -3 -r1.81 camel-service.c
--- camel-service.c	15 May 2003 01:00:56 -0000	1.81
+++ camel-service.c	18 Jun 2003 08:51:25 -0000
@@ -691,6 +691,7 @@
 #ifdef ENABLE_THREADS
 	EMsg msg;
 #endif
+	unsigned int cancelled:1;
 	const char *name;
 	int len;
 	int type;
@@ -718,7 +719,13 @@
 	d(printf("gethostbyname ok?\n"));
 
 #ifdef ENABLE_THREADS
-	e_msgport_reply((EMsg *)info);
+	/* If we got cancelled, dont reply, just free it */
+	if (info->cancelled) {
+		g_free(info->hostbufmem);
+		g_free(info);
+	} else {
+		e_msgport_reply((EMsg *)info);
+	}
 #endif
 	return NULL;
 }
@@ -766,27 +773,33 @@
 				FD_SET(cancel_fd, &rdset);
 				FD_SET(fd, &rdset);
 				fdmax = MAX(fd, cancel_fd) + 1;
-				status = select (fdmax, &rdset, NULL, 0, NULL);
+				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"));
-				pthread_cancel(id);
-			} else if (FD_ISSET(cancel_fd, &rdset)) {
-				d(printf("Cancelling lookup thread\n"));
-				camel_exception_setv(ex, CAMEL_EXCEPTION_USER_CANCEL, _("Cancelled"));
+
+			if (status == -1 || FD_ISSET(cancel_fd, &rdset)) {
+				if (status == -1)
+					camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Failure in name lookup: %s"), g_strerror(errno));
+				else
+					camel_exception_setv(ex, CAMEL_EXCEPTION_USER_CANCEL, _("Cancelled"));
+
+				/* We cancel so if the thread impl is decent it causes immediate exit.
+				   We detach so we dont need to wait for it to exit if it isn't.
+				   We check the reply port incase we had a reply in the mean time, which we free later */
+				d(printf("Cancelling lookup thread and leaving it\n"));
+				msg->cancelled = 1;
+				pthread_detach(id);
 				pthread_cancel(id);
+				msg = (struct _lookup_msg *)e_msgport_get(reply_port);
 			} else {
 				struct _lookup_msg *reply = (struct _lookup_msg *)e_msgport_get(reply_port);
 
 				g_assert(reply == msg);
+				d(printf("waiting for child to exit\n"));
+				pthread_join(id, NULL);
+				d(printf("child done\n"));
 			}
-			d(printf("waiting for child to exit\n"));
-			pthread_join(id, NULL);
-			d(printf("child done\n"));
+		} else {
+			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Host lookup failed: cannot create thread: %s"), g_strerror(errno));
 		}
 		e_msgport_destroy(reply_port);
 	}
@@ -794,23 +807,25 @@
 
 	camel_operation_end(NULL);
 
-	if (msg->result != 0) {
- 		if (!camel_exception_is_set(ex)) {
-			if (msg->herr == HOST_NOT_FOUND || msg->herr == NO_DATA)
-				camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-						      _("Host lookup failed: %s: host not found"), name);
-			else
-				camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-						      _("Host lookup failed: %s: unknown reason"), name);
-		}
+	if (!camel_exception_is_set(ex)) {
+		if (msg->result == 0)
+			return &msg->hostbuf;
+
+		if (msg->herr == HOST_NOT_FOUND || msg->herr == NO_DATA)
+			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+					      _("Host lookup failed: %s: host not found"), name);
+		else
+			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+					      _("Host lookup failed: %s: unknown reason"), name);
+	}
+
+	if (msg) {
 		g_free(msg->hostbufmem);
 		g_free(msg);
-		return NULL;
-	} else {
-		return &msg->hostbuf;
 	}
-}
 
+	return NULL;
+}
 
 static void *
 get_hostbyaddr (void *data)
@@ -830,7 +845,12 @@
 	d(printf ("gethostbyaddr ok?\n"));
 	
 #ifdef ENABLE_THREADS
-	e_msgport_reply ((EMsg *) info);
+	if (info->cancelled) {
+		g_free(info->hostbufmem);
+		g_free(info);
+	} else {
+		e_msgport_reply((EMsg *)info);
+	}
 #endif
 	return NULL;
 }
@@ -884,24 +904,28 @@
 				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"));
-				pthread_cancel (id);
-			} else if (FD_ISSET(cancel_fd, &rdset)) {
-				d(printf ("Cancelling lookup thread\n"));
-				camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Cancelled"));
-				pthread_cancel (id);
+			if (status == -1 || FD_ISSET(cancel_fd, &rdset)) {
+				if (status == -1)
+					camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Failure in name lookup: %s"), g_strerror(errno));
+				else
+					camel_exception_setv(ex, CAMEL_EXCEPTION_USER_CANCEL, _("Cancelled"));
+
+				/* We cancel so if the thread impl is decent it causes immediate exit.
+				   We detach so we dont need to wait for it to exit if it isn't.
+				   We check the reply port incase we had a reply in the mean time, which we free later */
+				d(printf("Cancelling lookup thread and leaving it\n"));
+				msg->cancelled = 1;
+				pthread_detach(id);
+				pthread_cancel(id);
+				msg = (struct _lookup_msg *)e_msgport_get(reply_port);
 			} else {
-				struct _lookup_msg *reply = (struct _lookup_msg *) e_msgport_get (reply_port);
-				
-				g_assert (reply == msg);
+				struct _lookup_msg *reply = (struct _lookup_msg *)e_msgport_get(reply_port);
+
+				g_assert(reply == msg);
+				d(printf("waiting for child to exit\n"));
+				pthread_join(id, NULL);
+				d(printf("child done\n"));
 			}
-			
-			d(printf ("waiting for child to exit\n"));
-			pthread_join (id, NULL);
-			d(printf ("child done\n"));
 		}
 		
 		e_msgport_destroy (reply_port);
@@ -909,23 +933,25 @@
 #endif
 	
 	camel_operation_end (NULL);
-	
-	if (msg->result != 0) {
- 		if (!camel_exception_is_set (ex)) {
-			if (msg->herr == HOST_NOT_FOUND || msg->herr == NO_DATA)
-				camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-						     _("Host lookup failed: host not found"));
-			else
-				camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-						     _("Host lookup failed: unknown reason"));
-		}
-		
-		g_free (msg->hostbufmem);
-		g_free (msg);
-		return NULL;
-	} else {
-		return &msg->hostbuf;
+
+	if (!camel_exception_is_set(ex)) {
+		if (msg->result == 0)
+			return &msg->hostbuf;
+
+		if (msg->herr == HOST_NOT_FOUND || msg->herr == NO_DATA)
+			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+					      _("Host lookup failed: host not found"));
+		else
+			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+					      _("Host lookup failed: unknown reason"));
+	}
+
+	if (msg) {
+		g_free(msg->hostbufmem);
+		g_free(msg);
 	}
+
+	return NULL;
 }
 
 void camel_free_host(struct hostent *h)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]