pidgin: e347e340: Better support running many Bonjour clie...
datallah at pidgin.im
datallah at pidgin.im
Sat Feb 21 17:15:39 EST 2009
-----------------------------------------------------------------
Revision: e347e340d58d48fe4f4011e8b9d77168e4f09fc9
Ancestor: ae7b0fcfb76d24f85e92d9df6a44db15d849fd0b
Author: datallah at pidgin.im
Date: 2009-02-21T22:10:27
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/e347e340d58d48fe4f4011e8b9d77168e4f09fc9
Modified files:
libpurple/protocols/bonjour/bonjour.c
libpurple/protocols/bonjour/bonjour.h
libpurple/protocols/bonjour/jabber.c
ChangeLog:
Better support running many Bonjour clients on the same machine by allowing a
listening port to be specified and falling back to a system-assigned port if
it can't be used.
Fixes #8462.
-------------- next part --------------
============================================================
--- libpurple/protocols/bonjour/bonjour.c 91b8867e0f9183a173d33f9edb7f17ad9988b6ac
+++ libpurple/protocols/bonjour/bonjour.c a443ba30e1ab2b49a5ffc7185790e9b76c9a1aba
@@ -102,7 +102,7 @@ bonjour_login(PurpleAccount *account)
/* Start waiting for jabber connections (iChat style) */
bd->jabber_data = g_new0(BonjourJabber, 1);
- bd->jabber_data->port = BONJOUR_DEFAULT_PORT_INT;
+ bd->jabber_data->port = purple_account_get_int(account, "port", BONJOUR_DEFAULT_PORT);
bd->jabber_data->account = account;
if (bonjour_jabber_start(bd->jabber_data) == -1) {
@@ -706,6 +706,9 @@ init_plugin(PurplePlugin *plugin)
prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
/* Creating the options for the protocol */
+ option = purple_account_option_int_new(_("Local Port"), "port", BONJOUR_DEFAULT_PORT);
+ prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
+
option = purple_account_option_string_new(_("First name"), "first", default_firstname);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
============================================================
--- libpurple/protocols/bonjour/bonjour.h 68110455d34e7a9de94b81f9d866d76c99a295c3
+++ libpurple/protocols/bonjour/bonjour.h b12fcaae1b424a4561f7f92b30840cae31eff193
@@ -38,7 +38,7 @@
#define BONJOUR_STATUS_ID_AVAILABLE "available"
#define BONJOUR_STATUS_ID_AWAY "away"
-#define BONJOUR_DEFAULT_PORT_INT 5298
+#define BONJOUR_DEFAULT_PORT 5298
typedef struct _BonjourData
{
============================================================
--- libpurple/protocols/bonjour/jabber.c 950c3dbec07ffe4800de1ed6c66bb5d4c54550b3
+++ libpurple/protocols/bonjour/jabber.c 93aef2e008f0c2d13cec109cf327ca5888585c23
@@ -672,14 +672,11 @@ bonjour_jabber_start(BonjourJabber *jdat
bonjour_jabber_start(BonjourJabber *jdata)
{
struct sockaddr_in my_addr;
- int i;
- gboolean bind_successful;
/* Open a listening socket for incoming conversations */
- if ((jdata->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0)
- {
+ if ((jdata->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
purple_debug_error("bonjour", "Cannot open socket: %s\n", g_strerror(errno));
- purple_connection_error_reason (jdata->account->gc,
+ purple_connection_error_reason(jdata->account->gc,
PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
_("Cannot open socket"));
return -1;
@@ -688,36 +685,25 @@ bonjour_jabber_start(BonjourJabber *jdat
memset(&my_addr, 0, sizeof(struct sockaddr_in));
my_addr.sin_family = AF_INET;
- /* Attempt to find a free port */
- bind_successful = FALSE;
- for (i = 0; i < 10; i++)
- {
- my_addr.sin_port = htons(jdata->port);
- if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == 0)
- {
- bind_successful = TRUE;
- break;
+ /* 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));
+ 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));
+ purple_connection_error_reason(jdata->account->gc,
+ PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+ _("Could not bind socket to port"));
+ return -1;
}
-
- purple_debug_info("bonjour", "Unable to bind to port %u.(%s)\n", jdata->port, g_strerror(errno));
- jdata->port++;
+ jdata->port = purple_network_get_port_from_fd(jdata->socket);
}
- /* On no! We tried 10 ports and could not bind to ANY of them */
- if (!bind_successful)
- {
- purple_debug_error("bonjour", "Cannot bind socket: %s\n", g_strerror(errno));
- purple_connection_error_reason (jdata->account->gc,
- PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- _("Could not bind socket to port"));
- return -1;
- }
-
/* Attempt to listen on the bound socket */
- if (listen(jdata->socket, 10) != 0)
- {
+ if (listen(jdata->socket, 10) != 0) {
purple_debug_error("bonjour", "Cannot listen on socket: %s\n", g_strerror(errno));
- purple_connection_error_reason (jdata->account->gc,
+ purple_connection_error_reason(jdata->account->gc,
PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
_("Could not listen on socket"));
return -1;
More information about the Commits
mailing list