From ec00c909a7e0e17970363e58c8388bf385067db7 Mon Sep 17 00:00:00 2001
From: Andreas Faerber <andreas.faerber@web.de>
Date: Sun, 13 Jun 2010 17:50:11 +0200
Subject: [PATCH 3/4] 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.
---
headers/private/kernel/boot/net/UDP.h | 1 +
src/system/boot/loader/net/UDP.cpp | 15 +++++++++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/headers/private/kernel/boot/net/UDP.h b/headers/private/kernel/boot/net/UDP.h
index fd1bdd6..2b587f4 100644
a
|
b
|
public:
|
52 | 52 | uint16 Port() const { return fPort; } |
53 | 53 | |
54 | 54 | status_t Bind(ip_addr_t address, uint16 port); |
| 55 | void Detach(); |
55 | 56 | |
56 | 57 | status_t Send(ip_addr_t destinationAddress, uint16 destinationPort, |
57 | 58 | ChainBuffer *buffer); |
diff --git a/src/system/boot/loader/net/UDP.cpp b/src/system/boot/loader/net/UDP.cpp
index e5eb1be..a02286c 100644
a
|
b
|
UDPSocket::Bind(ip_addr_t address, uint16 port)
|
171 | 171 | return B_OK; |
172 | 172 | } |
173 | 173 | |
| 174 | |
| 175 | void |
| 176 | UDPSocket::Detach() |
| 177 | { |
| 178 | fUDPService = NULL; |
| 179 | // This will lead to subsequent methods returning B_NO_INIT |
| 180 | } |
| 181 | |
| 182 | |
174 | 183 | |
175 | 184 | status_t |
176 | 185 | UDPSocket::Send(ip_addr_t destinationAddress, uint16 destinationPort, |
… |
… |
UDPService::UDPService(IPService *ipService)
|
261 | 279 | |
262 | 280 | UDPService::~UDPService() |
263 | 281 | { |
| 282 | int count = fSockets.Count(); |
| 283 | for (int i = 0; i < count; i++) { |
| 284 | UDPSocket *socket = fSockets.ElementAt(i); |
| 285 | socket->Detach(); |
| 286 | } |
| 287 | |
264 | 288 | if (fIPService != NULL) |
265 | 289 | fIPService->UnregisterIPSubService(this); |
266 | 290 | } |