libcutils/mq.c
static void peerProxyWriteConnection(PeerProxy* peerProxy) {
    int socket = peerProxy->currentPacket->socket;

    // Why does sending and receiving fds have to be such a PITA?
    struct msghdr msg;
    struct iovec iov[1];
    
    union {
        struct cmsghdr cm;
        char control[CMSG_SPACE(sizeof(int))];
    } control_un;
   
    struct cmsghdr *cmptr;
    
    msg.msg_control = control_un.control;
    msg.msg_controllen = sizeof(control_un.control);
    cmptr = CMSG_FIRSTHDR(&msg);
    cmptr->cmsg_len = CMSG_LEN(sizeof(int));
    cmptr->cmsg_level = SOL_SOCKET;
    cmptr->cmsg_type = SCM_RIGHTS;
   
    // Store the socket in the message.
    *((int *) CMSG_DATA(cmptr)) = peerProxy->currentPacket->socket;

    msg.msg_name = NULL;
    msg.msg_namelen = 0;
    iov[0].iov_base = "";
    iov[0].iov_len = 1;
    msg.msg_iov = iov;
    msg.msg_iovlen = 1;

    ssize_t result = sendmsg(peerProxy->fd->fd, &msg, 0);
    
    if (result < 0) {
        peerProxyHandleError(peerProxy, "sendmsg");
    } else {
        // Success. Queue up the next packet.
        peerProxyNextPacket(peerProxy);
        
    }
}
/** Sends a socket to the peer. */
Sends a socket to the peer.
Sends a socket to the peer .
static void peerProxyWriteConnection(PeerProxy* peerProxy) {
    int socket = peerProxy->currentPacket->socket;
    struct msghdr msg;
    struct iovec iov[1];
    union {
        struct cmsghdr cm;
        char control[CMSG_SPACE(sizeof(int))];
    } control_un;
    struct cmsghdr *cmptr;
    msg.msg_control = control_un.control;
    msg.msg_controllen = sizeof(control_un.control);
    cmptr = CMSG_FIRSTHDR(&msg);
    cmptr->cmsg_len = CMSG_LEN(sizeof(int));
    cmptr->cmsg_level = SOL_SOCKET;
    cmptr->cmsg_type = SCM_RIGHTS;
    *((int *) CMSG_DATA(cmptr)) = peerProxy->currentPacket->socket;
    msg.msg_name = NULL;
    msg.msg_namelen = 0;
    iov[0].iov_base = "";
    iov[0].iov_len = 1;
    msg.msg_iov = iov;
    msg.msg_iovlen = 1;
    ssize_t result = sendmsg(peerProxy->fd->fd, &msg, 0);
    if (result < 0) {
        peerProxyHandleError(peerProxy, "sendmsg");
    } else {
        peerProxyNextPacket(peerProxy);
    }
}
static void peerProxyWriteConnection ( PeerProxy * peerProxy ) { int socket = peerProxy -> currentPacket -> socket ; struct msghdr msg ; struct iovec iov [ 1 ] ; union { struct cmsghdr cm ; char control [ CMSG_SPACE ( sizeof ( int ) ) ] ; } control_un ; struct cmsghdr * cmptr ; msg . msg_control = control_un . control ; msg . msg_controllen = sizeof ( control_un . control ) ; cmptr = CMSG_FIRSTHDR ( & msg ) ; cmptr -> cmsg_len = CMSG_LEN ( sizeof ( int ) ) ; cmptr -> cmsg_level = SOL_SOCKET ; cmptr -> cmsg_type = SCM_RIGHTS ; * ( ( int * ) CMSG_DATA ( cmptr ) ) = peerProxy -> currentPacket -> socket ; msg . msg_name = NULL ; msg . msg_namelen = 0 ; iov [ 0 ] . iov_base = " " ; iov [ 0 ] . iov_len = 1 ; msg . msg_iov = iov ; msg . msg_iovlen = 1 ; ssize_t result = sendmsg ( peerProxy -> fd -> fd , & msg , 0 ) ; if ( result < 0 ) { peerProxyHandleError ( peerProxy , " " ) ; } else { peerProxyNextPacket ( peerProxy ) ; } }
Sends a socket to the peer.
Sends a socket to the peer .
// Why does sending and receiving fds have to be such a PITA? // Store the socket in the message. // Success. Queue up the next packet.