libcutils/mq.c
static bool peerProxyNextPacket(PeerProxy* peerProxy) {
    Peer* peer = peerProxy->peer;
    peerLock(peer);
    
    OutgoingPacket* current = peerProxy->currentPacket;
    
    if (current == NULL) {
    	// The queue is already empty.
        peerUnlock(peer);
        return false;
    }
    
    OutgoingPacket* next = current->nextPacket;
    peerProxy->currentPacket = next;
    current->nextPacket = NULL;
    current->free(current);
    if (next == NULL) {
        // The queue is empty.
        peerProxy->lastPacket = NULL;
        peerUnlock(peer);
        return false;
    } else {
        peerUnlock(peer);
        peerProxyPrepareOutgoingHeader(peerProxy); 

        // TODO: Start writing next packet? It would reduce the number of
        // system calls, but we could also starve other peers.
        return true;
    }
}
/** 
 * Frees current packet and moves to the next one. Returns true if there is
 * a next packet or false if the queue is empty.
 */
Frees current packet and moves to the next one. Returns true if there is
a next packet or false if the queue is empty.
Frees current packet and moves to the next one . Returns true if there is a next packet or false if the queue is empty .
static bool peerProxyNextPacket(PeerProxy* peerProxy) {
    Peer* peer = peerProxy->peer;
    peerLock(peer);
    OutgoingPacket* current = peerProxy->currentPacket;
    if (current == NULL) {
        peerUnlock(peer);
        return false;
    }
    OutgoingPacket* next = current->nextPacket;
    peerProxy->currentPacket = next;
    current->nextPacket = NULL;
    current->free(current);
    if (next == NULL) {
        peerProxy->lastPacket = NULL;
        peerUnlock(peer);
        return false;
    } else {
        peerUnlock(peer);
        peerProxyPrepareOutgoingHeader(peerProxy); 
        return true;
    }
}
static bool peerProxyNextPacket ( PeerProxy * peerProxy ) { Peer * peer = peerProxy -> peer ; peerLock ( peer ) ; OutgoingPacket * current = peerProxy -> currentPacket ; if ( current == NULL ) { peerUnlock ( peer ) ; return false ; } OutgoingPacket * next = current -> nextPacket ; peerProxy -> currentPacket = next ; current -> nextPacket = NULL ; current -> free ( current ) ; if ( next == NULL ) { peerProxy -> lastPacket = NULL ; peerUnlock ( peer ) ; return false ; } else { peerUnlock ( peer ) ; peerProxyPrepareOutgoingHeader ( peerProxy ) ; return true ; } }
Frees current packet and moves to the next one.
Frees current packet and moves to the next one .
// The queue is already empty. // The queue is empty. // TODO: Start writing next packet? It would reduce the number of // system calls, but we could also starve other peers.