From: Arnaud Giersch Date: Wed, 4 Jul 2012 12:34:27 +0000 (+0200) Subject: Make example compile with enable_warnings=ON. X-Git-Tag: v3_8~344 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3d84113e2eb8d578a6838d21f84f55d9e77c65d4 Make example compile with enable_warnings=ON. Main changes are: * remove unused variables. * use unsigned int for the index in xbt_dynar_foreach. --- diff --git a/examples/msg/bittorrent/bittorrent.c b/examples/msg/bittorrent/bittorrent.c index cb4cd80fa9..367933000c 100644 --- a/examples/msg/bittorrent/bittorrent.c +++ b/examples/msg/bittorrent/bittorrent.c @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) MSG_launch_application(deployment_file); - msg_error_t res = MSG_main(); + MSG_main(); MSG_clean(); diff --git a/examples/msg/bittorrent/bittorrent.h b/examples/msg/bittorrent/bittorrent.h index f122d2f3f2..4c24b9d58e 100644 --- a/examples/msg/bittorrent/bittorrent.h +++ b/examples/msg/bittorrent/bittorrent.h @@ -6,25 +6,15 @@ #ifndef BITTORRENT_BITTORRENT_H_ #define BITTORRENT_BITTORRENT_H_ -//TODO: Let users change this -/* - * File transfered data - */ -static int FILE_SIZE = 5120; -static int FILE_PIECE_SIZE = 512; -static int FILE_PIECES = 10; - -static int PIECES_BLOCKS = 5; -static int BLOCKS_REQUESTED = 2; -static int PIECE_COMM_SIZE = 1; /** * Information message size */ #define MESSAGE_SIZE 1 - - -#define MAILBOX_SIZE 40 /* Size of mailboxes */ +/** + * Size of mailboxes + */ +#define MAILBOX_SIZE 40 /** * Mailbox used to communicate with the tracker. */ diff --git a/examples/msg/bittorrent/peer.c b/examples/msg/bittorrent/peer.c index 70e2a982cb..acafbc7e7f 100644 --- a/examples/msg/bittorrent/peer.c +++ b/examples/msg/bittorrent/peer.c @@ -12,7 +12,15 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_peers, "Messages specific for the peers"); +//TODO: Let users change this +/* + * File transfered data + */ +static int FILE_SIZE = 5120; +static int FILE_PIECES = 10; +static int PIECES_BLOCKS = 5; +static int BLOCKS_REQUESTED = 2; /** * Peer main function @@ -171,7 +179,8 @@ int get_peers_data(peer_t peer) msg_error_t status = MSG_comm_wait(comm_received, GET_PEERS_TIMEOUT); if (status == MSG_OK) { tracker_task_data_t data = MSG_task_get_data(task_received); - int i, peer_id; + unsigned i; + int peer_id; //Add the peers the tracker gave us to our peer list. xbt_dynar_foreach(data->peers, i, peer_id) { if (peer_id != peer->id) @@ -392,7 +401,8 @@ void handle_message(peer_t peer, msg_task_t task) if (piece_complete(peer, message->index)) { peer->pieces_requested--; //Removing the piece from our piece list - int piece_index = -1, i, piece; + unsigned i; + int piece_index = -1, piece; xbt_dynar_foreach(peer->current_pieces, i, piece) { if (piece == message->index) { piece_index = i; @@ -446,7 +456,7 @@ void wait_for_pieces(peer_t peer, double deadline) MSG_comm_destroy(peer->comm_received); peer->comm_received = NULL; if (status == MSG_OK) { - message_t message = MSG_task_get_data(peer->task_received); + MSG_task_get_data(peer->task_received); handle_message(peer, peer->task_received); if (peer->current_piece != -1) { finished = 1; @@ -513,9 +523,8 @@ void update_current_piece(peer_t peer) } xbt_dynar_push_as(peer->current_pieces, int, peer->current_piece); XBT_DEBUG("New interested piece: %d", peer->current_piece); - xbt_assert((peer->current_piece >= 0 - && peer->current_piece < FILE_PIECES, - "Peer want to retrieve a piece that doesn't exist.")); + xbt_assert((peer->current_piece >= 0 && peer->current_piece < FILE_PIECES), + "Peer want to retrieve a piece that doesn't exist."); } /** @@ -527,7 +536,6 @@ void update_choked_peers(peer_t peer) { //update the current round peer->round = (peer->round + 1) % 3; - int i; char *key; connection_t peer_choosed = NULL; //remove a peer from the list @@ -616,7 +624,8 @@ void update_interested_after_receive(peer_t peer) char *key; xbt_dict_cursor_t cursor; connection_t connection; - int interested, cpt, piece; + unsigned cpt; + int interested, piece; xbt_dict_foreach(peer->peers, cursor, key, connection) { interested = 0; if (connection->am_interested) { @@ -684,7 +693,8 @@ int get_first_block(peer_t peer, int piece) */ void send_requests_to_peer(peer_t peer, connection_t remote_peer) { - int i, piece, block_index, block_length; + unsigned i; + int piece, block_index, block_length; xbt_dynar_foreach(peer->current_pieces, i, piece) { if (remote_peer->bitfield && remote_peer->bitfield[piece] == '1') { block_index = get_first_block(peer, piece); @@ -873,7 +883,8 @@ void send_piece(peer_t peer, const char *mailbox, int piece, int stalled, int in_current_pieces(peer_t peer, int piece) { - int is_in = 0, i, peer_piece; + unsigned i; + int is_in = 0, peer_piece; xbt_dynar_foreach(peer->current_pieces, i, peer_piece) { if (peer_piece == piece) { is_in = 1; diff --git a/examples/msg/bittorrent/tracker.c b/examples/msg/bittorrent/tracker.c index 9da5f9ae46..d6190473a6 100644 --- a/examples/msg/bittorrent/tracker.c +++ b/examples/msg/bittorrent/tracker.c @@ -17,9 +17,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_tracker, "Messages specific for the tracker"); */ int tracker(int argc, char *argv[]) { - int i, key_elm; - char *key; - void *data_p; + int i; RngStream stream = RngStream_CreateStream("tracker"); @@ -50,7 +48,7 @@ int tracker(int argc, char *argv[]) xbt_dynar_push_as(peers_list, int, data->peer_id); } //Sending peers to the peer - int nb_peers = 0, next_peer; + int next_peer; int peers_length = xbt_dynar_length(peers_list); for (i = 0; i < MAXIMUM_PAIRS && i < peers_length; i++) { do { @@ -140,7 +138,8 @@ void tracker_task_data_free(tracker_task_data_t task) */ int is_in_list(xbt_dynar_t peers, int id) { - int i, elm; + unsigned i; + int elm; xbt_dynar_foreach(peers, i, elm) { if (elm == id) { return 1;