|
We're talking apples and oranges.
A socket is not physical, so you can't physically
close it. To get off on a wild tangent, what is a socket? We are
given a socket handle, but that's not the "socket". The structure the
handle refers to isn't the actual socket itself either. The data that is
transferred on the "socket" isn't the socket either. You see, it's super
abstract. It's not even something that you can pinpoint in an abstract
way. Compare this with a file. There is a file handle, a structure
associated with the handle, etc... But there is a "file" - it is
comprised of the data on the disk. I can send you a file, I would send the
name and the data. I can't send you a socket, there's nothing to
send. When I create a file I have something, albeit a little
abstracted. When I create a socket I have nothing at all, just a handle
that points to a structure, neither of which is the socket itself. Even in
the winsock and lsp code my socket is abstract, with a file there is a point
where abstraction meets reality, with a socket there is no such meeting
place.
So how do you "physically" close a
socket?
Now back to reality...
I think what you meant was when you force a close
outside of your normal IOCP handling code, your closesocket gets called
twice.
So you wrap your socket in a class. The
class notes when the socket is open or when it has been closed. If you
closed it already, don't close it again. The IOCP is just going to
"cancel" all outstanding IOs on that socket when you close it
anyway.
Also lets think about how the socket connection
goes. Usually you have your own "handshake" that is done so that you know
to close the socket gracefully. Your IOCP server receives this "I'm
closing" handshake from the client, and it receives it in the IOCP code.
That's when it closes the socket there. If it doesn't receive the
handshake-close, it doesn't close the socket. And after every read
completion you should be posting another read to replace the one you are
handling that is coming off the stack, unless the socket is closed or in a
closing state.
|
_______________________________________________ msvc mailing list [email protected] See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription changes, and list archive.
