diff options
-rw-r--r-- | syncClientSocket.cpp | 21 | ||||
-rw-r--r-- | syncClientSocket.h | 2 | ||||
-rw-r--r-- | syncQueue.cpp | 4 | ||||
-rw-r--r-- | 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<int16_t>(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 #"<<mux<<" remote host " << conn.remote_host_ << ":" << conn.remote_port_ << std::endl; diff --git a/syncClientSocket.h b/syncClientSocket.h index 5334079..432657a 100644 --- a/syncClientSocket.h +++ b/syncClientSocket.h @@ -26,7 +26,7 @@ public: private: ConnectionList & cl_; std::stringstream iss_; - uint16_t missing_chars; + int16_t missing_chars; }; diff --git a/syncQueue.cpp b/syncQueue.cpp index 7d3c35f..a24a4f5 100644 --- a/syncQueue.cpp +++ b/syncQueue.cpp @@ -47,7 +47,9 @@ void SyncQueue::push(const SyncCommand & scom ) oa << scom; Lock lock(mutex_); - queue_.push(sout.str()); + std::stringstream lengthout; + lengthout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' '; + queue_.push(lengthout.str()+sout.str()); } void SyncQueue::push(const std::string & str ) diff --git a/syncSocket.cpp b/syncSocket.cpp index d557bf4..6681ba3 100644 --- a/syncSocket.cpp +++ b/syncSocket.cpp @@ -35,6 +35,9 @@ void SyncSocket::OnAccept() boost::archive::text_oarchive oa(sout); const SyncCommand scom(cl_,cit->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()); } } |