Mercurial > pidgin
diff src/stun.c @ 12909:8e3b85fe4a55
[gaim-migrate @ 15262]
Make UPnP truly asynchronous.
There are probably still a couple socket calls that should be made nonblocking, but I wanted to commit this before it became even bigger. This contains a number of probable leak fixes in the upnp stuff.
The UPnP stuff has been updated to use gaim_url_fetch_request() instead of the specific implementation.
To make this all work, I had to make gaim_network_listen() and gaim_network_listen_range() also asynchronous - seems to work just fine apart from the UPnP calls seeming to take longer than they should (I'm planning to look into this).
I also triggered a STUN and UPnP discovery on startup so that we hopefully have the information when we need it.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 17 Jan 2006 05:48:51 +0000 |
parents | a7bf698eb37c |
children | c3167a1dd817 |
line wrap: on
line diff
--- a/src/stun.c Tue Jan 17 05:20:38 2006 +0000 +++ b/src/stun.c Tue Jan 17 05:48:51 2006 +0000 @@ -273,22 +273,14 @@ } } -static void hbn_cb(GSList *hosts, gpointer data, const char *error_message) { + +static void hbn_listen_cb(int fd, gpointer data) { + GSList *hosts = data; struct stun_conn *sc; static struct stun_header hdr_data; - int ret, fd; + int ret; - if(!hosts || !hosts->data) { - nattype.status = GAIM_STUN_STATUS_UNDISCOVERED; - nattype.lookup_time = time(NULL); - do_callbacks(); - return; - } - - - fd = gaim_network_listen_range(12108, 12208, SOCK_DGRAM); - - if(!fd) { + if(fd < 0) { nattype.status = GAIM_STUN_STATUS_UNKNOWN; nattype.lookup_time = time(NULL); do_callbacks(); @@ -337,6 +329,25 @@ sc->timeout = gaim_timeout_add(500, (GSourceFunc) timeoutfunc, sc); } +static void hbn_cb(GSList *hosts, gpointer data, const char *error_message) { + + if(!hosts || !hosts->data) { + nattype.status = GAIM_STUN_STATUS_UNDISCOVERED; + nattype.lookup_time = time(NULL); + do_callbacks(); + return; + } + + if (!gaim_network_listen_range(12108, 12208, SOCK_DGRAM, hbn_listen_cb, hosts)) { + nattype.status = GAIM_STUN_STATUS_UNKNOWN; + nattype.lookup_time = time(NULL); + do_callbacks(); + return; + } + + +} + static void do_test1(GaimSrvResponse *resp, int results, gpointer sdata) { const char *servername = sdata; int port = 3478; @@ -417,4 +428,5 @@ void gaim_stun_init() { gaim_prefs_add_string("/core/network/stun_server", ""); + gaim_stun_discover(NULL); }