changeset 15130:8138277e9369

[gaim-migrate @ 17915] * Add a little cushion to the rate average calculation to hopefully account for any inaccuracies due to network lag and stuff * If one of our connections is disconnected, close the socket and don't try to write to it again. This will hopefully fix a weird race condition that Kevin was running into? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 07 Dec 2006 08:23:18 +0000
parents 1cf62d550a7a
children 6d015bcd8d1d
files libgaim/protocols/oscar/flap_connection.c libgaim/protocols/oscar/peer.c
diffstat 2 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libgaim/protocols/oscar/flap_connection.c	Thu Dec 07 08:06:48 2006 +0000
+++ b/libgaim/protocols/oscar/flap_connection.c	Thu Dec 07 08:23:18 2006 +0000
@@ -129,7 +129,8 @@
 
 			new_current = rateclass_get_new_current(conn, rateclass, &now);
 
-			if (new_current < rateclass->alert)
+			if (new_current < rateclass->alert + 100)
+				/* (Add 100ms padding to account for inaccuracies in the calculation) */
 				/* Not ready to send this SNAC yet--keep waiting. */
 				return TRUE;
 
@@ -185,8 +186,9 @@
 		gettimeofday(&now, NULL);
 		new_current = rateclass_get_new_current(conn, rateclass, &now);
 
-		if (new_current < rateclass->alert)
+		if (new_current < rateclass->alert + 100)
 		{
+			/* (Add 100ms padding to account for inaccuracies in the calculation) */
 			enqueue = TRUE;
 		}
 		else
@@ -905,6 +907,10 @@
 			return;
 
 		/* Error! */
+		gaim_input_remove(conn->watcher_outgoing);
+		conn->watcher_outgoing = 0;
+		close(conn->fd);
+		conn->fd = -1;
 		flap_connection_schedule_destroy(conn,
 				OSCAR_DISCONNECT_LOST_CONNECTION, strerror(errno));
 		return;
@@ -930,7 +936,7 @@
 	gaim_circ_buffer_append(conn->buffer_outgoing, bs->data, count);
 
 	/* If we haven't already started writing stuff, then start the cycle */
-	if (conn->watcher_outgoing == 0)
+	if ((conn->watcher_outgoing == 0) && (conn->fd != -1))
 	{
 		conn->watcher_outgoing = gaim_input_add(conn->fd,
 				GAIM_INPUT_WRITE, send_cb, conn);
--- a/libgaim/protocols/oscar/peer.c	Thu Dec 07 08:06:48 2006 +0000
+++ b/libgaim/protocols/oscar/peer.c	Thu Dec 07 08:23:18 2006 +0000
@@ -421,8 +421,14 @@
 			return;
 
 		if (conn->ready)
+		{
+			gaim_input_remove(conn->watcher_outgoing);
+			conn->watcher_outgoing = 0;
+			close(conn->fd);
+			conn->fd = -1;
 			peer_connection_schedule_destroy(conn,
 					OSCAR_DISCONNECT_LOST_CONNECTION, NULL);
+		}
 		else
 		{
 			/*
@@ -450,7 +456,7 @@
 	gaim_circ_buffer_append(conn->buffer_outgoing, bs->data, bs->len);
 
 	/* If we haven't already started writing stuff, then start the cycle */
-	if (conn->watcher_outgoing == 0)
+	if ((conn->watcher_outgoing == 0) && (conn->fd != -1))
 	{
 		conn->watcher_outgoing = gaim_input_add(conn->fd,
 				GAIM_INPUT_WRITE, send_cb, conn);
@@ -708,8 +714,6 @@
 	gaim_debug_info("oscar", "Peer connection timed out after 5 seconds.  "
 			"Trying next method...\n");
 
-	peer_connection_close(conn);
-
 	peer_connection_trynext(conn);
 
 	/* Cancel this timer.  It'll be added again, if needed. */