0

I have a Windows service application written in C++/MFC that establishes an HTTP connection via Windows sockets. It employs WinHttp* APIs to do all the socket related operations. It all works great, except when someone tries to stop/uninstall that service if it's in the process of connecting via the socket (espeically in a situation when such connection could not be established, like, say, if my Internet cable is unplugged) those socket APIs do not return for several seconds before the service can close (obviously, the mechanism inside the service waits for my socket thread to finish "gracefully".)

My question is, if I have an open socket handle, as well connection and request handles (of HINTERNET type), obtained from a call to WinHttpOpen(), WinHttpConnect() and WinHttpOpenRequest(), is there any way to forcefully make any other WinHttp* APIs that may be currently working with the socket to return immediately?

PS. I was thinking to do so from a main thread before it begins waiting for the socket thread to close (before uninstalling/stopping the service.)

4

2 回答 2

1

您可以从另一个线程关闭您的 WinHTTP 句柄。这会以您试图避免的延迟中断主线程上的阻塞调用。请参阅如何取消同步 WinHttp 请求?

于 2012-04-18T10:50:15.857 回答
0

[显然,服务内部的机制等待我的套接字线程“优雅地”完成] - 如果您知道问题的原因,为什么不将其删除?

你为什么要等?

于 2012-04-18T10:41:53.297 回答