libcutils/mq.c
void peerInitialize(BytesListener* bytesListener, 
        DeathListener* deathListener) {
    // Connect to master peer.
    int masterSocket = socket(AF_LOCAL, SOCK_STREAM, 0);
    if (masterSocket == -1) {
        LOG_ALWAYS_FATAL("socket() error: %s", strerror(errno));
    }
    int result = connect(masterSocket, (SocketAddress*) getMasterAddress(),
            sizeof(UnixAddress));
    if (result != 0) {
        LOG_ALWAYS_FATAL("connect() error: %s", strerror(errno));
    }

    // Create the peer for this process. Fail if we already have one.
    if (localPeer != NULL) {
        LOG_ALWAYS_FATAL("Peer is already initialized.");
    }
    localPeer = peerCreate();
    if (localPeer == NULL) {
        LOG_ALWAYS_FATAL("malloc() failed.");
    }
    localPeer->onBytes = bytesListener;
    localPeer->onDeath = deathListener;
    
    // Make connection selectable.
    SelectableFd* masterFd = selectorAdd(localPeer->selector, masterSocket);
    if (masterFd == NULL) {
        LOG_ALWAYS_FATAL("malloc() error.");
    }

    // Create a peer proxy for the master peer.
    PeerProxy* masterProxy = peerProxyCreate(localPeer, MASTER_CREDENTIALS);
    if (masterProxy == NULL) {
        LOG_ALWAYS_FATAL("malloc() error.");
    }
    peerProxySetFd(masterProxy, masterFd);
    masterProxy->master = true;
    localPeer->masterProxy = masterProxy;
}
/**
 * Starts a local peer.
 *
 * Goes into an I/O loop and does not return.
 */
Starts a local peer.
Goes into an I/O loop and does not return.
Starts a local peer . Goes into an I / O loop and does not return .
void peerInitialize(BytesListener* bytesListener, 
        DeathListener* deathListener) {
    int masterSocket = socket(AF_LOCAL, SOCK_STREAM, 0);
    if (masterSocket == -1) {
        LOG_ALWAYS_FATAL("socket() error: %s", strerror(errno));
    }
    int result = connect(masterSocket, (SocketAddress*) getMasterAddress(),
            sizeof(UnixAddress));
    if (result != 0) {
        LOG_ALWAYS_FATAL("connect() error: %s", strerror(errno));
    }
    if (localPeer != NULL) {
        LOG_ALWAYS_FATAL("Peer is already initialized.");
    }
    localPeer = peerCreate();
    if (localPeer == NULL) {
        LOG_ALWAYS_FATAL("malloc() failed.");
    }
    localPeer->onBytes = bytesListener;
    localPeer->onDeath = deathListener;
    SelectableFd* masterFd = selectorAdd(localPeer->selector, masterSocket);
    if (masterFd == NULL) {
        LOG_ALWAYS_FATAL("malloc() error.");
    }
    PeerProxy* masterProxy = peerProxyCreate(localPeer, MASTER_CREDENTIALS);
    if (masterProxy == NULL) {
        LOG_ALWAYS_FATAL("malloc() error.");
    }
    peerProxySetFd(masterProxy, masterFd);
    masterProxy->master = true;
    localPeer->masterProxy = masterProxy;
}
void peerInitialize ( BytesListener * bytesListener , DeathListener * deathListener ) { int masterSocket = socket ( AF_LOCAL , SOCK_STREAM , 0 ) ; if ( masterSocket == -1 ) { LOG_ALWAYS_FATAL ( " " , strerror ( errno ) ) ; } int result = connect ( masterSocket , ( SocketAddress * ) getMasterAddress ( ) , sizeof ( UnixAddress ) ) ; if ( result != 0 ) { LOG_ALWAYS_FATAL ( " " , strerror ( errno ) ) ; } if ( localPeer != NULL ) { LOG_ALWAYS_FATAL ( " " ) ; } localPeer = peerCreate ( ) ; if ( localPeer == NULL ) { LOG_ALWAYS_FATAL ( " " ) ; } localPeer -> onBytes = bytesListener ; localPeer -> onDeath = deathListener ; SelectableFd * masterFd = selectorAdd ( localPeer -> selector , masterSocket ) ; if ( masterFd == NULL ) { LOG_ALWAYS_FATAL ( " " ) ; } PeerProxy * masterProxy = peerProxyCreate ( localPeer , MASTER_CREDENTIALS ) ; if ( masterProxy == NULL ) { LOG_ALWAYS_FATAL ( " " ) ; } peerProxySetFd ( masterProxy , masterFd ) ; masterProxy -> master = true ; localPeer -> masterProxy = masterProxy ; }
Starts a local peer.
Starts a local peer .
// Connect to master peer. // Create the peer for this process. Fail if we already have one. // Make connection selectable. // Create a peer proxy for the master peer.