Discussion:
does closesocket call CloseHandle internally?
(too old to reply)
sakito
2006-11-24 14:58:02 UTC
Permalink
Hi,

Well my question is quite concise. As the subject field states, I just want
to know if calling closesocket(hsocket), it calls internally CloseHandle.
I've seen that msdn documentation on CloseHandle says that is used to free
syste resources on ...., Files, ..., Sockets, ...

Any help will be appreciated.

Thanks,

sakito.
Vladimir Scherbina
2006-11-24 18:31:11 UTC
Permalink
No.

Disassemling the function shows that there are no calls to CloseHandle
inside closesocket. You can also easially check that making test application
that calls closesocket - set the breakpoint to CloseHandle in WinDbg - it
would not hit.
--
Vladimir (Windows SDK MVP)
Post by sakito
Hi,
Well my question is quite concise. As the subject field states, I just want
to know if calling closesocket(hsocket), it calls internally CloseHandle.
I've seen that msdn documentation on CloseHandle says that is used to free
syste resources on ...., Files, ..., Sockets, ...
Any help will be appreciated.
Thanks,
sakito.
Skywing [MVP]
2006-11-24 19:56:11 UTC
Permalink
You should not use CloseHandle on a socket handle. There is internal state
kept by the default AFD winsock provider that doesn't get properly cleaned
up if you do this. Additionally, if there is a third party LSP installed,
then you are really taking your life into your own hands as there is no
telling what getting the state of the LSP mixed up will cause.
--
Ken Johnson (Skywing)
Windows SDK MVP
http://www.nynaeve.net
Post by sakito
Hi,
Well my question is quite concise. As the subject field states, I just want
to know if calling closesocket(hsocket), it calls internally CloseHandle.
I've seen that msdn documentation on CloseHandle says that is used to free
syste resources on ...., Files, ..., Sockets, ...
Any help will be appreciated.
Thanks,
sakito.
Vladimir Scherbina
2006-11-25 14:03:23 UTC
Permalink
More specifically, winsock would not be able to release the additional data
associated with the given socket. Because Wah* routines would not be called.
(I mean the WahRemoveHandleContext, etc.)
--
Vladimir (Windows SDK MVP)
Post by Skywing [MVP]
You should not use CloseHandle on a socket handle. There is internal
state kept by the default AFD winsock provider that doesn't get properly
cleaned up if you do this. Additionally, if there is a third party LSP
installed, then you are really taking your life into your own hands as
there is no telling what getting the state of the LSP mixed up will cause.
--
Ken Johnson (Skywing)
Windows SDK MVP
http://www.nynaeve.net
Post by sakito
Hi,
Well my question is quite concise. As the subject field states, I just want
to know if calling closesocket(hsocket), it calls internally CloseHandle.
I've seen that msdn documentation on CloseHandle says that is used to free
syste resources on ...., Files, ..., Sockets, ...
Any help will be appreciated.
Thanks,
sakito.
Arkady Frenkel
2006-11-26 07:08:00 UTC
Permalink
Interesting if v.v. op exist ?
Arkady
Post by Vladimir Scherbina
More specifically, winsock would not be able to release the additional
data associated with the given socket. Because Wah* routines would not be
called. (I mean the WahRemoveHandleContext, etc.)
--
Vladimir (Windows SDK MVP)
Post by Skywing [MVP]
You should not use CloseHandle on a socket handle. There is internal
state kept by the default AFD winsock provider that doesn't get properly
cleaned up if you do this. Additionally, if there is a third party LSP
installed, then you are really taking your life into your own hands as
there is no telling what getting the state of the LSP mixed up will cause.
--
Ken Johnson (Skywing)
Windows SDK MVP
http://www.nynaeve.net
Post by sakito
Hi,
Well my question is quite concise. As the subject field states, I just want
to know if calling closesocket(hsocket), it calls internally
CloseHandle.
I've seen that msdn documentation on CloseHandle says that is used to free
syste resources on ...., Files, ..., Sockets, ...
Any help will be appreciated.
Thanks,
sakito.
sakito
2006-11-26 17:33:01 UTC
Permalink
thak you all guys! that's been a very valuable help!

Juanjo.
Post by Arkady Frenkel
Interesting if v.v. op exist ?
Arkady
Post by Vladimir Scherbina
More specifically, winsock would not be able to release the additional
data associated with the given socket. Because Wah* routines would not be
called. (I mean the WahRemoveHandleContext, etc.)
--
Vladimir (Windows SDK MVP)
Post by Skywing [MVP]
You should not use CloseHandle on a socket handle. There is internal
state kept by the default AFD winsock provider that doesn't get properly
cleaned up if you do this. Additionally, if there is a third party LSP
installed, then you are really taking your life into your own hands as
there is no telling what getting the state of the LSP mixed up will cause.
--
Ken Johnson (Skywing)
Windows SDK MVP
http://www.nynaeve.net
Post by sakito
Hi,
Well my question is quite concise. As the subject field states, I just want
to know if calling closesocket(hsocket), it calls internally CloseHandle.
I've seen that msdn documentation on CloseHandle says that is used to free
syste resources on ...., Files, ..., Sockets, ...
Any help will be appreciated.
Thanks,
sakito.
Vladimir Scherbina
2006-11-27 08:04:08 UTC
Permalink
Post by Arkady Frenkel
Interesting if v.v. op exist ?
No
--
Vladimir (Windows SDK MVP)
Arkady Frenkel
2006-11-27 08:10:27 UTC
Permalink
Tnx
Arkady
Post by Vladimir Scherbina
Post by Arkady Frenkel
Interesting if v.v. op exist ?
No
--
Vladimir (Windows SDK MVP)
qfel
2006-11-27 20:30:46 UTC
Permalink
Then what are routines like WPUCreateSocketHandle or WPUModifyIFSHandle for?
I thought the only disadventage of treating socket handle as a file handle
(using CancelIo, CloseHandle, ReadFile) is possible performance lose in some
cases due to translation mechanism.
Skywing [MVP]
2006-11-27 21:48:48 UTC
Permalink
For supporting LSPs. You shouldn't be using those from a Winsock program...
--
Ken Johnson (Skywing)
Windows SDK MVP
http://www.nynaeve.net
Post by qfel
Then what are routines like WPUCreateSocketHandle or WPUModifyIFSHandle
for? I thought the only disadventage of treating socket handle as a file
handle (using CancelIo, CloseHandle, ReadFile) is possible performance
lose in some cases due to translation mechanism.
qfel
2006-11-27 22:21:30 UTC
Permalink
Post by Skywing [MVP]
For supporting LSPs. You shouldn't be using those from a Winsock program...
Yeah I know, but isn't this support meant to redirect file I/O (along with
CloseHandle and similar?) calls to proper LSPs?

Loading...