Ticket #6166: 0003-Detach-UDP-sockets-on-cleanup.patch

File 0003-Detach-UDP-sockets-on-cleanup.patch, 1.8 KB (added by jessicah, 10 years ago)

proposed patch: detach UDP sockets

  • headers/private/kernel/boot/net/UDP.h

    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:  
    5252    uint16 Port() const         { return fPort; }
    5353
    5454    status_t Bind(ip_addr_t address, uint16 port);
     55    void Detach();
    5556
    5657    status_t Send(ip_addr_t destinationAddress, uint16 destinationPort,
    5758        ChainBuffer *buffer);
  • src/system/boot/loader/net/UDP.cpp

    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)  
    171171    return B_OK;
    172172}
    173173
     174
     175void
     176UDPSocket::Detach()
     177{
     178    fUDPService = NULL;
     179        // This will lead to subsequent methods returning B_NO_INIT
     180}
     181
     182
    174183
    175184status_t
    176185UDPSocket::Send(ip_addr_t destinationAddress, uint16 destinationPort,
    UDPService::UDPService(IPService *ipService)  
    261279
    262280UDPService::~UDPService()
    263281{
     282    int count = fSockets.Count();
     283    for (int i = 0; i < count; i++) {
     284        UDPSocket *socket = fSockets.ElementAt(i);
     285        socket->Detach();
     286    }
     287
    264288    if (fIPService != NULL)
    265289        fIPService->UnregisterIPSubService(this);
    266290}