Index: device/bluetooth/bluetooth_task_manager_win.cc |
diff --git a/device/bluetooth/bluetooth_task_manager_win.cc b/device/bluetooth/bluetooth_task_manager_win.cc |
index db2540b12e77ddf41d8132c8b1ab5a904e590c6a..3f72ed83c603b62205306228bca4ec11556e901b 100644 |
--- a/device/bluetooth/bluetooth_task_manager_win.cc |
+++ b/device/bluetooth/bluetooth_task_manager_win.cc |
@@ -537,6 +537,7 @@ bool BluetoothTaskManagerWin::DiscoverClassicDeviceServices( |
const GUID& protocol_uuid, |
bool search_cached_services_only, |
ScopedVector<ServiceRecordState>* service_record_states) { |
+TryAgain: |
// Bluetooth and WSAQUERYSET for Service Inquiry. See http://goo.gl/2v9pyt. |
WSAQUERYSET sdp_query; |
ZeroMemory(&sdp_query, sizeof(sdp_query)); |
@@ -562,7 +563,16 @@ bool BluetoothTaskManagerWin::DiscoverClassicDeviceServices( |
HANDLE sdp_handle; |
if (ERROR_SUCCESS != |
WSALookupServiceBegin(&sdp_query, control_flags, &sdp_handle)) { |
- LogPollingError("Error calling WSALookupServiceBegin", WSAGetLastError()); |
+ int last_error = WSAGetLastError(); |
+ // If the device is "offline", no services are returned when specifying |
+ // "LUP_FLUSHCACHE". Try again without flushing the cache so that the list |
+ // of previously known services is returned. |
+ if (!search_cached_services_only && |
+ (last_error == WSASERVICE_NOT_FOUND || last_error == WSANO_DATA)) { |
+ search_cached_services_only = true; |
+ goto TryAgain; |
xiyuan
2014/08/14 19:35:29
Can we get rid of the "goto"?
rpaquay
2014/08/15 19:55:33
Done.
|
+ } |
+ LogPollingError("Error calling WSALookupServiceBegin", last_error); |
return false; |
} |
char sdp_buffer[kServiceDiscoveryResultBufferSize]; |