From ce6fdd33ef1dc4214d2c3edeb5692540753b7e3b Mon Sep 17 00:00:00 2001 From: Andreas Faerber Date: Sun, 13 Jun 2010 17:50:11 +0200 Subject: [PATCH] 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 --- headers/private/kernel/boot/net/UDP.h | 1 + src/system/boot/loader/net/UDP.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/headers/private/kernel/boot/net/UDP.h b/headers/private/kernel/boot/net/UDP.h index fd1bdd6495..2b587f49a4 100644 --- a/headers/private/kernel/boot/net/UDP.h +++ b/headers/private/kernel/boot/net/UDP.h @@ -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); diff --git a/src/system/boot/loader/net/UDP.cpp b/src/system/boot/loader/net/UDP.cpp index 10af060bc4..5c4adbdc35 100644 --- a/src/system/boot/loader/net/UDP.cpp +++ b/src/system/boot/loader/net/UDP.cpp @@ -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); }