INIT-RMQ()
{
    Initialize internal data structures to nil.
}
INIT-LINK( int link )
{
    Create socket connection to link, remember fd
    Return socket buffer size
}
ENQUE-ENVELOPE( Request request )
{
    THREAD-LOCK(request->link)
    write( request->packet )
    if (not all written) {
       add to pending write queue
    }
    THREAD-UNLOCK(request->link)
}
PUT-DATA( Request request )
{
    THREAD-LOCK(request->link)
    writev( send-data packet header, request->data )
    if (not all written) {
       add to pending write queue
    }
    THREAD-UNLOCK(request->link)
}
POLL-RMQ( blocking )
{
    for each link (in increasing order), THREAD-LOCK(request->link)
    select( open fds, timeout = (blocking ? NULL:0) );
    for each unselected link, THREAD-UNLOCK(request->link)
    for each set fd {
       if (read) {
           read packet
           // process incoming data (locking for access)
           RMQ_Dispatch_packet( &packet, methodid );
           // Use ADI3 routines to access message queues
       }
       if (write)
           advance pending writes (locking for access)
       THREAD-UNLOCK(link corresponding to fd)
    }
}
