changeset 27453:96cafa3d271c

Make some error messages more uniform. Include output from g_strerror() in the message when possible--users might not always know exactly what it means, but it might help some people, and for people who don't understand the error message it will be easier for them to ask about it, or to search for other people with the same problem.
author Mark Doliner <mark@kingant.net>
date Mon, 06 Jul 2009 05:22:25 +0000
parents 97947f51b221
children 7fd1b4c73310
files libpurple/protocols/bonjour/jabber.c
diffstat 1 files changed, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/jabber.c	Mon Jul 06 05:18:34 2009 +0000
+++ b/libpurple/protocols/bonjour/jabber.c	Mon Jul 06 05:22:25 2009 +0000
@@ -686,11 +686,13 @@
 	struct sockaddr_in my_addr;
 
 	/* Open a listening socket for incoming conversations */
-	if ((jdata->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
-		purple_debug_error("bonjour", "Cannot open socket: %s\n", g_strerror(errno));
+	jdata->socket = socket(PF_INET, SOCK_STREAM, 0);
+	if (jdata->socket < 0) {
+		gchar *buf = g_strdup_printf(_("Unable to create socket: %s"),
+				g_strerror(errno));
 		purple_connection_error_reason(jdata->account->gc,
-			PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
-			_("Cannot open socket"));
+			PURPLE_CONNECTION_ERROR_NETWORK_ERROR, buf);
+		g_free(buf);
 		return -1;
 	}
 
@@ -699,25 +701,31 @@
 
 	/* Try to use the specified port - if it isn't available, use a random port */
 	my_addr.sin_port = htons(jdata->port);
-	if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) {
-		purple_debug_info("bonjour", "Unable to bind to specified port %u (%s).\n", jdata->port, g_strerror(errno));
+	if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0)
+	{
+		purple_debug_info("bonjour", "Unable to bind to specified "
+				"port %i: %s\n", jdata->port, g_strerror(errno));
 		my_addr.sin_port = 0;
-		if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) {
-			purple_debug_error("bonjour", "Unable to bind to system assigned port (%s).\n", g_strerror(errno));
+		if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0)
+		{
+			gchar *buf = g_strdup_printf(_("Unable to bind socket "
+					"to port: %s"), g_strerror(errno));
 			purple_connection_error_reason(jdata->account->gc,
-				PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
-				_("Could not bind socket to port"));
+				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, buf);
+			g_free(buf);
 			return -1;
 		}
 		jdata->port = purple_network_get_port_from_fd(jdata->socket);
 	}
 
 	/* Attempt to listen on the bound socket */
-	if (listen(jdata->socket, 10) != 0) {
-		purple_debug_error("bonjour", "Cannot listen on socket: %s\n", g_strerror(errno));
+	if (listen(jdata->socket, 10) != 0)
+	{
+		gchar *buf = g_strdup_printf(_("Unable to listen on socket: %s"),
+				g_strerror(errno));
 		purple_connection_error_reason(jdata->account->gc,
-			PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
-			_("Could not listen on socket"));
+			PURPLE_CONNECTION_ERROR_NETWORK_ERROR, buf);
+		g_free(buf);
 		return -1;
 	}