libcutils/mq.c
int peerSendBytes(pid_t pid, const char* bytes, size_t size) {
	Peer* peer = localPeer;
    assert(peer != NULL);

    OutgoingPacket* packet = calloc(1, sizeof(OutgoingPacket));
    if (packet == NULL) {
        errno = ENOMEM;
        return -1;
    }

    Buffer* copy = bufferCreate(size); 
    if (copy == NULL) {
        free(packet);
        errno = ENOMEM;
        return -1;
    }

    // Copy data.
    memcpy(copy->data, bytes, size);
    copy->size = size;
    
    packet->bytes = copy;
    packet->header.type = BYTES;
    packet->header.size = size;
    packet->free = outgoingPacketFreeBytes;
    bufferPrepareForWrite(packet->bytes);
    
    peerLock(peer);
    
    PeerProxy* peerProxy = peerProxyGetOrCreate(peer, pid, true);
    if (peerProxy == NULL) {
        // The peer is already dead or we couldn't alloc memory. Either way,
        // errno is set.
        peerUnlock(peer);
        packet->free(packet); 
        return -1;
    } else {
        peerProxyEnqueueOutgoingPacket(peerProxy, packet);
        peerUnlock(peer);
        selectorWakeUp(peer->selector);
        return 0; 
    }
}
/**
 * Sends a packet of bytes to a remote peer. Returns 0 on success.
 *
 * Returns -1 if an error occurs. Sets errno to ENOMEM if memory couldn't be
 * allocated. Sets errno to EHOSTDOWN if the peer died recently. Sets errno
 * to EINVAL if pid is the same as the local pid.
 */
Sends a packet of bytes to a remote peer. Returns 0 on success.
Returns -1 if an error occurs. Sets errno to ENOMEM if memory couldn't be
allocated. Sets errno to EHOSTDOWN if the peer died recently. Sets errno
to EINVAL if pid is the same as the local pid.
Sends a packet of bytes to a remote peer . Returns 0 on success . Returns - 1 if an error occurs . Sets errno to ENOMEM if memory couldn ' t be allocated . Sets errno to EHOSTDOWN if the peer died recently . Sets errno to EINVAL if pid is the same as the local pid .
int peerSendBytes(pid_t pid, const char* bytes, size_t size) {
	Peer* peer = localPeer;
    assert(peer != NULL);
    OutgoingPacket* packet = calloc(1, sizeof(OutgoingPacket));
    if (packet == NULL) {
        errno = ENOMEM;
        return -1;
    }
    Buffer* copy = bufferCreate(size); 
    if (copy == NULL) {
        free(packet);
        errno = ENOMEM;
        return -1;
    }
    memcpy(copy->data, bytes, size);
    copy->size = size;
    packet->bytes = copy;
    packet->header.type = BYTES;
    packet->header.size = size;
    packet->free = outgoingPacketFreeBytes;
    bufferPrepareForWrite(packet->bytes);
    peerLock(peer);
    PeerProxy* peerProxy = peerProxyGetOrCreate(peer, pid, true);
    if (peerProxy == NULL) {
        peerUnlock(peer);
        packet->free(packet); 
        return -1;
    } else {
        peerProxyEnqueueOutgoingPacket(peerProxy, packet);
        peerUnlock(peer);
        selectorWakeUp(peer->selector);
        return 0; 
    }
}
int peerSendBytes ( pid_t pid , const char * bytes , size_t size ) { Peer * peer = localPeer ; assert ( peer != NULL ) ; OutgoingPacket * packet = calloc ( 1 , sizeof ( OutgoingPacket ) ) ; if ( packet == NULL ) { errno = ENOMEM ; return -1 ; } Buffer * copy = bufferCreate ( size ) ; if ( copy == NULL ) { free ( packet ) ; errno = ENOMEM ; return -1 ; } memcpy ( copy -> data , bytes , size ) ; copy -> size = size ; packet -> bytes = copy ; packet -> header . type = BYTES ; packet -> header . size = size ; packet -> free = outgoingPacketFreeBytes ; bufferPrepareForWrite ( packet -> bytes ) ; peerLock ( peer ) ; PeerProxy * peerProxy = peerProxyGetOrCreate ( peer , pid , true ) ; if ( peerProxy == NULL ) { peerUnlock ( peer ) ; packet -> free ( packet ) ; return -1 ; } else { peerProxyEnqueueOutgoingPacket ( peerProxy , packet ) ; peerUnlock ( peer ) ; selectorWakeUp ( peer -> selector ) ; return 0 ; } }
Sends a packet of bytes to a remote peer.
Sends a packet of bytes to a remote peer .
// Copy data. // The peer is already dead or we couldn't alloc memory. Either way, // errno is set.