ivshmem_client_handle_server_msg(IvshmemClient *client)
{
    IvshmemClientPeer *peer;
    long peer_id;
    int ret, fd;
    ret = ivshmem_client_read_one_msg(client, &peer_id, &fd);
    if (ret < 0) {
    /* can return a peer or the local client */
    peer = ivshmem_client_search_peer(client, peer_id);
    /* delete peer */
    if (fd == -1) {
        if (peer == NULL || peer == &client->local) {
            IVSHMEM_CLIENT_DEBUG(client, "receive delete for invalid "
                                 "peer %ld\n", peer_id);
        IVSHMEM_CLIENT_DEBUG(client, "delete peer id = %ld\n", peer_id);
        ivshmem_client_free_peer(client, peer);
        return 0;
    /* new peer */
    if (peer == NULL) {
        peer = g_malloc0(sizeof(*peer));
        peer->id = peer_id;
        peer->vectors_count = 0;
        QTAILQ_INSERT_TAIL(&client->peer_list, peer, next);
        IVSHMEM_CLIENT_DEBUG(client, "new peer id = %ld\n", peer_id);
    /* new vector */
    IVSHMEM_CLIENT_DEBUG(client, "  new vector %d (fd=%d) for peer id %ld\n",
                         peer->vectors_count, fd, peer->id);
    peer->vectors[peer->vectors_count] = fd;
    peer->vectors_count++;
    return 0;
ivshmem_client_handle_server_msg(IvshmemClient *client)
{
    IvshmemClientPeer *peer;
    long peer_id;
    int ret, fd;
    ret = ivshmem_client_read_one_msg(client, &peer_id, &fd);
    if (ret < 0) {
    
    peer = ivshmem_client_search_peer(client, peer_id);
    
    if (fd == -1) {
        if (peer == NULL || peer == &client->local) {
            IVSHMEM_CLIENT_DEBUG(client, "receive delete for invalid "
                                 "peer %ld\n", peer_id);
        IVSHMEM_CLIENT_DEBUG(client, "delete peer id = %ld\n", peer_id);
        ivshmem_client_free_peer(client, peer);
        return 0;
    
    if (peer == NULL) {
        peer = g_malloc0(sizeof(*peer));
        peer->id = peer_id;
        peer->vectors_count = 0;
        QTAILQ_INSERT_TAIL(&client->peer_list, peer, next);
        IVSHMEM_CLIENT_DEBUG(client, "new peer id = %ld\n", peer_id);
    
    IVSHMEM_CLIENT_DEBUG(client, "  new vector %d (fd=%d) for peer id %ld\n",
                         peer->vectors_count, fd, peer->id);
    peer->vectors[peer->vectors_count] = fd;
    peer->vectors_count++;
    return 0;
FUNC_0(IvshmemClient *VAR_0)
{
    IvshmemClientPeer *peer;
    long VAR_1;
    int VAR_2, VAR_3;
    VAR_2 = ivshmem_client_read_one_msg(VAR_0, &VAR_1, &VAR_3);
    if (VAR_2 < 0) {
    
    peer = ivshmem_client_search_peer(VAR_0, VAR_1);
    
    if (VAR_3 == -1) {
        if (peer == NULL || peer == &VAR_0->local) {
            IVSHMEM_CLIENT_DEBUG(VAR_0, "receive delete for invalid "
                                 "peer %ld\n", VAR_1);
        IVSHMEM_CLIENT_DEBUG(VAR_0, "delete peer id = %ld\n", VAR_1);
        ivshmem_client_free_peer(VAR_0, peer);
        return 0;
    
    if (peer == NULL) {
        peer = g_malloc0(sizeof(*peer));
        peer->id = VAR_1;
        peer->vectors_count = 0;
        QTAILQ_INSERT_TAIL(&VAR_0->peer_list, peer, next);
        IVSHMEM_CLIENT_DEBUG(VAR_0, "new peer id = %ld\n", VAR_1);
    
    IVSHMEM_CLIENT_DEBUG(VAR_0, "  new vector %d (VAR_3=%d) for peer id %ld\n",
                         peer->vectors_count, VAR_3, peer->id);
    peer->vectors[peer->vectors_count] = VAR_3;
    peer->vectors_count++;
    return 0;
FUNC_0(IvshmemClient *VAR_0)
{ IvshmemClientPeer *peer; long VAR_1; int VAR_2, VAR_3; VAR_2 = ivshmem_client_read_one_msg(VAR_0, &VAR_1, &VAR_3); if (VAR_2 < 0) { peer = ivshmem_client_search_peer(VAR_0, VAR_1); if (VAR_3 == -1) { if (peer == NULL || peer == &VAR_0->local) { IVSHMEM_CLIENT_DEBUG(VAR_0, "receive delete for invalid "
"peer %ld\n", VAR_1); IVSHMEM_CLIENT_DEBUG(VAR_0, "delete peer id = %ld\n", VAR_1); ivshmem_client_free_peer(VAR_0, peer); return 0; if (peer == NULL) { peer = g_malloc0(sizeof(*peer)); peer->id = VAR_1; peer->vectors_count = 0; QTAILQ_INSERT_TAIL(&VAR_0->peer_list, peer, next); IVSHMEM_CLIENT_DEBUG(VAR_0, "new peer id = %ld\n", VAR_1); IVSHMEM_CLIENT_DEBUG(VAR_0, "  new vector %d (VAR_3=%d) for peer id %ld\n",
peer->vectors_count, VAR_3, peer->id); peer->vectors[peer->vectors_count] = VAR_3; peer->vectors_count++; return 0;