FACT++  1.0
void ConnectionFAD::HandleReceivedData ( const bs::error_code &  err,
size_t  bytes_received,
int  type 
)
inlineprivate

Definition at line 136 of file fadctrl.cc.

References buffer, data, EventBuilderWrapper::debugHead(), end, Error(), fRegionOfInterest, Connection::HandleReadTimeout(), i, kDelimiterEnd, kDelimiterStart, kNumChannels, str, and EventBuilderWrapper::This.

137  {
138  // Do not schedule a new read if the connection failed.
139  if (bytes_received==0 || err)
140  {
141  if (err==ba::error::eof)
142  Warn("Connection to "+URL()+" closed by remote host (FAD).");
143 
144  // 107: Transport endpoint is not connected (bs::error_code(107, bs::system_category))
145  // 125: Operation canceled
146  if (err && err!=ba::error::eof && // Connection closed by remote host
147  err!=ba::error::basic_errors::not_connected && // Connection closed by remote host
148  err!=ba::error::basic_errors::operation_aborted) // Connection closed by us
149  {
150  ostringstream str;
151  str << "Reading from " << URL() << ": " << err.message() << " (" << err << ")";// << endl;
152  Error(str);
153  }
154  //PostClose(err!=ba::error::basic_errors::operation_aborted);
155  PostClose(false);
156  return;
157  }
158 
159  if (type==kReadHeader)
160  {
161  if (bytes_received!=sizeof(FAD::EventHeader))
162  {
163  ostringstream str;
164  str << "Bytes received (" << bytes_received << " don't match header size " << sizeof(FAD::EventHeader);
165  Error(str);
166  PostClose(false);
167  return;
168  }
169 
171 
172  if (fEventHeader.fStartDelimiter!=FAD::kDelimiterStart)
173  {
174  ostringstream str;
175  str << "Invalid header received: start delimiter wrong, received ";
176  str << hex << fEventHeader.fStartDelimiter << ", expected " << FAD::kDelimiterStart << ".";
177  Error(str);
178  PostClose(false);
179  return;
180  }
181 
182  if (fCounter==0)
184 
186 
188 
189  fBuffer.resize(fEventHeader.fPackageLength-sizeof(FAD::EventHeader)/2);
192 
193  return;
194  }
195 
196  fInTimeout.cancel();
197 
198  if (ntohs(fBuffer.back())!=FAD::kDelimiterEnd)
199  {
200  ostringstream str;
201  str << "Invalid data received: end delimiter wrong, received ";
202  str << hex << ntohs(fBuffer.back()) << ", expected " << FAD::kDelimiterEnd << ".";
203  Error(str);
204  PostClose(false);
205  return;
206  }
207 
208  uint8_t *ptr = reinterpret_cast<uint8_t*>(fBuffer.data());
209  uint8_t *end = ptr + fBuffer.size()*2;
210  for (unsigned int i=0; i<FAD::kNumChannels; i++)
211  {
212  if (ptr+sizeof(FAD::ChannelHeader) > end)
213  {
214  Error("Channel header exceeds buffer size.");
215  PostClose(false);
216  return;
217  }
218 
219  fChannelHeader[i] = vector<uint16_t>((uint16_t*)ptr, (uint16_t*)ptr+sizeof(FAD::ChannelHeader)/2);
220  ptr += sizeof(FAD::ChannelHeader);
221 
222  //UpdateChannelHeader(i);
223 
224  if (ptr+fChannelHeader[i].fRegionOfInterest*2 > end)
225  {
226  Error("Data block exceeds buffer size.");
227  PostClose(false);
228  return;
229  }
230 
231  const uint16_t *data = reinterpret_cast<uint16_t*>(ptr);
233  ptr += fChannelHeader[i].fRegionOfInterest*2;
234  }
235 
236  if (fIsVerbose)
238 
239  fCounter++;
240 
241  fBuffer.resize(sizeof(FAD::EventHeader)/2);
243  }
uint16_t fRegionOfInterest
Definition: HeadersFAD.h:95
void AsyncWait(boost::asio::deadline_timer &timer, int millisec, void(Connection::*handler)(const boost::system::error_code &))
Definition: Connection.h:75
virtual void UpdateChannelHeaders()
Definition: fadctrl.cc:114
boost::asio::deadline_timer fInTimeout
Definition: Connection.h:36
void PostClose(bool restart=true)
Definition: Connection.cc:125
bool fIsVerbose
Definition: fadctrl.cc:43
int i
Definition: db_dim_client.c:21
virtual void UpdateFirstHeader()
Definition: fadctrl.cc:103
char str[80]
Definition: test_client.c:7
void debugHead(const FAD::EventHeader &h)
uint64_t fCounter
Definition: fadctrl.cc:48
FAD::ChannelHeader fChannelHeader[FAD::kNumChannels]
Definition: fadctrl.cc:40
vector< uint16_t > fBuffer
Definition: fadctrl.cc:36
int type
std::string URL() const
Definition: Connection.h:151
int Error(const std::string &str)
Definition: MessageImp.h:49
int Warn(const std::string &str)
Definition: MessageImp.h:48
double end
void AsyncRead(const boost::asio::mutable_buffers_1 buffers, int type=0)
Definition: Connection.cc:31
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
float data[4 *1440]
virtual void HandleReadTimeout(const boost::system::error_code &)
Definition: Connection.h:138
virtual void UpdateEventHeader()
Definition: fadctrl.cc:107
if(extraDns) new Dns
static EventBuilderWrapper * This
FAD::EventHeader fEventHeader
Definition: fadctrl.cc:39
virtual void UpdateData(const uint16_t *data, size_t sz)
Definition: fadctrl.cc:122

+ Here is the call graph for this function: