Can I tell a socket to abandon an operation? suppose the thread that started it has timed out and has been killed.I would like to call a fresh thread on the same socket to try again RRS feed

  • Question

  • I am running winsock2 ver. 514. Consider a client which creates a given UDP socket, a thread is opened that does a sendto and recvfrom, which may block waiting for the echo msg from the server. This try thread is called by the originator of the socket. This try thread may time out   to guard against waits forever on lost reply packets. Both sendto and recvfrm are given addresses to write to. Suppose a timeout happens on the try thread, the  recvfrom or sendto  fall off their wait and the try  thread exits The socket has not been informed that its calling thread and addresses to write messages to and get replies from are not longer valid. Another thread is started, (same socket) and we try again hoping for a success, so this thread
    issues its own sendto-recvfrom pair. This time the winsock dll is very angry and gives the infamous 10004 (blocking operation was interrupted by a call to WSAcancelBlockingCall) after a SOCKET_ERROR result from either the sendto or recvfrom, and WSAGetLastError gives the 10004. That’s if you are lucky. If you are unlucky, the second call will result it thread corruption, those addresses given to try1 are no longer valid after the original thread timeout, and you can get memory corruption. 

    Is there a way that after try 1 times out, you can tell the socket to forget what it was doing? . Maybe it was working on a recvfrom then its thread was killed. 
    I suppose I could destroy the socket after a thread times out, and start with a fresh socket for each try. I don’t know if that will work. I will try, but it seems not efficient to build a new socket. Cant I tell the old one "never mind" before a start a new thread to give the socket a fresh start at a successful sendto recvfrom? 
    I understand WSACancelBlockingCall (sounds like a promicing name) has been removed form winsock2.
    Wednesday, July 15, 2009 4:18 PM