static void update_peers(struct network_manager* nm) { // Perform the select first fd_set read_fds = nm->poll_read_fds, write_fds = nm->poll_write_fds, exception_fds = nm->poll_exception_fds; struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 0; if(select(nm->poll_max_fd + 1, &read_fds, &write_fds, &exception_fds, &timeout) < 0) { // weird error? perror("select"); return; } // Then loop over all peers passing in the select status struct network_peer** ppeer = NULL; Word_t index = 0; struct vector disconnected_peers; vector_init(&disconnected_peers); JLF(ppeer, nm->peer_list, index); while(ppeer != NULL) { int action_flags = 0; int* psock = NULL; uintptr_t p = (uintptr_t)*ppeer; JLG(psock, nm->poll_socket_by_peer, p); if(psock != NULL) { if(FD_ISSET(*psock, &read_fds)) action_flags |= NETWORK_PEER_ACTION_FLAGS_READ; if(FD_ISSET(*psock, &write_fds)) action_flags |= NETWORK_PEER_ACTION_FLAGS_WRITE; if(FD_ISSET(*psock, &exception_fds)) action_flags |= NETWORK_PEER_ACTION_FLAGS_EXCEPTION; } network_peer_update(*ppeer, action_flags); if(network_peer_disconnected(*ppeer) == 1) { vector_add(&disconnected_peers, (uintptr_t)*ppeer); } JLN(ppeer, nm->peer_list, index); } size_t num_disconnected = vector_count(&disconnected_peers); for(size_t i = 0; i < num_disconnected; i++) { struct network_peer* peer = (struct network_peer*)vector_get(&disconnected_peers, i); stop_peer(nm, peer); } vector_free(&disconnected_peers); }
/** * Cleans up the given PeerReconfigureContext * * @param prc the PeerReconfigureContext */ static void cleanup_prc (struct PeerReconfigureContext *prc) { struct Peer *peer; if (VALID_PEER_ID (prc->peer_id)) { peer = GST_peer_list [prc->peer_id]; if (1 != prc->stopped) { GNUNET_TESTING_peer_stop_async_cancel (peer->details.local.peer); stop_peer (peer); /* Stop the peer synchronously */ } } if (NULL != prc->cfg) GNUNET_CONFIGURATION_destroy (prc->cfg); GNUNET_CONTAINER_DLL_remove (prc_head, prc_tail, prc); GNUNET_free (prc); }