Пример #1
0
nsresult TransportLayerLoopback::QueuePacket(const unsigned char *data,
                                         size_t len) {
  MOZ_ASSERT(packets_lock_);

  PR_Lock(packets_lock_);

  if (combinePackets_ && !packets_.empty()) {
    QueuedPacket *packet = packets_.front();
    packets_.pop();

    MOZ_MTLOG(ML_DEBUG, LAYER_INFO << " Enqueuing combined packets of length " << packet->len() << " and " << len);
    packets_.push(new QueuedPacket());
    packets_.back()->Assign(packet->data(), packet->len(),
                            data, len);
  } else {
    MOZ_MTLOG(ML_DEBUG, LAYER_INFO << " Enqueuing packet of length " << len);
    packets_.push(new QueuedPacket());
    packets_.back()->Assign(data, len);
  }

  PRStatus r = PR_Unlock(packets_lock_);
  MOZ_ASSERT(r == PR_SUCCESS);
  if (r != PR_SUCCESS)
    return NS_ERROR_FAILURE;

  return NS_OK;
}
void TransportLayerLoopback::DeliverPackets() {
  while (!packets_.empty()) {
    QueuedPacket *packet = packets_.front();
    packets_.pop();

    MOZ_MTLOG(ML_DEBUG, LAYER_INFO << " Delivering packet of length " <<
         packet->len());
    SignalPacketReceived(this, packet->data(), packet->len());

    delete packet;
  }
}