Changeset 17932 for trunk/FACT++/src
- Timestamp:
- 07/23/14 15:39:06 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/sqmctrl.cc
r17931 r17932 30 30 private: 31 31 bool fIsVerbose; 32 bool fFirstMessage; 33 bool fValid; 32 34 uint16_t fTimeout; 33 35 … … 54 56 Error(str); 55 57 } 56 PostClose( err!=ba::error::basic_errors::operation_aborted);58 PostClose(false);//err!=ba::error::basic_errors::operation_aborted); 57 59 return; 58 60 } … … 71 73 72 74 if (fIsVerbose) 73 Out() << Time().GetAsStr("%H:%M:%S.%f") << "[" << buffer.size() << "]: " << buffer << endl; 75 { 76 Out() << Time().GetAsStr("%H:%M:%S.%f") << "[" << buffer.size() << "]: " << buffer << "|" << endl; 77 // Out() << Time().GetAsStr("%H:%M:%S.%f") << "[ " << vec.size() << "]: "; 78 // for (auto it=vec.begin(); it!=vec.end(); it++) 79 // Out() << *it << "|"; 80 // Out() << endl; 81 } 74 82 75 83 vector<string> vec; 76 84 boost::split(vec, buffer, boost::is_any_of(",")); 77 85 78 // Send next request in fTimeout milliseconds calculated from79 // the last request onwards.80 fTrigger.expires_at(fTrigger.expires_at()+boost::posix_time::milliseconds(fTimeout));81 fTrigger.async_wait(boost::bind(&ConnectionSQM::HandleRequestTrigger,82 this, dummy::error));83 86 try 84 87 { … … 87 90 88 91 if (vec[0]!="r") 89 throw runtime_error("Not a 'reading request' answer: "+vec[0]);92 throw runtime_error("Not a proper answer["+to_string(vec[0].size())+"]: "+vec[0]); 90 93 91 94 SQM::Data data; … … 98 101 99 102 Update(data); 103 104 fValid = true; 100 105 } 101 106 catch (const exception &e) 102 107 { 103 Error("Parsing received data failed ["+string(e.what())+"]"); 104 Error("Received: "+buffer); 105 PostClose(true); 106 } 108 if (fFirstMessage) 109 Warn("Parsing first message failed ["+string(e.what())+"]"); 110 else 111 { 112 Error("Parsing received message failed ["+string(e.what())+"]"); 113 Error("Received: "+buffer); 114 PostClose(false); 115 return; 116 } 117 } 118 119 // Send next request in fTimeout milliseconds calculated from 120 // the last request onwards. 121 fTrigger.expires_at(fTrigger.expires_at()+boost::posix_time::milliseconds(fTimeout)); 122 fTrigger.async_wait(boost::bind(&ConnectionSQM::HandleRequestTrigger, 123 this, dummy::error)); 124 125 fFirstMessage = false; 107 126 } 108 127 … … 116 135 Error(str); 117 136 118 PostClose( true);137 PostClose(false); 119 138 return; 120 139 } … … 124 143 // For example: Here we could schedule a new accept if we 125 144 // would not want to allow two connections at the same time. 126 //PostClose(true); 127 return; 128 } 145 PostClose(true); 146 return; 147 } 148 149 // This is called if the deadline has been shifted 150 if (error==ba::error::basic_errors::operation_aborted) 151 return; 129 152 130 153 // Check whether the deadline has passed. We compare the deadline … … 139 162 Error(str); 140 163 141 PostClose(true); 164 PostClose(false); 165 166 fInTimeout.expires_from_now(boost::posix_time::milliseconds(1000)); 167 fInTimeout.async_wait(boost::bind(&ConnectionSQM::HandleReadTimeout, 168 this, dummy::error)); 142 169 } 143 170 144 171 void HandleRequestTrigger(const bs::error_code &error) 145 172 { 173 146 174 // 125: Operation canceled (bs::error_code(125, bs::system_category)) 147 175 if (error && error!=ba::error::basic_errors::operation_aborted) … … 151 179 Error(str); 152 180 153 PostClose( true);181 PostClose(false); 154 182 return; 155 183 } … … 177 205 PostMessage(string("rx\n"), 3); 178 206 207 // Do not schedule two reads 208 if (!fFirstMessage) 209 { 210 async_read_until(*this, fBuffer, '\n', 211 boost::bind(&ConnectionSQM::HandleRead, this, 212 dummy::error, dummy::bytes_transferred)); 213 } 214 215 fInTimeout.expires_from_now(boost::posix_time::milliseconds(fTimeout*1.5)); 216 fInTimeout.async_wait(boost::bind(&ConnectionSQM::HandleReadTimeout, 217 this, dummy::error)); 218 } 219 220 private: 221 // This is called when a connection was established 222 void ConnectionEstablished() 223 { 224 fValid = false; 225 fFirstMessage = true; 226 227 // Empty a possible buffer first before we start reading 228 // otherwise reading and writing might not be consecutive 179 229 async_read_until(*this, fBuffer, '\n', 180 230 boost::bind(&ConnectionSQM::HandleRead, this, 181 231 dummy::error, dummy::bytes_transferred)); 182 232 183 fInTimeout.expires_from_now(boost::posix_time::milliseconds(fTimeout*1.5)); 184 fInTimeout.async_wait(boost::bind(&ConnectionSQM::HandleReadTimeout, 185 this, dummy::error)); 186 } 187 188 private: 189 // This is called when a connection was established 190 void ConnectionEstablished() 191 { 192 StartReadReport(); 193 fTrigger.expires_at(Time()); 233 // If there was no immediate answer, send a request 234 fTrigger.expires_at(Time()+boost::posix_time::milliseconds(1000)); 235 fTrigger.async_wait(boost::bind(&ConnectionSQM::HandleRequestTrigger, 236 this, dummy::error)); 194 237 } 195 238 … … 217 260 int GetState() const 218 261 { 219 return is_open() ? SQM::State::kConnected : SQM::State::kDisconnected; 262 if (!is_open()) 263 return SQM::State::kDisconnected; 264 265 return fValid ? SQM::State::kValid : SQM::State::kConnected; 220 266 } 221 267 };
Note:
See TracChangeset
for help on using the changeset viewer.