Page tree
Skip to end of metadata
Go to start of metadata

bool FB::SimpleStreamHelper::onStreamDataArrived ( FB::StreamDataArrivedEvent *  evt,
FB::BrowserStream Stream 
)
virtual

Called when data arrives.

Author
Matthias

Reimplemented from FB::DefaultBrowserStreamHandler.

Definition at line 196 of file SimpleStreamHelper.cpp.

197 {
198  received += evt->getLength();
199  const uint8_t* buf = reinterpret_cast<const uint8_t*>(evt->getData());
200  const uint8_t* endbuf = buf + evt->getLength();
201 
202  int len = evt->getLength();
203  int offset = evt->getDataPosition();
204  while (buf < endbuf) {
205  size_t n = offset / blockSize;
206  size_t pos = offset % blockSize;
207  if (blocks.size() < n+1) {
208  blocks.push_back(boost::shared_array<uint8_t>(new uint8_t[blockSize]));
209  }
210  uint8_t *destBuf = blocks.back().get();
211  //if (pos + len > )
212  int curLen = len;
213  if (pos + len >= blockSize) {
214  // If there isn't room in the current block, copy what there is room for
215  // and loop
216  curLen = blockSize-pos;
217  }
218  // Copy the bytes that fit in this buffer
219  std::copy(buf, buf+curLen, destBuf+pos);
220  buf += curLen;
221  offset += curLen;
222  len -= curLen;
223  }
224  return false;
225 }
  • No labels