Afficher un message
Vieux 08/05/2007, 15h09   #4
Roy Smith
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can we know if a socket descriptor is already allocated ?

"robertwessel2@yahoo.com" <robertwessel2@yahoo.com> wrote:
> In short knowing that "descriptor 3" is open, tells you almost nothing
> of value, because there is no way to determine *why* it's open, or by
> what part of your program.


It's funny that this came up today, because I was struggling with this
exact issue yesterday.

I've written a C++ class which manages a socket. Part of the specification
is that the socket is closed when the object is destroyed. I was looking
for a way to write a unit test which verifies that a given socket
descriptor is valid, then destroys the object under test, then verifies
that the descriptor was closed. The best I came up with was to just close
the descriptor myself; it I got EBADF, that meant it was already closed
(and the test passed).

I'll admit, however, that while that worked in the specific case of a
(single-threaded) unit test, it might not be a good plan in a more general
environment.
  Réponse avec citation
 
Page generated in 0,07338 seconds with 9 queries