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:
parent
74077e46e1
commit
ce6fdd33ef
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user