loudmouth/lm-connection.c
changeset 156 8c054d9e98b8
parent 155 d24c4392d4e3
child 168 ac1affcd5d22
--- a/loudmouth/lm-connection.c	Fri Jun 16 09:21:33 2006 +0000
+++ b/loudmouth/lm-connection.c	Sun Jun 25 10:28:28 2006 +0000
@@ -1623,9 +1623,11 @@
 lm_connection_close (LmConnection      *connection, 
 		     GError           **error)
 {
-	g_return_val_if_fail (connection != NULL, FALSE);
+	gboolean no_errors = TRUE;
 	
-	if (!lm_connection_is_open (connection)) {
+	g_return_val_if_fail (connection != NULL, FALSE);
+
+	if (connection->state == LM_CONNECTION_STATE_CLOSED) {
 		g_set_error (error,
 			     LM_ERROR,
 			     LM_ERROR_CONNECTION_NOT_OPEN,
@@ -1636,16 +1638,18 @@
 	lm_verbose ("Disconnecting from: %s:%d\n", 
 		    connection->server, connection->port);
 	
-	if (!connection_send (connection, "</stream:stream>", -1, error)) {
-		return FALSE;
+	if (lm_connection_is_open (connection)) {
+		if (!connection_send (connection, "</stream:stream>", -1, error)) {
+			no_errors = FALSE;
+		}
+		
+		g_io_channel_flush (connection->io_channel, NULL);
 	}
 	
- 	g_io_channel_flush (connection->io_channel, NULL);
-	
 	connection_do_close (connection);
 	connection_signal_disconnect (connection, LM_DISCONNECT_REASON_OK);
 	
-	return TRUE;
+	return no_errors;
 }
 
 /**