From e3c947f118a40c6136d6f355736814b043090dda Mon Sep 17 00:00:00 2001 From: Dwight Date: Sun, 18 Nov 2007 14:05:28 -0500 Subject: [PATCH] cleaner output --- db/db.cpp | 16 ++++++++-------- grid/protoimpl.h | 13 +++++++++++-- grid/protorecv.cpp | 4 +--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/db/db.cpp b/db/db.cpp index 7f78df4fbc2..b6506784921 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -224,15 +224,15 @@ void run() { m.reset(); // temp: - sleepsecs(1); + // sleepsecs(1); - cout << '\n' << curTimeMillis() << " waiting for msg..." << endl; + cout << curTimeMillis() % 10000 << " waiting for msg..." << endl; if( !dbMsgPort.recv(m) ) { cout << "MessagingPort::recv() returned false" << endl; break; } - cout << '\n' << curTimeMillis() << " **** db.cpp got msg ************\n" << endl; + cout << curTimeMillis() % 10000 << " db.cpp got msg" << endl; //cout << " got msg" << endl; //cout << " op:" << m.data->operation << " len:" << m.data->len << endl; @@ -241,7 +241,7 @@ void run() { char *p = m.data->_data; int len = strlen(p); if( len > 400 ) - cout << curTimeMillis() << + cout << curTimeMillis() % 10000 << " long msg received, len:" << len << " ends with: " << p + len - 10 << endl; bool end = strcmp("end", p) == 0; @@ -249,7 +249,7 @@ void run() { resp.setData(opReply, "i am fine"); dbMsgPort.reply(m, resp); if( end ) { - cout << curTimeMillis() << " end msg" << endl; + cout << curTimeMillis() % 10000 << " end msg" << endl; break; } } @@ -290,9 +290,9 @@ void msg(const char *m, int extras = 0) { for( int i = 0; i < extras; i++ ) p.say(p.channel(), db, send); - cout << curTimeMillis() << " ****calling DB..." << endl; + cout << curTimeMillis() % 10000 << " ****calling DB..." << endl; bool ok = p.call(db, send, response); - cout << curTimeMillis() << " ****ok. response.data:" << ok << " ****" << endl; + cout << curTimeMillis() % 10000 << " ****ok. response.data:" << ok << " ****" << endl; /* cout << " " << response.data->id << endl; cout << " " << response.data->len << endl; cout << " " << response.data->operation << endl; @@ -311,7 +311,7 @@ cout << "hello2" << endl; int main(int argc, char* argv[], char *envp[] ) { srand(curTimeMillis()); - cout << curTimeMillis() << endl; + cout << curTimeMillis() % 10000 << endl; quicktest(); diff --git a/grid/protoimpl.h b/grid/protoimpl.h index 02691e623c4..26eeed8f336 100644 --- a/grid/protoimpl.h +++ b/grid/protoimpl.h @@ -4,6 +4,11 @@ #include "message.h" +using namespace boost; +typedef boost::mutex::scoped_lock lock; + +extern boost::mutex coutmutex; + const int FragMax = 1480; const int FragHeader = 10; const int MSS = FragMax - FragHeader; @@ -71,6 +76,7 @@ inline void DUMPDATA(Fragment& f, const char *tabs) { } inline void SEND(UDPConnection& c, Fragment &f, SockAddr& to, const char *extra="") { + lock lk(coutmutex); DUMP(f, to, "\t\t\t\t\t>"); c.sendto((char *) &f, f.fragmentLen, to); cout << extra; @@ -152,8 +158,11 @@ inline F* __recv(UDPConnection& c, SockAddr& from) { cout << ".recvfrom returned error " << getLastError() << " socket:" << c.sock << endl; } assert( f->fragmentLen == n ); - DUMP(*f, from, "\t\t\t\t\t\t\t\t\t\t<"); - DUMPDATA(*f, "\t\t\t\t\t\t\t\t\t\t "); + { + lock lk(coutmutex); + DUMP(*f, from, "\t\t\t\t\t\t\t\t\t\t<"); + DUMPDATA(*f, "\t\t\t\t\t\t\t\t\t\t "); + } return new F(f); } diff --git a/grid/protorecv.cpp b/grid/protorecv.cpp index 0d55909ab07..8cd613954a8 100644 --- a/grid/protorecv.cpp +++ b/grid/protorecv.cpp @@ -7,9 +7,7 @@ #include "../util/sock.h" #include "protoimpl.h" -using namespace boost; -typedef boost::mutex::scoped_lock lock; - +boost::mutex coutmutex; boost::mutex mutexr; boost::condition threadActivate; // creating a new thread, grabbing threadUseThisOne ProtocolConnection *threadUseThisOne = 0;