changeset 25572:11e2d8a878b0

Close p2p connection when read() does not return anything.
author Sulabh Mahajan <sulabh@soc.pidgin.im>
date Fri, 13 Jun 2008 11:04:13 +0000
parents ef47df3e5dd4
children f1de4ccc433e
files libpurple/protocols/yahoo/yahoo.c libpurple/protocols/yahoo/yahoo.h
diffstat 2 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/yahoo.c	Mon Jun 09 08:08:21 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Fri Jun 13 11:04:13 2008 +0000
@@ -246,7 +246,7 @@
 			if (f->away == 2) {
 				/* Idle may have already been set in a more precise way in case 137 */
 				if (f->idle == 0)
-					f->idle = time(NULL);
+					f->idle = time(NULL) - 60;	/*start idle at 1 min*/
 			}
 
 			break;
@@ -2296,13 +2296,22 @@
 	guchar *start = NULL;
 	struct yahoo_p2p_data *user_data;
 
-	user_data = data;
-
-	if((len = read(source, buf, sizeof(buf))) <= 0 )
-		purple_debug_warning("yahoo","p2p: Error in connection to p2p host\n");
+	if(!(user_data = data))
+		return ;
+
+	if((len = read(source, buf, sizeof(buf))) <= 0 )	{
+		purple_debug_warning("yahoo","p2p: Error in connection to p2p host or host disconnected\n");
+		purple_input_remove(user_data->input_event);
+		close(source);
+		/*free user data*/
+		g_free(user_data->host_ip);
+		g_free(user_data->host_username);
+		g_free(user_data);
+	}
 
 	if(len < YAHOO_PACKET_HDRLEN)
 		return;
+
 	if(strncmp((char *)buf, "YMSG", MIN(4, len)) != 0) {
 		/* Not a YMSG packet */
 		purple_debug_warning("yahoo","p2p: Got something other than YMSG packet\n");
@@ -2361,12 +2370,12 @@
 		purple_debug_warning("yahoo","p2p: %s\n",error_message);
 		return;
 	}
-	/*Add an Input Read event to the file descriptor*/
-	purple_input_add(source, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data);
-
 	if(!(user_data = data))
 		return ;
 
+	/*Add an Input Read event to the file descriptor*/
+	user_data->input_event = purple_input_add(source, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data);
+
 	account = purple_connection_get_account(user_data->gc);
 
 	/*Build the yahoo packet*/
--- a/libpurple/protocols/yahoo/yahoo.h	Mon Jun 09 08:08:21 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.h	Fri Jun 13 11:04:13 2008 +0000
@@ -120,6 +120,7 @@
 	int session_id;
 	char *host_username;
 	int val_13;
+	guint input_event;
 };
 
 struct _YchtConn;