简体   繁体   English

如何强制Windows Bluetooth Connect()调用超时

[英]How to force a Windows Bluetooth Connect() call to timeout

Is there any way - Any way at all - to force the 有什么办法-完全有办法-强迫

BluetoothAuthenticateDevice( HWND hwndParent, HANDLE hRadio, BLUETOOTH_DEVICE_INFO * pbtbi, PWSTR pszPasskey, ULONG ulPasskeyLength);

and the

connect(SOCKET s, const struct sockaddr FAR * name, int namelen);

function calls to timeout? 函数调用超时?

I have tried setting SO_RCVTIMEO and SO_SNDTIMEO to different values on the connect() socket to see if they affect the length of the function call, to no avail - and there is some discussion about whether they affect connect() anyway in this question . 我尝试将SO_RCVTIMEO和SO_SNDTIMEO设置为connect()套接字上的不同值,以查看它们是否影响函数调用的长度,但无济于事-并且在此问题中有一些关于它们是否影响connect()的讨论

It appears the default timeout is about 5 seconds on connect() and can apparently be as slow as 30-45 seconds on AuthenticateDevice - i have seen the auth/connect fail process take 80 seconds. 似乎connect()上的默认超时大约为5秒,并且在AuthenticateDevice上显然可以慢到30-45秒 -我已经看到认证/连接失败过程需要80秒。 However, if it hasn't connected in the first 1-2 seconds, it isn't going to - and until this gives up, our GUI can't display anything meaningful to the end user either way. 但是,如果它在最初的1-2秒内没有连接,就不会连接-在此之前,我们的GUI都无法以任何一种方式显示对最终用户有意义的任何内容。 The extra few seconds do matter. 多余的几秒钟确实很重要。

Is it possible to actually enforce a timeout or is the only way to start it in a thread and kill the thread if it takes too long? 是否可以实际执行超时,还是在线程中启动超时并杀死线程的唯一方法(如果花费的时间太长)?

Have you tried setting the socket as non-blocking before making the connect call? 在进行连接调用之前,您是否尝试过将套接字设置为非阻塞状态?

long lFlag;
SOCKET btSocket;

   btSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
   lFlag = 1;
   ioctlsocket(btSocket, FIONBIO, &lFlag);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM