transportlayerlog.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. // Original author: ekr@rtfm.com
  6. #include "logging.h"
  7. #include "transportflow.h"
  8. #include "transportlayerlog.h"
  9. namespace mozilla {
  10. MOZ_MTLOG_MODULE("mtransport")
  11. void TransportLayerLogging::WasInserted() {
  12. if (downward_) {
  13. downward_->SignalStateChange.connect(
  14. this, &TransportLayerLogging::StateChange);
  15. downward_->SignalPacketReceived.connect(
  16. this, &TransportLayerLogging::PacketReceived);
  17. TL_SET_STATE(downward_->state());
  18. }
  19. }
  20. TransportResult
  21. TransportLayerLogging::SendPacket(const unsigned char *data, size_t len) {
  22. MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "SendPacket(" << len << ")");
  23. if (downward_) {
  24. return downward_->SendPacket(data, len);
  25. }
  26. else {
  27. return static_cast<TransportResult>(len);
  28. }
  29. }
  30. void TransportLayerLogging::StateChange(TransportLayer *layer, State state) {
  31. MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Received StateChange to " << state);
  32. TL_SET_STATE(state);
  33. }
  34. void TransportLayerLogging::PacketReceived(TransportLayer* layer,
  35. const unsigned char *data,
  36. size_t len) {
  37. MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "PacketReceived(" << len << ")");
  38. SignalPacketReceived(this, data, len);
  39. }
  40. } // close namespace