From 28a4348365cbdeb111e8807f63ff2e455a620453 Mon Sep 17 00:00:00 2001 From: glenux Date: Mon, 6 Mar 2006 16:17:28 +0000 Subject: [PATCH] --- src/clock_cb.cc | 3 +++ src/group.cc | 20 +++++++++++++++++++- src/lowsender.cc | 26 ++++++++++++++------------ src/message.cc | 19 ++++++++++++------- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/clock_cb.cc b/src/clock_cb.cc index 74d1098..8312abe 100644 --- a/src/clock_cb.cc +++ b/src/clock_cb.cc @@ -1,4 +1,5 @@ +#include "macros.h" #include "clock_cb.h" ClockCb::ClockCb(size_t size, size_t index){ @@ -49,6 +50,8 @@ bool ClockCb::adjust(TimeStamp ts){ // si les deux conditions sont respectées, on met à jour l'horloge... _ticks[emit_idx] = _ticks[emit_idx] + 1; printf("ClockCb::adjust -- time update _ticks[%d] = %d\n", emit_idx, _ticks[emit_idx]); + } else { + printf("ClockCb::adding -- %scannot adjust%s ... \n", COLOR_RED, COLOR_NORMAL); } return result; } diff --git a/src/group.cc b/src/group.cc index fecec1f..21d609a 100644 --- a/src/group.cc +++ b/src/group.cc @@ -72,10 +72,27 @@ void Group::broadcast(Message & msg){ printf("Group::broadcast -- enter\n"); std::vector::iterator saIter; + std::list raList; + // choisir aléatoirement l'ordre des sites recepteurs for (int index = 0; index < _addrs.size(); index++){ - this->sendto(msg, index); + raList.push_back(index); } + while(raList.size() > 0){ + int r=rand() % raList.size(); + + std::list::iterator it; + it = raList.begin(); + for (int i=0; isendto(msg, *it); + + raList.remove(*it); + } + if (DEBUG) printf("Group::broadcast -- exit\n"); } @@ -98,6 +115,7 @@ void Group::sendto(Message &msg, short index){ if (DEBUG) printf("Group::sendto -- got mesg\n"); + sleep(1); //FIXME: de-activate if ((en = ::sendto(_socket_desc, message, message_len, diff --git a/src/lowsender.cc b/src/lowsender.cc index 43ee79b..dfb85ff 100644 --- a/src/lowsender.cc +++ b/src/lowsender.cc @@ -13,21 +13,23 @@ LowSender::LowSender(Group &grp, Clock &clk, Protocol::Type type) : _group(grp), void LowSender::run(){ // thread part srand(time(NULL)); + for (int delay = 10; delay >= 0; delay-- ){ + printf("\rLowSender::run -- Waiting %d seconds... ", delay); + fflush(stdout); + sleep(1); + } + printf("\n"); while(1){ - sleep(3); - if (rand() % 3 == 0) { - printf("LowSender::run -- Broadcasting '%s'\n", MESSAGE); - TimeStamp ts = _clock.inc(); - pDEBUG("Timestamp done\n"); + sleep(1); + printf("LowSender::run -- Broadcasting '%s'\n", MESSAGE); + TimeStamp ts = _clock.inc(); + pDEBUG("Timestamp done\n"); - Message msg(_type, ts, MESSAGE, strlen(MESSAGE)); - pDEBUG("Mesg done and ready to send\n"); + Message msg(_type, ts, MESSAGE, strlen(MESSAGE)); + pDEBUG("Mesg done and ready to send\n"); - _group.broadcast(msg); - pDEBUG("Mesg sent\n"); - } else { - pDEBUG("Not sending\n"); - } + _group.broadcast(msg); + pDEBUG("Mesg sent\n"); } } diff --git a/src/message.cc b/src/message.cc index a62b267..19d6d0d 100644 --- a/src/message.cc +++ b/src/message.cc @@ -1,10 +1,13 @@ #include +#include "macros.h" #include "message.h" -#define DEBUG_INPUT 1 -#define DEBUG_OUTPUT 1 +#define DEBUG_INPUT 0 +#define DEBUG_OUTPUT 0 + +#define DEBUG (DEBUG_INPUT || DEBUG_OUTPUT) Message::Message(const Message & original){ printf("Message::Message -- copy\n"); @@ -138,18 +141,20 @@ char * Message::getRaw(){ char * result = new char[_size]; memcpy(result, _raw, _size); - printf("Message::getRaw -- hex: \n"); - for (int i=0; i < _size; i++){ - printf("%#x ", result[i]); + if (DEBUG){ + pDEBUG("hex: \n"); + for (int i=0; i < _size; i++){ + printf("%#x ", result[i]); + } + printf("\n"); } - printf("\n"); return result; } size_t Message::getRawSize(){ - printf("Message::getRawSize -- %d\n",_size); + pDEBUG("%d\n",_size); return _size; }