From 8ddb2c09f6cf2e3781ed660aa28f4e68aeeb4fc5 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Thu, 28 Feb 2008 21:30:28 +0000 Subject: new sync protocol --- syncClientSocket.cpp | 21 +++++++++++++++------ syncClientSocket.h | 2 +- syncQueue.cpp | 4 +++- syncSocket.cpp | 6 ++++++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/syncClientSocket.cpp b/syncClientSocket.cpp index 09faeda..0159f83 100644 --- a/syncClientSocket.cpp +++ b/syncClientSocket.cpp @@ -14,7 +14,7 @@ SyncClientSocket::SyncClientSocket(ISocketHandler& h,ConnectionList & cl) -:TcpSocket(h),cl_(cl),missing_chars(0) +:TcpSocket(h),cl_(cl),missing_chars(-1) { // initial connection timeout setting and number of retries SetConnectTimeout(12); @@ -48,13 +48,22 @@ void SyncClientSocket::OnRawData(const char *buf,size_t len) std::cout << buf[index]; iss_ << buf[index]; } - - while(iss_.good()) + while (1) { - boost::archive::text_iarchive ia(iss_); - SyncCommand scom(cl_); - ia >> scom; + if(missing_chars==-1 && iss_.str().size()>5) + { + iss_>>missing_chars; + } else + if(missing_chars>0 && missing_chars<=static_cast(iss_.str().size())) + { + boost::archive::text_iarchive ia(iss_); + SyncCommand scom(cl_); + ia >> scom; + missing_chars=-1; + } else + break; } + //u_int16_t mux = scom.getMux(); //const ConnectionParam & conn = cl_.getConnection(mux)->second; //cLog.msg(Log::PRIO_NOTICE) << "sync connection #"<first); oa << scom; + std::stringstream lengthout; + lengthout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' '; + Send(lengthout.str()); Send(sout.str()); } //TODO Locking here @@ -46,6 +49,9 @@ void SyncSocket::OnAccept() boost::archive::text_oarchive oa(sout); const SyncCommand scom(tmp); oa << scom; + std::stringstream lengthout; + lengthout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' '; + Send(lengthout.str()); Send(sout.str()); } } -- cgit v1.2.3