Detach UDP sockets on cleanup

The UDP service does not own the UDP sockets. When shutting down,
inform the bound sockets that the service is no longer available.
This allows subsequent method calls to error out cleanly.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
This commit is contained in:
Andreas Faerber 2010-06-13 17:50:11 +02:00 committed by Augustin Cavalier
parent 74077e46e1
commit ce6fdd33ef
2 changed files with 16 additions and 0 deletions

View File

@ -52,6 +52,7 @@ public:
uint16 Port() const { return fPort; }
status_t Bind(ip_addr_t address, uint16 port);
void Detach();
status_t Send(ip_addr_t destinationAddress, uint16 destinationPort,
ChainBuffer *buffer);

View File

@ -175,6 +175,15 @@ UDPSocket::Bind(ip_addr_t address, uint16 port)
}
void
UDPSocket::Detach()
{
fUDPService = NULL;
// This will lead to subsequent methods returning B_NO_INIT
}
status_t
UDPSocket::Send(ip_addr_t destinationAddress, uint16 destinationPort,
ChainBuffer *buffer)
@ -264,6 +273,12 @@ UDPService::UDPService(IPService *ipService)
UDPService::~UDPService()
{
int count = fSockets.Count();
for (int i = 0; i < count; i++) {
UDPSocket *socket = fSockets.ElementAt(i);
socket->Detach();
}
if (fIPService != NULL)
fIPService->UnregisterIPSubService(this);
}