diff libgaim/protocols/oscar/flap_connection.c @ 15129: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 6cc89a43bf8f
children 4934e7a03a98
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);