AltDataOutputStreamParent.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "mozilla/net/AltDataOutputStreamParent.h"
  6. #include "mozilla/Unused.h"
  7. namespace mozilla {
  8. namespace net {
  9. NS_IMPL_ISUPPORTS0(AltDataOutputStreamParent)
  10. AltDataOutputStreamParent::AltDataOutputStreamParent(nsIOutputStream* aStream)
  11. : mOutputStream(aStream)
  12. , mStatus(NS_OK)
  13. {
  14. MOZ_ASSERT(NS_IsMainThread(), "Main thread only");
  15. }
  16. AltDataOutputStreamParent::~AltDataOutputStreamParent()
  17. {
  18. MOZ_ASSERT(NS_IsMainThread(), "Main thread only");
  19. }
  20. bool
  21. AltDataOutputStreamParent::RecvWriteData(const nsCString& data)
  22. {
  23. if (NS_FAILED(mStatus)) {
  24. Unused << SendError(mStatus);
  25. return true;
  26. }
  27. nsresult rv;
  28. uint32_t n;
  29. if (mOutputStream) {
  30. rv = mOutputStream->Write(data.BeginReading(), data.Length(), &n);
  31. MOZ_ASSERT(n == data.Length());
  32. if (NS_FAILED(rv)) {
  33. Unused << SendError(rv);
  34. }
  35. }
  36. return true;
  37. }
  38. bool
  39. AltDataOutputStreamParent::RecvClose()
  40. {
  41. if (NS_FAILED(mStatus)) {
  42. Unused << SendError(mStatus);
  43. return true;
  44. }
  45. nsresult rv;
  46. if (mOutputStream) {
  47. rv = mOutputStream->Close();
  48. if (NS_FAILED(rv)) {
  49. Unused << SendError(rv);
  50. }
  51. mOutputStream = nullptr;
  52. }
  53. return true;
  54. }
  55. void
  56. AltDataOutputStreamParent::ActorDestroy(ActorDestroyReason aWhy)
  57. {
  58. }
  59. } // namespace net
  60. } // namespace mozilla