Mercurial > pidgin.yaz
comparison libgaim/network.c @ 14791:2727e465602f
[gaim-migrate @ 17556]
This will fix the constant network change notification in Wingaim when "Peer Name Resolution Protocol" service is enabled.
We now only look at the Network Location Awareness namespace.
Add some better error handling.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Sat, 21 Oct 2006 19:12:54 +0000 |
parents | ec9cc2219e55 |
children | c678034a7e3e |
comparison
equal
deleted
inserted
replaced
14790:a33d179d5508 | 14791:2727e465602f |
---|---|
375 | 375 |
376 return ntohs(addr.sin_port); | 376 return ntohs(addr.sin_port); |
377 } | 377 } |
378 | 378 |
379 #ifdef _WIN32 | 379 #ifdef _WIN32 |
380 #ifndef NS_NLA | |
381 #define NS_NLA 15 | |
382 #endif | |
380 static gint | 383 static gint |
381 wgaim_get_connected_network_count(void) | 384 wgaim_get_connected_network_count(void) |
382 { | 385 { |
383 guint net_cnt = 0; | 386 guint net_cnt = 0; |
384 | 387 |
386 HANDLE h; | 389 HANDLE h; |
387 int retval; | 390 int retval; |
388 | 391 |
389 memset(&qs, 0, sizeof(WSAQUERYSET)); | 392 memset(&qs, 0, sizeof(WSAQUERYSET)); |
390 qs.dwSize = sizeof(WSAQUERYSET); | 393 qs.dwSize = sizeof(WSAQUERYSET); |
391 qs.dwNameSpace = NS_ALL; | 394 qs.dwNameSpace = NS_NLA; |
392 | 395 |
393 retval = WSALookupServiceBegin(&qs, LUP_RETURN_ALL, &h); | 396 retval = WSALookupServiceBegin(&qs, LUP_RETURN_ALL, &h); |
394 if (retval != ERROR_SUCCESS) { | 397 if (retval != ERROR_SUCCESS) { |
395 int errorid = WSAGetLastError(); | 398 int errorid = WSAGetLastError(); |
396 gchar *msg = g_win32_error_message(errorid); | 399 gchar *msg = g_win32_error_message(errorid); |
397 gaim_debug_warning("network", "Couldn't look up connected networks. %s (%d).\n", msg, errorid); | 400 gaim_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. " |
401 "NLA service is probably not running. Message: %s (%d).\n", | |
402 msg, errorid); | |
398 g_free(msg); | 403 g_free(msg); |
399 | 404 |
400 return -1; | 405 return -1; |
401 } else { | 406 } else { |
402 char buf[1024]; | 407 char buf[1024]; |
444 HANDLE h; | 449 HANDLE h; |
445 WSAQUERYSET qs; | 450 WSAQUERYSET qs; |
446 time_t last_trigger = time(NULL); | 451 time_t last_trigger = time(NULL); |
447 | 452 |
448 int WSAAPI (*MyWSANSPIoctl) ( | 453 int WSAAPI (*MyWSANSPIoctl) ( |
449 HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer, | 454 HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer, |
450 DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, | 455 DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, |
451 LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion) = NULL; | 456 LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion) = NULL; |
452 | 457 |
453 MyWSANSPIoctl = (void*) wgaim_find_and_loadproc("ws2_32.dll", "WSANSPIoctl"); | 458 if (!(MyWSANSPIoctl = (void*) wgaim_find_and_loadproc("ws2_32.dll", "WSANSPIoctl"))) { |
454 if (!MyWSANSPIoctl) { | |
455 gaim_debug_error("network", "Couldn't load WSANSPIoctl from ws2_32.dll.\n"); | |
456 g_thread_exit(NULL); | 459 g_thread_exit(NULL); |
457 return NULL; | 460 return NULL; |
458 } | 461 } |
459 | 462 |
460 while (TRUE) { | 463 while (TRUE) { |
461 int retval; | 464 int retval; |
462 DWORD retLen = 0; | 465 DWORD retLen = 0; |
463 | 466 |
464 memset(&qs, 0, sizeof(WSAQUERYSET)); | 467 memset(&qs, 0, sizeof(WSAQUERYSET)); |
465 qs.dwSize = sizeof(WSAQUERYSET); | 468 qs.dwSize = sizeof(WSAQUERYSET); |
466 qs.dwNameSpace = NS_ALL; | 469 qs.dwNameSpace = NS_NLA; |
467 | 470 if (WSALookupServiceBegin(&qs, 0, &h) == SOCKET_ERROR) { |
468 retval = WSALookupServiceBegin(&qs, LUP_RETURN_ALL, &h); | 471 int errorid = WSAGetLastError(); |
472 gchar *msg = g_win32_error_message(errorid); | |
473 gaim_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. " | |
474 "NLA service is probably not running. Message: %s (%d).\n", | |
475 msg, errorid); | |
476 g_free(msg); | |
477 g_thread_exit(NULL); | |
478 return NULL; | |
479 } | |
469 | 480 |
470 /* Make sure at least 30 seconds have elapsed since the last | 481 /* Make sure at least 30 seconds have elapsed since the last |
471 * notification so we don't peg the cpu if this keeps changing. */ | 482 * notification so we don't peg the cpu if this keeps changing. */ |
472 if ((time(NULL) - last_trigger) < 30) | 483 if ((time(NULL) - last_trigger) < 30) |
473 Sleep(30000); | 484 Sleep(30000); |
474 | 485 |
475 last_trigger = time(NULL); | 486 last_trigger = time(NULL); |
476 | 487 |
477 /* This will block until there is a network change */ | 488 /* This will block until there is a network change */ |
478 retval = MyWSANSPIoctl(h, SIO_NSP_NOTIFY_CHANGE, NULL, 0, NULL, 0, &retLen, NULL); | 489 if (MyWSANSPIoctl(h, SIO_NSP_NOTIFY_CHANGE, NULL, 0, NULL, 0, &retLen, NULL) == SOCKET_ERROR) { |
490 int errorid = WSAGetLastError(); | |
491 gchar *msg = g_win32_error_message(errorid); | |
492 gaim_debug_warning("network", "Unable to wait for changes. Message: %s (%d).\n", | |
493 msg, errorid); | |
494 g_free(msg); | |
495 } | |
479 | 496 |
480 retval = WSALookupServiceEnd(h); | 497 retval = WSALookupServiceEnd(h); |
481 | 498 |
482 g_idle_add(wgaim_network_change_thread_cb, NULL); | 499 g_idle_add(wgaim_network_change_thread_cb, NULL); |
483 | 500 |
484 } | 501 } |
502 | |
503 g_thread_exit(NULL); | |
504 return NULL; | |
485 } | 505 } |
486 #endif | 506 #endif |
487 | 507 |
488 gboolean | 508 gboolean |
489 gaim_network_is_available(void) | 509 gaim_network_is_available(void) |