libcutils/mq.c
static void peerProxyKill(PeerProxy* peerProxy, bool errnoIsSet) {
    if (errnoIsSet) {
        LOGI("Peer %d died. errno: %s", peerProxy->credentials.pid, 
                strerror(errno));
    } else {
        LOGI("Peer %d died.", peerProxy->credentials.pid);
    }
    
    // If we lost the master, we're up a creek. We can't let this happen.
    if (peerProxy->master) {    
        LOG_ALWAYS_FATAL("Lost connection to master.");
    }

    Peer* localPeer = peerProxy->peer;
    pid_t pid = peerProxy->credentials.pid;
    
    peerLock(localPeer);
    
    // Remember for awhile that the peer died.
    localPeer->deadPeers[localPeer->deadPeerCursor] 
        = peerProxy->credentials.pid;
    localPeer->deadPeerCursor++;
    if (localPeer->deadPeerCursor == PEER_HISTORY) {
        localPeer->deadPeerCursor = 0;
    }
  
    // Remove from peer map.
    hashmapRemove(localPeer->peerProxies, &pid);
    
    // External threads can no longer get to this peer proxy, so we don't 
    // need the lock anymore.
    peerUnlock(localPeer);
    
    // Remove the fd from the selector.
    if (peerProxy->fd != NULL) {
        peerProxy->fd->remove = true;
    }

    // Clear outgoing packet queue.
    while (peerProxyNextPacket(peerProxy)) {}

    bufferFree(peerProxy->inputBuffer);

    // This only applies to the master.
    if (peerProxy->connections != NULL) {
        // We can't leave these other maps pointing to freed memory.
        hashmapForEach(peerProxy->connections, &peerProxyRemoveConnection, 
                peerProxy);
        hashmapFree(peerProxy->connections);
    }

    // Invoke death listener.
    localPeer->onDeath(pid);

    // Free the peer proxy itself.
    free(peerProxy);
}
/**
 * Called when the peer dies.
 */
Called when the peer dies.
Called when the peer dies .
static void peerProxyKill(PeerProxy* peerProxy, bool errnoIsSet) {
    if (errnoIsSet) {
        LOGI("Peer %d died. errno: %s", peerProxy->credentials.pid, 
                strerror(errno));
    } else {
        LOGI("Peer %d died.", peerProxy->credentials.pid);
    }
    if (peerProxy->master) {    
        LOG_ALWAYS_FATAL("Lost connection to master.");
    }
    Peer* localPeer = peerProxy->peer;
    pid_t pid = peerProxy->credentials.pid;
    peerLock(localPeer);
    localPeer->deadPeers[localPeer->deadPeerCursor] 
        = peerProxy->credentials.pid;
    localPeer->deadPeerCursor++;
    if (localPeer->deadPeerCursor == PEER_HISTORY) {
        localPeer->deadPeerCursor = 0;
    }
    hashmapRemove(localPeer->peerProxies, &pid);
    peerUnlock(localPeer);
    if (peerProxy->fd != NULL) {
        peerProxy->fd->remove = true;
    }
    while (peerProxyNextPacket(peerProxy)) {}
    bufferFree(peerProxy->inputBuffer);
    if (peerProxy->connections != NULL) {
        hashmapForEach(peerProxy->connections, &peerProxyRemoveConnection, 
                peerProxy);
        hashmapFree(peerProxy->connections);
    }
    localPeer->onDeath(pid);
    free(peerProxy);
}
static void peerProxyKill ( PeerProxy * peerProxy , bool errnoIsSet ) { if ( errnoIsSet ) { LOGI ( " " , peerProxy -> credentials . pid , strerror ( errno ) ) ; } else { LOGI ( " " , peerProxy -> credentials . pid ) ; } if ( peerProxy -> master ) { LOG_ALWAYS_FATAL ( " " ) ; } Peer * localPeer = peerProxy -> peer ; pid_t pid = peerProxy -> credentials . pid ; peerLock ( localPeer ) ; localPeer -> deadPeers [ localPeer -> deadPeerCursor ] = peerProxy -> credentials . pid ; localPeer -> deadPeerCursor ++ ; if ( localPeer -> deadPeerCursor == PEER_HISTORY ) { localPeer -> deadPeerCursor = 0 ; } hashmapRemove ( localPeer -> peerProxies , & pid ) ; peerUnlock ( localPeer ) ; if ( peerProxy -> fd != NULL ) { peerProxy -> fd -> remove = true ; } while ( peerProxyNextPacket ( peerProxy ) ) { } bufferFree ( peerProxy -> inputBuffer ) ; if ( peerProxy -> connections != NULL ) { hashmapForEach ( peerProxy -> connections , & peerProxyRemoveConnection , peerProxy ) ; hashmapFree ( peerProxy -> connections ) ; } localPeer -> onDeath ( pid ) ; free ( peerProxy ) ; }
Called when the peer dies.
Called when the peer dies .
// If we lost the master, we're up a creek. We can't let this happen. // Remember for awhile that the peer died. // Remove from peer map. // External threads can no longer get to this peer proxy, so we don't  // need the lock anymore. // Remove the fd from the selector. // Clear outgoing packet queue. // This only applies to the master. // We can't leave these other maps pointing to freed memory. // Invoke death listener. // Free the peer proxy itself.