Example #1
0
void Socket::WriteData(std::unique_ptr<std::string>&& buffer) {
  if (!is_open() || !buffer || buffer->size() < 1) return;

  std::shared_ptr<std::string> buff(buffer.release());

  if (list_.empty()) {
    list_.push_back(buff);
    DoWriteData();
  } else {
    list_.push_back(buff);
  }
}
Example #2
0
void Socket::WriteData(const char* data, std::size_t size) {
  if (!is_open() || size < 1) return;

  auto buff = std::make_shared<std::string>();
  buff->append(data, size);

  if (list_.empty()) {
    list_.push_back(buff);
    DoWriteData();
  } else {
    list_.push_back(buff);
  }
}
// ----------------------------------------------------------------------------
// Complete queued message
// ----------------------------------------------------------------------------
//
void CMPXPlaybackSession::CompleteAsync(
    TInt aErr,
    TInt aSlot1, const TDesC8* aVal1,
    TInt aSlot2, const TDesC8* aVal2)
    {
    MPX_ASSERT(!iMessage.IsNull());
    TInt err(KErrNone);
    if (KErrNone==aErr)
        {
        err = DoWriteData(aSlot1, aVal1, aSlot2, aVal2);
        if (err)
            { // Set to new error
            aErr = err;
            }
        }
    MPX_DEBUG4("CMPXPlaybackSession::CompleteAsync 0x%08x task %d err %d",
            this, iMessage.Function(), aErr);
    iMessage.Complete(aErr);
    }
Example #4
0
void Socket::DoWriteData() {
  if (list_.empty()) return;

  auto buff = list_.front();
  auto self = shared_from_this();
  async_write_some(boost::asio::buffer(buff->data(), buff->size()),
                   [buff, self, this](const boost::system::error_code& ec, std::size_t wd) {
                     if (ec) {
                       BB_ERROR_LOG("socket[%d] write data ec:%s", GetId(), ec.message().c_str());
                       Close();
                       return;
                     }

                     if (wd < buff->size()) {
                       buff->erase(0, wd);
                     } else {
                       list_.pop_front();
                     }
                     DoWriteData();
                   });
}